Comments (1)
Hey, @xtofl.
This is a great dive into meaningful callback/handler names. We don't currently recommend how you should name your handlers, and the A/HC/LC pattern is still applicable to functions like mark
, which stand for a meaningful action passed to wherever you choose.
There's one nuance about naming handlers after their intention as opposed to after their application:
handleClickOutside // application
refetchUsers // intention
When preferring the intention, there's always a danger of that intention migrating away or growing out of proportion in time. Let's take your country's example:
country.on_click(mark)
Initially, mark
circles the clicked country on the map. That sounds great. Now, in time, we've also decided it to display some country info next to the circle. So it also displays the info, that's still under the "mark" intention. Well, then, we also wanted to fetch some weather forecast in that country and render it right next to the country name. Now we also do this side-effect... I hope you're getting the point. We (developers) tend to let our intentions grow and change but it's not a general practice to make sure that function names stay aligned with the intention. Partially, because intentions may become complex, and representing them in a function name gets too verbose:
country.on_click(mark_and_show_weather_also_maybe_track_analytics_if_signed_in)
That's my argument for considering application-based names like handleCountryClick
. I agree that it doesn't give you the intention from the function name, but it gives you enough contextual information (hey, this is called when I click on a country) to get started. This way we encapsulate the complexity of our intentions within the function itself, and the handler name will remain true as long as it's passed to country.on_click
.
I also think that function names alone are insufficient sometimes to describe the intention. Mainly, due to the complexity of those intentions that I've described above. That's why it's generally dangerous to derive intentions from function names alone. I'd rather trust tests, as those can be as verbose as the intention requires.
from naming-cheatsheet.
Related Issues (20)
- Plurals Considered Harmful HOT 4
- Add recommendation on how to handle unsafe async / remote fetch functions HOT 4
- isRoot or hasParent? HOT 2
- Incorrect order of arguments HOT 1
- React prop: disabled Vs. isDisabled HOT 4
- JavaScript getter/setters (S|Get keyword) HOT 5
- Use of singular/plurals for compound terms HOT 2
- add translation version link in readme.md HOT 4
- verb suggestions HOT 2
- Negative boolean variable names HOT 1
- Counter-example to avoiding `a` as a variable name HOT 1
- Why can't I jump to the anchor link in the Readme document? HOT 2
- Suggestion: difference between verb `remove` and `delete` HOT 2
- Questions about naming functions? HOT 1
- Suggestion: Change [Reflect the expected result] to [Reflect the positive result]
- What about abbreviation / Acronyms? HOT 1
- State-of-being verbs HOT 1
- Add Create Action
- [suggestion] Add type naming conventions & recommendations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from naming-cheatsheet.