Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 4812

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 27, 20242024-11-27T03:28:10+00:00 2024-11-27T03:28:10+00:00

Make Your Code Self-Documenting with Descriptive Event Handler Names

  • 61k

In software development, one of the key principles is to make code that is easy to read and understand. This is especially important in declarative systems like React, Vue or Svelte where the code describes what the system is supposed to do rather than the specific steps to do it. When you give your event handlers meaningful names, it becomes much easier for other developers (and yourself, when you come back to the code later) to understand the purpose of the handler just by reading the name.

For example, consider the following two event handlers:

// meaningful event handlers <Touch   onTouchStart={saveOffsetForMoveAndFocus}   onTouchMove={moveWindow}> ... </Touch>  // generic event handlers <Touch   onTouchStart={handleTouchStart}   onTouchMove={handleTouchMove}> ... </Touch> 
Enter fullscreen mode Exit fullscreen mode

Which of these handlers is more meaningful? The first example clearly communicates what is supposed to happen, whereas the second one does not so, you need to browse the rest of the code to understand its purpose.

Using descriptive names for your event handlers makes your code more self-documenting, which can save time and reduce the need for detailed documentation. It can also make it easier to find and fix bugs in your code, as the names can provide clues about the purpose of the event handler and where it is being used.

Wait, this way my function names are gonna be too long!!!

When it comes to the length of method names, Uncle Bob suggests that it is generally better to err on the side of longer and more descriptive names, rather than shorter and more vague names. In “Clean Code” he writes:

“Don’t be afraid to make a name long. A long descriptive name is better than a short enigmatic name. A long descriptive name is better than a long descriptive comment. Use a naming convention that allows multiple words to be easily read in the function names, and then make use of those multiple words to give the function a name that says what it does.”

To add to that, I recently came across a concept: the “Principle of Least Astonishment” or POLA, which states that code should be written in a way that minimises the surprise of the reader. I think that by giving your event handlers descriptive names, you can make it clear what they do and reduce the potential for a surprise when reading the code.

javascriptprogrammingreactwebdev
  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.