I've noticed that it's common (at least in ECMAScript) to suffix event handlers with 'handler': clickHandler
, fooBarHandler
, etc… But I've always thought it made more sense to prefix them with 'handle': handleClick
, handleFooBar
, etc.
With prefix notation, methods are much easier to visually parse (it's very easy to distinguish between handlers and other things), faster to find (or ignore) with the editor's text completion and they adhere to the convention that methods should be verbs (handleClick
is a verb, clickHandler
is a noun).
So, why is the suffix notation common? Is there some hidden benefit that I haven't noticed?
It doesn't matter. Do what you like and get in religious debates with your co-workers.
The traditional Flash naming convention uses "on" as a prefix rather than "Handler" as a suffix. Some people prefer verb method names, some prefer noun method names. The name onMouseClick is more of an adverb, mouseClickHandler is a noun which sounds like a class name, and handleMouseClick is a verb.
I typically use the "Handler" suffix to follow the Adobe Flex coding conventions, but the "on" prefix is much shorter and has the (already mentioned) benefit of sorting. If you are in Flex Builder hit Ctrl-O and it will popup a shortcut menu and typing just "on" will show you every handler in the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With