Live data from Hacker News

Shit programmers write

shitprogrammerswrite.com

71–80 of 82 posts

Re: Shit programmers write

#71
post #16

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.

True. I find unit tests the most useful and economical when I'm testing algorithms, rather than data bookkeeping or user interfaces.

Re: Shit programmers write

#72
post #56

Earlier 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.

toString() blows up on a null value, the + operator does not.

I've written similar Java code for that reason.

Re: Shit programmers write

#73

I 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

Nope, 100% real. Copy pasted as is from a project I work on. Legacy code from 5? Years ago... No idea who the original author is. But it worked. It now uses newtonsoft.json library now.

About 6 years ago I wrote something similar, but that was before newtonsoft.json was super popular.

Re: Shit programmers write

#74
Is anyone else as infuriated as I am that you can't actually read any of the code?

Maybe 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

#75
post #16

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…

Best practices is something you learn over time, as you gain experience. I don't think there is a lack of best practices, it's just that there are always developers learning and gaining experience and before a best practice to make sense to them they have to do it wrong first. I.e. knowing the rules of chess doesn't make you a chess master.

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

#76
post #69

Earlier 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;

... or

  return foo || null;
if you're into that sort of thing

Re: Shit programmers write

#77
post #32

Earlier 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..

Yeah, it was a wild guess. I have a habit of making things more verbose for future maintainers.

Re: Shit programmers write

#78
post #7

Love this one: return foo == null ? null : foo;

This reminds me of this one, which is quite common: return foo == null ? true : false;

I did something of this kind recently and it was to enforce more of an api in my object, like internally I call some low api method that either gives me the object I'm looking for or false / null when doesn't find it, but in my interface I don't want to leak that object, just true or false. So

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

#79

Earlier 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?

It helps to understand the structure. I was looking for repetitions (and luckily I found a lot), but I needed to look out for things that change between repetitions.

I just found the picture I took that day. The boxing gloves just happened to be in the same conf room.

http://i.imgur.com/bQCA08C.jpg

Re: Shit programmers write

#80
post #24

Earlier 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;

To a non programmer or an absolute beginner? Sure, but then I would ask; why in the hell are you writing your code in a style catered to people who don't know what they are doing? That line simply shows that the writer doesn't understand Boolean expressions.
Post reply on HN