Event names are constants. The name of any event will not change in the runtime. So, write them in constants.

These days, I use to write a dedicated module to store a hash containing event names. Doing so, I even take the benefit of having all events listed in just one place. It helps me understand which are all the events my application is making use of. Also, it prevents name collision and make naming conventions explicit for everyone.

When you link your events with constants, you make them more consistent and avoid the trap of spreading out plain words that can be misspelled leading the application to an unexpected behavior.

From now on, you can avoid three traps that event-driven programming might set to you. Do you know a couple more traps? Please, don’t hesitate in use the comments section to share.