“onButtonClick” or “onClickButton"
[Note to others: This question was also asked on English.SE, it is an explanation for someone whose first language is not English; and wants help naming functions.]
When creating function names, remember to read one word at a time from left to right. The first capitalized word usually indicates the object or action, with "on" representing a handler and the following word indicating the action or object.
If you have a button, for example, you may need an onButtonClick() function to handle clicks on the button, which might then call onClickButton(). While the second function is not mandatory, the first is likely defined within the GUI's header files.
Objects like buttons, images, thumbnails, and text can be paired with actions such as click and hover. These are just examples of the possibilities available when naming functions.
If there is a "Button", any interaction involving it would begin with "onButton". Whether you click or hover determines the rest of the function name – onButtonClick or onButtonHover.
In situations where a handler needs to take action based on these interactions, additional functions like onClick() or onHover() come into play. These functions could perform tasks like highlighting elements during hovering or triggering certain activities upon clicking.
The onClick() function could potentially include subroutines for handling clicks on different objects, ranging from buttons to text.
To better understand this concept, consider reading up on subclassing in controls to create your own custom functions.
Based on search results, variations like "onButtonClicked" and "onButtonClick" appear to be more widely preferred in coding practices compared to alternatives like "onClickedButton" or "onClickButton".