Live data from Hacker News

Shit programmers write

shitprogrammerswrite.com

41–50 of 82 posts

Re: Shit programmers write

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

Re: Shit programmers write

#42

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…

I replaced an old AS400 system from the 70s as one of my first gigs. It was 50k lines of incomprehensible RPG code. I would often have to print out the code, steal a conference room, lay out all the pages, and go to town with a bunch of highlighters to tell what the hell was going on.

On the plus side, the code still had comments for the punchcard numbers, so it was pretty easy to keep the pages in order :)

Re: Shit programmers write

#43
I wonder how much of that is due to problems in documentation/documentation discoverability. This seems precisely the kind of data that we need to make docs better.

Re: Shit programmers write

#44

    if (Math.random() == 0.1234567890)
    {
        for (var i = 0; i 
Reminds me of the code I have to insert to prevent overzealous compilers from completely optimizing away my benchmark loops.

Re: Shit programmers write

#45

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…

This is my life.

Re: Shit programmers write

#46

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?

Every once in a while you find code whose control structures are wrapped around a ton of working code... paging up and down to try to grok the entire structure pagefaults my short term memory badly enough that having it all visible at once is the only workaround.

Sometimes, if you're really lucky, the blocks of working code don't modify their own conditionals, and you can 'fold' them and just look at the if's and loops...

Re: Shit programmers write

#47
public bool ShowOptional() { bool bolReturn = false;

    return bolReturn;
}

The above actually seems reasonable if you assume the programmer that wrote it was intelligent. I'm imagining that the above code is called multiple times by the application, for a new optional feature in development. Currently, they haven't developed the feature, and so we are always returning false. But in the future, we likely will want to show the feature given some condition. So this programmer has (hopefully) decided that (s)he will write the current code to take this future development into account, and rather than pass some boolean or config value throughout the code, has isolated it to one specific method.

Now, when they go to implement Optional, whatever that is, that developer can just update this one method with the expression, and go about coding their feature without any knowledge of the previous code base, which is exactly what's supposed to happen.

Re: Shit programmers write

#48
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 

Re: Shit programmers write

#49

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?

For me, the ability to spread the paper across a table and look at many different parts of the code simultaneously. It's like having a giant high resolution monitor.

Also, faster and more flexible annotation (drawings, etc), but that's secondary.

Re: Shit programmers write

#50

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

I assume item itself is missing, so nothing to convert... My guess
Post reply on HN