A lot of these seem to be attempts to fit into existing "best practices". Unit tests that prove nothing. Boilerplate Java code that does nothing. Maybe we should reevaluate some best practices. I have debated before on here that many unit tests seem useless as the units are too small, and you essentially end up testing your language or framework which you already know works. Integration testing on the other hand make…
I always feel happiest writing unit tests for functions that contain non-trivial logic . But I always feel sad when testing methods that mostly just introduce side effects. It seems like when I'm running into more of the latter, it is often worthwhile to find ways to refactor toward having more of the former, but sometimes not.
Shit programmers write
71–80 of 82 posts
Re: Shit programmers write
#72Earlier quoted context omitted.
Do this in javascript all the time. Adding a `+ ""` forces the object to become a string. Though not sure why it was required for this particular comparison.
Why not use toString()? It is clearer to the reader that way.
I've written similar Java code for that reason.
Re: Shit programmers write
#73I haven't slept well lastnight (only 4 hours) so please bear with me... but what is the joke on this snippet? "I Don’t Know".ToJson(); public string ToJson() { var s = new StringBuilder("{"); for (var i = 0; i
About 6 years ago I wrote something similar, but that was before newtonsoft.json was super popular.
Re: Shit programmers write
#74Maybe I'm missing a button somewhere, but I needed to open up the DOM inspector or RSS feed to read every single one.
Unacceptable
Re: Shit programmers write
#75A lot of these seem to be attempts to fit into existing "best practices". Unit tests that prove nothing. Boilerplate Java code that does nothing. Maybe we should reevaluate some best practices. I have debated before on here that many unit tests seem useless as the units are too small, and you essentially end up testing your language or framework which you already know works. Integration testing on the other hand make…
As I mature as a developer I notice that it takes more and more time for me to finish something. When I was younger I simply wasn't aware of half the stuff that could go wrong. Now I'm older and I am aware I find myself taking more and more time to implement something and spend a lot more time on e.g. clean interfaces and error handling. Something I simply didn't do many many years ago.
Re: Shit programmers write
#76Earlier quoted context omitted.
That one makes a bit of sense in Javascript as it'd return null if foo was null OR undefined.
It might be technically correct, but if the intention was a loose comparison surely don't include null in the comparison? return !foo ? null : foo;
return foo || null;
if you're into that sort of thingRe: Shit programmers write
#77Earlier quoted context omitted.
Maybe this is a programmer who likes to spell things out for future readers. It's easier to convey meaning with return foo == null ? true : false;
Let's picture a future reader: "Hmmm, if 'foo == null' is true, than it's true... I see..." Seriously..
Re: Shit programmers write
#78Love this one: return foo == null ? null : foo;
This reminds me of this one, which is quite common: return foo == null ? true : false;
function isAvailable(){ objInDb = findByName('Joan Carlos'); // the object or false
return objInDb ? true : false;
}But all this could be because I'm a noob in a language I don't really know... Php that magical land where nothing is what it looks like and is always ready to stab you in the back, can't say I'm a fan of it... Or dynamic languages, or anything magical... Ok, I'm going to places I don't want to remember, sorry...
Re: Shit programmers write
#79Earlier quoted context omitted.
From my experience, such code is not specific to MS technologies, but is indeed often found in “enterprisey” code, a lot of which just happens to be in Java and C#. And enterprisey code is like that because it's often outsourced to the lowest bidder. I once had to print a method that took 50 pages of paper, so I could understand what it does, and after 15 minutes I realized it's the same 60 lines repeated over and ov…
Just curious: Why does printing it on paper helps you to understand code better than reading it on screen?
I just found the picture I took that day. The boxing gloves just happened to be in the same conf room.
Re: Shit programmers write
#80Earlier quoted context omitted.
The result of "foo == null" (or better "foo === null") is boolean, I don't know what is the "equivalence" problem here.
Maybe this is a programmer who likes to spell things out for future readers. It's easier to convey meaning with return foo == null ? true : false;