When writing code, it is always better to be as explicit as possible instead of going for tricks. This concept is best explained by examples so let...
For further actions, you may consider blocking this person and/or reporting abuse
I pretty much agree with this, but what is and isn't a trick is largely a matter of perception, and may change with time. Specifically, I remember learning
!!
to convert something to a boolean, and I didn't regard it as a trick. To me, it was just the way you convert something to a boolean. It's what I and the people around me did. I don't think I even knew aboutBoolean()
then.I think the perception that it's a fancy trick is one that has grown and become more common over time. Now I too regard it as one, and use
Boolean()
instead.That is exactly what we wish to rectify.
Very bad idea. Will only drag down the quality of developers over time.
Teach people all about the language, don't blindly preach dogma and opinions. Show them the ins and outs of it, how it works, and different ways of doing the same things. Don't patronise them and treat them like children unable to make decisions about which way to do it is best for them or their project.
Readability is purely subjective, and marking parts of the language as 'off limits' or 'bad practice' inhibits knowledge, and potentially the performance of software.
It's this kind of thinking that has progressively dragged down and overcomplicated software over the past decade or more, particularly in web development.
A lot of the time, they do add performance benefit - and it can be considerable (a quick test showed
!!
to be consistently faster thanBoolean
- more than twice as fast in fact)Boolean is as fast as !!. Your test is not accurate.
github.com/solidjs/solid/pull/500#...
Run this in both Chrome and Firefox.
!!
is faster in both, and on Firefox it is almost twice as fastIf you want the simplest test possible, try this - not quite such a pronounced difference, but
!!
still fasterNot for me.
dev-to-uploads.s3.amazonaws.com/up...
Interesting. It's faster for me both on Mac, Linux, and Android - on both Firefox and Chrome
That is some quality input. Appreciated!
Just a side note about type casting. Kind of have to deal with it in JavaScript since all incoming data from the DOM is of type string!
I agree with all your points, but could you change the links to something more descriptive than, "click here"?
A screen reader listing links out will speak them all the same.
Thanks for highlighting this. I've updated the link texts.