DEV Community

Discussion on: You're a Dev > So Write Like One. Thoughts on writing long-form, not short.

Collapse
 
hopemanryan profile image
Ryan Hoffman

The general idea of naming convention is that when I read your code I can assume what to expect the output of that function would be , (using interfaces is an extra bonus).
If you use a outside trigger to emit the function , the function should not care where its called from , as long as it gets the relevant arguments than it should all be fine.
Your suggestion could be relevant if there is some smart logic to do if the function is called from a click event and not from another place, so you can have a unique function from the click event (or pass it as an argument BTW - usually better ), Keep things as generic as possible is the key to go.

Thread Thread
 
brad_beggs profile image
Brad Beggs

Fair point about being able to assume correctly what the expected output is of a function. When you say generic is the way to go, what do you mean by generic? The names, or something else?

Thread Thread
 
hopemanryan profile image
Ryan Hoffman • Edited

It means not naming arguments (dataFromUserInput) => {...} and other examples can be added if needed.
simple is smooth, smooth is fast.
Making complex code is cool, but what happens if you want to change something, add something. how many places do you need to update your code in order to make your app not break, plus how many do you need to add to make the app show your change.

When you keep functions generic , i.e any one can use it and get the same result if they pass the same arguments , means many components of your code can use the same function for getting the information it wants, so changing only one function updates in a way in your entire application/server/whatever.

I went through your project and saw this line of code

<div className="service-specs" onClick={props.specClick}>
  1. I have no idea what specClick does,
  2. If I will want to run the same logic on inputChange what will you do ? add another prop ? I think not