Live data from Hacker News

Shit programmers write

shitprogrammerswrite.com

11–20 of 82 posts

Re: Shit programmers write

#11
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?

Re: Shit programmers write

#13
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 sometimes do that in PHP because I hate the equivalence between "", false, null, '0' and 0. Seeing true and false written out makes it more readable.

Re: Shit programmers write

#14
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...

I'm guessing you don't realize that the plus operator has less precedence than the == operator. That if is equivalent to if (startDate + true) EDIT: I was wrong. I haven't slept.

Does it mean if(1 + 1 == 2) is equivalent to if(1 + true)?

Re: Shit programmers write

#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 makes a lot more sens.

When I started with Java, it seemed appropriate to put hundreds of getter / setter methods. Is there much advantage to that over allowing the variable to be accessed directly? (Perl felt very strange at first having getter and setter methods combined as one method).

As I get more experienced as a developer, my skill set has grown but my coding becomes simpler. Don't use every language feature to show how knowledgeable you are. Use it when appropriate, and when it makes the code more readable / reusable / simpler. Sometimes a higher level abstraction is more difficult to understand , but is overall better choice. An example would be a map as opposed to a for loop. Less chance of side effects in a map, as we don't have to track the iterator variable, but a map is not as intuitive for less experienced coders.

Re: Shit programmers write

#18
post #13
post #7

Earlier quoted context omitted.

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

I sometimes do that in PHP because I hate the equivalence between "", false, null, '0' and 0. Seeing true and false written out makes it more readable.

would a comment not be more appropriate in such circumstances?

Re: Shit programmers write

#19

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

I don't think people tend to write this kind of code, per se.

Rather, it "evolves".

It starts as:

  return foo == null ? error_handler(bar) : foo;
And someone realizes error_handler actually does nothing, so replaces all calls with null, mechanically.

Re: Shit programmers write

#20
post #14

Earlier quoted context omitted.

I'm guessing you don't realize that the plus operator has less precedence than the == operator. That if is equivalent to if (startDate + true) EDIT: I was wrong. I haven't slept.

Does it mean if(1 + 1 == 2) is equivalent to if(1 + true)?

1) + has a higher precedence than ==

2) even if == had a higher precedence, then 1 == 2 would still be false :D

Post reply on HN