Live data from Hacker News

Shit programmers write

shitprogrammerswrite.com

31–40 of 82 posts

Re: Shit programmers write

#32
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;

Let's picture a future reader:

"Hmmm, if 'foo == null' is true, than it's true... I see..."

Seriously..

Re: Shit programmers write

#34

Earlier quoted context omitted.

I shell languages I do this a lot. if "x$VARIABLE" == "x" because it handles the cases where $VARIABLE is undefined or multiple words without vomiting all over the place.

I hate when people do that because it's not needed at all. The quoting already fixes everything. if [[ "$VARIABLE" == "" ]] or even better if [ -z "$VARIABLE" ] will handle undefined, empty and multiple words just fine.

Unless you're running with -u, which you should be, in which case it will blow up on an undefined variable. To treat undefined as empty, you want:

    if [[ -z "${VARIABLE:-}" ]]

Re: Shit programmers write

#35

A lot of these seem to be Microsoft technologies like C# or SQL server. Is that because the owner is more familiar with the MS stack? Or do MS devs have more to complain about?

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 over with different conditions. The guy who wrote it had no idea he could have extracted a method.

Re: Shit programmers write

#36

A lot of these seem to be Microsoft technologies like C# or SQL server. Is that because the owner is more familiar with the MS stack? Or do MS devs have more to complain about?

I'm not the owner, but I know the owner of the site. It's mostly C# / SQL because he is a .NET developer and so its only really been shared among other .NET devs.

It's not meant to be specific to any language. It's just funny shit people have written.

I submitted a few from old code I wrote like 5 years ago. Its all good fun :)

Re: Shit programmers write

#37
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…

The fact that you can write bad unit tests is orthogonal to the notion that writing unit tests is, in general, a good thing to do.

Re: Shit programmers write

#38
If this:

  function nop()
  {
      if (Math.random() == 0.1234567890)
      {
          for (var i = 0; i 
wouldn't have been written in JavaScript, my guess would be that this is an attempt to create an empty function (no-op) and prevent it from being optimized away by the compiler. Still unclear who may need to call it.

Re: Shit programmers write

#39
post #6

> if (Session["startDate"] + "" == "") This feels horribly familiar. I'm not sure to recognize the specific language used, but there must be cases where one would like to target empty of filled with non processable characters strings only, and let null and falsy values pass through. This kind of use would typically need a line of comment, but hey...

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.

Re: Shit programmers write

#40

A lot of these seem to be Microsoft technologies like C# or SQL server. Is that because the owner is more familiar with the MS stack? Or do MS devs have more to complain about?

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?
Post reply on HN