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
-
I see that === 'function' is waay more logical in A. Lets go w/ that instead.😅
#nosleep -
dayo30538yI prefer B for anything other then a function/callback, but if you change the type check to function you can make sure it is a function before executing it
-
@fattymiller thats pretty smart, too, nice idea!
Even tho this might be hell for others who have to work w/ the code..^^ -
viking817428yA
It's not about compacting the code as much as possible. You should code so it's possible to skim through and understand.
These alternatives have pretty much no performance impact either way, so it's more showing off than leaving readable code after you.
Hipster code. Stick with readability as if the person inheriting your code is a crazy serial killer. -
@viking8 absolutely, of course.
But readability is a relative thing. Imagine like 2 or 3 ifs and a loop where this callback gets called in. Imho, a compact line is much more readable there as another if-thing.
You should always go for readability, i never said sth else, but i was just curious how others would compress such an often-happening, easy thing.(:
I wouldn't call it hipster code right away, perl existed ages ago and introduced magically working oneliners. -
I'd definitely go with C. It's concise, expressive and it doesn't involve any "wait what was that again, oh yeah, right..." Moment when you go back to it months later. Especially B I think could seriously trip you up, it's a beautiful line of code, but maintenance is probably a massive pain.
Related Rants
!rant
Aside from performance concerns.. which one would you prefer for an optional callback?:b
I always use B, but i'm kinda interested in what you guys say.
✌
undefined
js
readability
logic
whatchathinkin