GithubHelp home page GithubHelp logo

Comments (1)

kettanaito avatar kettanaito commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.