Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Voxera113886yI mostly use arrow functions for single expression functions that fits in one line within the screen.
One exception is when I need to preserve “this” in js in for example a react component, but in those cases the arrow function also always follow the assignment so its quite obvious.
For long expressions I usually break them apart into several consecutive expression with intermediate variables indicating purpose or break out parts into separate functions to make reading and understanding easier.
One prominent exception when I use arrow functions along with a function body with {} is if I need multiple almost identical functions that for some reason is difficult to convert into an expression.
I then some times make long one liners IF this means that its obvious for the reader that its almost repeating code and the fact that every line starts with the name is sufficient to convey what is going on.
For example when I bind external functions into out script engine.
I bind round 60 external calls and having them one per line with the name first makes it very easy to find the binding you are looking for.
But I always try it out and go with whatever looks easiest to read or understand, that is more important than consistency for consistency’s sake. -
perymimon396y@Voxera nice I like to read what you write. I also play with my code until it satisfaction my ability to read it easily.
I started thinking of back using `function` statement as a default for call back. because even for writes it make more sense to declare myself that i'm going to write function now and then thinking about the argument . then write variables and then say it will be arguments for next expression -
[Serious question] Aren't you supposed to stick to a single style when you write code? That's why I use arrow functions for all my function definitions in the first place.
Anyway, I believe this is the language fault to have more than one way to do a task. -
Voxera113886y@rantsauce no there is no point in sticking to only one, they are good for different purposes.
To hard policy’s on code style will lead to some very odd code, especially with new people on the team.
A guideline along with code review to polish off rough edges is good but go to far an productivity and readability will be hampered.
Also, a to strict policy will have a harder time with a language that evolves.
But that just my opinion.
I hate the overuse of arrow function everywhere even for super long expression. that `function` should fit to them more comfortably .
writer of code should aware that it take three time more to read expiration with arrow function inside
devrant
js arrow function