Wait, What?
github.com
github.com
!((_ok) ? true : (Math.random() > 0.1))
_ok ? false : !(Math.random() > 0.1)
!_ok && Math.random() <= 0.1
Seems fine...until you realise that this is the condition to exit early, it's still logging 90% of the time which is almost certainly not the desired behavior.Not to mention _ok is a terrible name for that variable, and it's only ever being used as a negation. Why isn't it called _error or something?
if(!((_ok) ? true : (Math.random() > 0.1)))
when you could use if(!(_ok || Math.random() > 0.1))
or just if(!_ok && Math.random() < 0.1)
?One Evening, Close to 5:
Boss: "I see we're getting quite a few exception reports in the code."
Developer: "Yeah, working on that. I just need a bit of time."
Boss: "Well, I want to see at least 10% fewer exceptions by tomorrow morning."
Developer: "..."
Next Morning:
Boss: "So I took a look at the reports this morning. Glad to see the number of exceptions are down."
Developer: "..."
Probably got a raise.
I had a young developer work for me that did this all the time. He was actually quite brilliant - but he would put sometimes 20 statements into one line of code that would scroll past the end of the screen. It was difficult to discern intent but even worse it was impossible to debug. I asked him several times if he was taking his programming style from:
Well, there is. More LOC is the most stable predictor of more bugs.
Of course, complexity per LOC also matters.
This is why Python's PEP8 recommends an 80 char limit on line length. Not because at column 81 the code magically becomes more complicated, but because if you're struggling to make it all fit on one line, it's probably a good sign that you need to factor out some complexity.
Although you could certainly still write extremely terse (read: unreadable) code with less than 80 chars per line.