Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it convention to suffix event handlers with 'handler'? Why not prefix them with 'handle'?

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?

like image 598
David Wolever Avatar asked Dec 17 '22 06:12

David Wolever


2 Answers

It doesn't matter. Do what you like and get in religious debates with your co-workers.

like image 198
Tom Ritter Avatar answered May 19 '23 08:05

Tom Ritter


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.

like image 40
Jonathan Branam Avatar answered May 19 '23 09:05

Jonathan Branam