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.
I didn't know about trunc and I would have just used parseInt without giving it a thought, but that gotcha you explain is a good point.
Unless I was mimimising/golfing or there's a tiny performance benefit and you're performing the operation a gazillion times per second, I'd stay clear of the bitwise tricks. They're curiosities but they make the code difficult to read.
I guess bitwise operators are not as popular, so if you use it in your code it’s probably going to make a few people spin their heads as to what’s going on 😵... honestly, I have never used bitwise operator in my code before 😥 do you know if there are any other gotcha with using bitwise operators?
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.
Totally! Writing code is like communication, sure you can use all the fancy lingo. But if no one understands you, are you actually communicating. Good call! 👍
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I didn't know about
trunc
and I would have just usedparseInt
without giving it a thought, but that gotcha you explain is a good point.Unless I was mimimising/golfing or there's a tiny performance benefit and you're performing the operation a gazillion times per second, I'd stay clear of the bitwise tricks. They're curiosities but they make the code difficult to read.
I guess bitwise operators are not as popular, so if you use it in your code it’s probably going to make a few people spin their heads as to what’s going on 😵... honestly, I have never used bitwise operator in my code before 😥 do you know if there are any other gotcha with using bitwise operators?
I don't think so, but I like to write code as if the person maintaining it isn't familiar with all these little tricks!
Totally! Writing code is like communication, sure you can use all the fancy lingo. But if no one understands you, are you actually communicating. Good call! 👍