I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
is quite difficult to read, because in cases where you have proper variable names you have to dart your eyes left and right and count the position of each thing to know what's being assinged to what.
It also makes version control more difficult because if these were each on their own line then changes would be easier to spot.
Short circuits are popular in REPLs or shell scripts:
isLoggedin&&goToHomepage();
... but they make things harder to read in anything but trivial cases and it's easier to make mistakes. @mcsee has a good post about it -
I'm all for multiple value checking, but examples like this:
if([1,'one',2,'two'].includes(value)){
imply that value could be different types, and that's usually a code smell in itself.
Converting to numbers with parseInt needs a second argument, the base that's going to be used. Otherwise you might get some unexpected results. Your shorthand version is better in that case, but using values like +'23' as a kind of cast is going to make the next person to look at the code wonder if you left something out.
I have a few concerns about some of these.
This pattern:
is quite difficult to read, because in cases where you have proper variable names you have to dart your eyes left and right and count the position of each thing to know what's being assinged to what.
It also makes version control more difficult because if these were each on their own line then changes would be easier to spot.
Short circuits are popular in REPLs or shell scripts:
... but they make things harder to read in anything but trivial cases and it's easier to make mistakes. @mcsee has a good post about it -
Code Smell 145 - Short Circuit Hack
Maxi Contieri ・ Jun 30 ・ 2 min read
I'm all for multiple value checking, but examples like this:
imply that
value
could be different types, and that's usually a code smell in itself.Converting to numbers with
parseInt
needs a second argument, the base that's going to be used. Otherwise you might get some unexpected results. Your shorthand version is better in that case, but using values like+'23'
as a kind of cast is going to make the next person to look at the code wonder if you left something out.Most of these are concerns due to what you consider to be readable, and readability is purely subjective.