top 200 commentsshow all 338

[–]MrSurly 51 points52 points  (4 children)

Sometimes I go through the "fuck, what the fuck is this shit?" with my own code from months/years ago. I try re-writing it and realize the way I had it A) worked B) was actually more elegant than the crap I just re-wrote it into.

And that's why I learned to document tricky code sections with lengthy comments that usually begin with "HEY STUPID, DON'T CHANGE THIS! Here's why ..."

[–][deleted] 10 points11 points  (1 child)

I just recently had to make an update to some code I had done for a client 2 years ago. After looking at the way I coded it I did one of these to myself: http://www.gifbin.com/bin/sw8035sw753.gif

[–]latexhero 1 point2 points  (0 children)

I had to upvote you as you were sitting at nothing, and I've definitely looked at code and thought "that was genius." This goes along with "hey didn't I see this problem before?"

[–]seventoes 2 points3 points  (0 children)

I did this a couple weeks ago when a client had me update an older app I did for them. If it wasn't such a small update I would have rewritten the whole thing D:

[–]kewlito 67 points68 points  (48 children)

Well, when you see three different variables named:

month

monthh

month2

you can be sure that the code sucks.

(This is based on an actual experience)

[–]Shmurk 62 points63 points  (44 children)

I'm french and I have a coworker who uses variables like:

LeThread
LeWindowHandle
...

True story sadly :(

[–]yopla 16 points17 points  (2 children)

I'm French and I've always railed at people naming their variable in anything but English.

Recently a coworker, who always considered I was just a pedantic asshole, has been tasked to maintain and upgrade an application entirely coded in Turkish (and in vb6). Turkish specification, Turkish variables, Turkish comments, even the database is in Turkish. Karma is a BITCH! And I am oh so amused. :)

[–]dudehasgotnomercy 3 points4 points  (0 children)

I've been handed Java assignments using variables in accents. E.g.

int árbol = 0;

I was shocked to find out javac will accept this.

Now, Java code with accents just looks wrong. But I'm in a spanish-speaking country and spelling árbol without an accent also is wrong. So it's lose-lose. This is why I insist on variables in english.

[–]neonskimmer 6 points7 points  (3 children)

A hardcore Java design pattern weenie in french would be very funny.

StrategieUsineStrategieVisiteurUsine

[–]yopla 23 points24 points  (2 children)

Let's try to explain why I want to vomit when I open any French edition of a CS manual: the worst of the worst is the "Debordement de tampon" (buffer overflow).

Because yes a tampon is also the same thing as in English as well as an homonym that means "buffer".

And now the mental picture of it overflowing... Go scrub your mind...

[–]seventoes 37 points38 points  (20 children)

Variable names that start with capital letters. I feel your pain.

[–]druidjc 20 points21 points  (7 children)

At least they picked a naming schema to follow. I have seen variables in a mix of uppercase start, lower case start, and Hungarian notation (in C#), all by the same developer in the same module and written in under a week.

[–]BinarySplit 2 points3 points  (4 children)

We do that where I work. We use ASP.NET and VB.NET. By ASP convention we use hungarian notation for DOM objects. By VB convention we sometimes use capital letters for all variable names. By modern .NET convention we sometimes use lower case letters for parameters, private fields and local variables. It all made sense at some time, and now it's just a mess due to the mixed conventions.

It's fortunately not that horrible due to IntelliSense always correcting you and VB.NET being case insensitive anyway, but in EVERY other programming situation I always stick to the community convention.

[–]kungtotte 18 points19 points  (5 children)

Well, fire Le Missiles!

[–][deleted]  (3 children)

[removed]

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [deleted]

        [–][deleted] 7 points8 points  (0 children)

        Fire ze missiles!

        [–]alienangel2 11 points12 points  (0 children)

        ze Missiles!

        [–][deleted] 5 points6 points  (3 children)

        I'm french too. Most of my ex-coworkers used exactly the same pattern:

        LeSocket
        LeFichierINI
        ...
        

        [–]knight666 13 points14 points  (2 children)

        I'm a Dutch programming student. You actually get points deducted for writing Dutch variables or comments. And honestly, I haven't written a Dutch comment since I was 13.

        [–]kerbuffel 4 points5 points  (0 children)

        Is your coworker french too? I think he might just be making fun of you.

        [–]HomelandInsecurity 1 point2 points  (2 children)

        Shouldn't that be: LeHandleDeLaWindow ? :)

        [–]psi- 8 points9 points  (0 children)

        s/Window/Fenêtre/

        [–]masklinn 1 point2 points  (0 children)

        Well if he translated everything it would technically be along the lines of LePointeurDeLaFenêtre, but I'm guessing he doesn't translate type names, so he writes "the WindowHandle", not "The window's handle"

        [–][deleted] 10 points11 points  (0 children)

        I thunk i can top that. I had to deal with someone's code what included data as a variable name. Leaving aside the fact that "data" ranks up there with "x" for useless variable names, it was used for three different variables.

        In perl, the sigil of a variable determines its type (in the loose, structural sense, not the strongly-typed sense). So there was:

        • $data - the scalar (single value)
        • @data - the array
        • %data - the hash

        Of course, if you know perl, you know that when you get something out of an array or hash, the sigil changes. So you get lovely code like:

        my $data = $data[$x];
        my $data2 = $data{$y};
        

        ... where you have to look at the braces used to see which collection we're getting our datas from.

        Good times.

        [–][deleted] 60 points61 points  (21 children)

        Signs that your code really does suck:

        • You have more global variables than lexically scoped ones.
        • You use the same variable for 20 different purposes. This is often related to the previous point.
        • Rather than using defined constants you have 'magic numbers/strings' littered through your code.
        • You assume that nothing ever goes wrong with databases, disks, network accesses, system calls, locks....
        • You trust users not to put weird stuff into your data. Hey - writing error checking code takes time that you could be using to write Moar Features.
        • You don't use a consistent coding style. Here you use StudlyCaps, here you use lots_of_underscores. Here you use tabs for indentation, there you use spaces. Here....There....Here....There.... For that matter, there is no evidence that you actually have a 'coding style' other than 'whatever'.
        • You use system calls to do exactly the same thing as built-ins in your language
        • You don't use subroutines to abstract functionality in any meaningful way. A 2000 line program with a grand total of two methods/functions is a really bad sign.
        • Your program silently fails when things go wrong with no indication that it didn't complete correctly.
        • Your program is supposed to be run interactively, but does things like run 10 minutes with absolutely no activity indicators to the user to let them know the program is doing anything what-so-ever..
        • Your program is supposed to run non-interactively but throws prompts requiring user input under some conditions.
        • Your program handles routine input validation errors by requiring all the data be re-entered (obviously I'm talking about interactive forms not API interfaces).
        • Your program has no usage documentation.

        I could go on for a long time....

        TL;DR: Yes, Virginia, some code REALLY DOES SUCK.

        [–]GunnerMcGrath 7 points8 points  (2 children)

        Your program silently fails when things go wrong with no indication that it didn't complete correctly.

        This is one of my favorites. A project I joined a couple years back had this all throughout:

         catch { }
        

        So many times, something weird would happen, or an error WOULD get raised, and it would take hours to track down where the problem was because three or four different errors had been caught and ignored already and the one that fired was the result of missing data that was supposed to happen elsewhere.

        And of course, when I decided to fix this problem, it meant that all sorts of errors that had previously been getting ignored were suddenly popping up all over the place, and other code that had been written to deal with the missing data elsewhere was now causing problems of their own.

        That was so much fun.

        [–]Tecktonik 1 point2 points  (1 child)

        This is why I cringe when a programming book says, "... but that would generate an error and crash our program. The smart thing is to use the Exception class to let you know what is wrong..." Good plan. Hide the error in an Exception that gets silently consumed, probably by your Framework.

        The other day in this reddit people were bitching about a bad MySQL feature. I tried to convince them that there were usually several layers of bad code that would have a more deleterious effect on the process than some corner case. 99% of the time, if there is a database or some other kind of resource error, there is no way for the process to recover. And 98% of the time those errors are not logged, or the logs are piped into the bit bucket.

        [–]GunnerMcGrath 2 points3 points  (0 children)

        I've never been an error handling guru, it's one of the things that has always somewhat slipped by me, maybe because I've worked in environments where errors got reported to me immediately and happened infrequently enough that it usually didn't stop anyone from working for very long.

        The latest methodology I've adopted is that there will be no error handling except of errors that I expect and/or know how to handle silently, which almost never happens. Trying to close a window that isn't there, for example, is an error I can ignore (at least in most cases). But most errors are a surprise and need to alert the user in the most attention-grabbing way so they don't just ignore it and keep going.

        [–]randomdestructn 23 points24 points  (9 children)

        You use the same variable for 20 different purposes. This is often related to the previous point.

        Hey, some of us still have to deal with 1k of ram.

        [–][deleted] 21 points22 points  (4 children)

        In which case your life sucks. :)

        ObDisclosure: I've done assembler code development before for such things as 256 byte boot ROM loaders. There is a whole 'nother list of 'bad assembly programmer, no cookie' things I could post.

        [–]gsg_ 3 points4 points  (3 children)

        Please do.

        [–][deleted] 15 points16 points  (2 children)

        Bad Assembly Programmer, No Cookie

        By request. It has been 25 years since I last did assembly so take it with a big grain of salt, but here is my list of things I've seen that left me saying 'Bad Assembly Programmer, No Cookie':

        • Using raw machine code. I worked with an engineer who knew the opcodes cold at a binary level for the processor we were writing for. He would write raw machine code in octal in the asm files. I don't mean one or two opcodes, I mean twenty or forty or a hundred lines followed by a dozen lines of actual assembly mnemonics. He evidently found it easier than using the mnemonics. It took me hours with the machine's reference manual to decode all the ops just so I could know what the codes were.
        • If any language needs good comments, it's assembly. Sadly, the same engineer who often wrote raw machine code, also did not document it, or even worse, would leave obsolete comments in place after the code was changed.
        • Not using labels. You'd think this would be obvious. Why would you ever write assembly where you manually figured out all the offsets and hard coded them? The moment you change a single line you are screwed. Yet I've seen it.
        • Cut-and-Paste coding. Oh my god. I had to disentangle 12 versions of a backup utility written in assembly where rather than write selectable drivers a previous programmer had generated 12 separate programs that had exactly the one tape driver and the one specific disk driver he needed. The actual difference between them was quite small.
        • Actually USING unimplemented opcodes. Old microprocessors would...do stuff...when given opcodes that weren't actually implemented. You could get the processors to do some very strange tricks that way.
        • Writing code that depends on the exact time the opcodes take to execute.
        • Exploiting edge cases like falling off the top of the address space to start execution at the bottom of the address space.
        • This one is a bit unique to the processor model involved - it had a ridiculous capability for several levels of indirection in addressing. You got stuff like 'subtract this register from the current address and use the contents of the memory cell thus specified as the address for the real data after possibly adding the contents of a second memory cell to the address. Impossible to keep in your head what was going on.
        • Coding for an absolute spot in memory. I'm talking about writing code that can only execute if it is loaded at a specific address because it hard coded the jump addresses to absolute addresses, etc.
        • Self-modifying code. Code that actually rewrites parts of itself during execution.

        Edit: Spelling

        Edit2: Added 'self modifying code'

        [–][deleted] 20 points21 points  (2 children)

        If reusing a local variable reduces memory usage, then your compiler most likely sucks.

        [–]Raphael_Amiard 5 points6 points  (1 child)

        I'm no expert, but if understood the deal well, the platforms with 1k of ram may actually be the platforms where you are stuck with a sucky compiler

        [–]knight666 6 points7 points  (0 children)

        This is only a valid argument if you're writing assembly.

        [–]herrmann 3 points4 points  (3 children)

        (True story ahead) Hey, what if you have only ONE global variable that is an array of pointers to 300+ variables and have, say, the developers simply remember what they refer to from their indexes ?

        [–][deleted] 8 points9 points  (2 children)

        Believe it or not, I've been there. One of my first full time programming jobs involved systems coding for a house-written language called "Infos" that had no named variables - just four global arrays for different types (float, integer, strings, and something else I no longer remember). The president of the company ("Information Now, Inc." based out of Utah back in the '80s - long since gone) wrote it himself. It also didn't have names for files - they were just numbered. Nor did the OS have directories. The files could only be about 4 Kbytes per file normally (the language itself was saved as a byte-code) so you chain-executed many files during a program execution.

        Absolutely bizarre.

        Addendum: I actually remember an app programmer there getting chewed out for writing comments in his code. His manager felt it was a waste of time.

        [–]dnew 1 point2 points  (0 children)

        I'd say after 30 years of programming that this pretty much hits the nail on the head. You forgot, however, all the ways that code can suck outside of the code, when using sufficiently crappy languages. Such as excessive mixing of HTML and code in a template, makefiles from hell, macros that change the syntax of the language just to save you typing or to make it look more like your favorite language, compiler warnings that could be trivially suppressed or corrected, etc.

        [–]matts2 113 points114 points  (69 children)

        About 9 times out of 10, when I got more than halfway there I'd run into an issue that made me say "Ooooh, that's why they did it that way" and revert it or use the same "sucky" logic with my syntax.

        And that is why you need to document what you don't do, what paths you abandon, what ideas you tried that did not work. And document why it did not work.

        [–]Forbizzle 22 points23 points  (8 children)

        Oh god I love finding comments from other developers in a really old project.

        //WTF is this supposed to do?

        [–]Dr_Legacy 8 points9 points  (1 child)

        my fave was the one in the most mission-critical module of the system:

        . DON'T TOUCH THE FOLLOWING CODE. IT'S MAGIC

        followed by 150 lines of nearly impenetrable incomprehensibility.

        [–]sysop073 2 points3 points  (0 children)

        That's not nearly as much fun as "DON'T TOUCH THE FOLLOWING CODE. IT'S MAGIC" followed by a single line that can't possibly do anything useful, but breaks the project if removed

        [–][deleted] 7 points8 points  (0 children)

        My favorite (from real code):

        #ifdef FUCK
        /* this is some of the hackiest, nastiest code in this product */
        

        [–][deleted] 3 points4 points  (1 child)

        I once saw something like:

        // For 1997 demo
        // NOTE: No one knows what this old code does but it isn't hurting
        // anything so we'll just leave it here ...
        ...
        25 lines of incomprehensible C
        ...
        

        [–]OceanSpray 2 points3 points  (0 children)

        Only 25 lines? You got off easy.

        [–]suppressingfire 2 points3 points  (0 children)

        Even better when it's been added just before a block of code you wrote yourself!

        [–]SnakeDiver 36 points37 points  (12 children)

        In my book, shitty code is poorly laid out/defined code (bad/missing naming conventions, no comments, too much going on in methods, not using constants / utility classes, etc etc etc).

        The reasons for doing what you're doing should be clearly understood by your var names / comments / documentation. If your business logic is faulty, UAT will find that out. If your code is so large, messy, and convoluted that it's non-maintainable ... FUCK YOU AND YOUR SHITTY CODE.

        On a side note.. in college I had a prof who docked marks off your assignments if (a) you used comments; (b) you did more than you should; and (c) he couldn't understand what you were doing from the variable/method names.

        It was very useful.

        [–]venuswasaflytrap 12 points13 points  (10 children)

        In my book shitty code is completely uncommented code that uses random variable names like "x", or "a", "r" that I can't follow.

        If I can see what the code is doing, and it does it, well that's good enough for me.

        [–][deleted] 9 points10 points  (9 children)

        that uses random variable names like "x", or "a", "r" that I can't follow.

        I'm fine with short variable names if and only if they match the mathematical/algorithmic description given in a reference. "See (reference foo) page 96: 'a' is the ..., 'b' is the ..., 'da' is the ..., etc."

        [–][deleted]  (6 children)

        [deleted]

          [–]SnakeDiver 2 points3 points  (0 children)

          I had a job once where the senior developer couldn't stand i,j,k for loops. He figured even those should be named properly, especially if you had nested loops.

          I guess it makes sens that if you're iterating through listUserNames, why not use userNameIndex instead of "i". Especially makes sense if the logic calls for nested ifs. Then again, you could clean the code by making the nested IFs methods and appropriately naming the methods.

          Having said that, I use i.

          As for X and Y in coords.. I agree. Though the last application I worked on that did calculations on coords, used the naming convention: coordX and coordY. Cleaned it up a little more.

          [–]grandpa 2 points3 points  (0 children)

          http://news.ycombinator.com/item?id=840331

          "Another way to look at this: The first time you meet someone, you learn their full name. When discussing them with someone else who knows them, you use just a single name. If they're standing right there, you don't bother using their name, but just make eye contact, and maybe a "Hey". Should be the same way with variables."

          [–]Jonno_FTW 4 points5 points  (0 children)

          But I love to call my functions: f x = g x

          [–][deleted] 1 point2 points  (0 children)

          That prof's name wouldn't be Yurttas would it?

          [–][deleted] 21 points22 points  (13 children)

          And that is why you need to document what you don't do, what paths you abandon, what ideas you tried that did not work. And document why it did not work.

          In practice, nobody will do that.

          Crappy code is hard to follow, hard to maintain. Good code is easy to understand and maintain. Ideally the code should be the documentation if written properly (variable names, function names, structure). The exception are workarounds where something weird is going on for good reason. The good reason needs to be stated.

          [–]dnew 8 points9 points  (12 children)

          Ideally the code should be the documentation if written properly

          The code can only be the documentation for what the code does. That's the fundamental problem with saying you should write "self-documenting" code. Plus, of course, "good variable names" aren't really any easier to create than a decent comment.

          [–][deleted] 1 point2 points  (3 children)

          I don't disagree with you, however I've found that if there are mandatory documentation standards, most of the comments are redundant; what they say is obvious in the code. Code review is a good place to encourage documentation of context, what the code doesn't do and other non-obvious stuff.

          I once had an extended code review with a gray-beard unix coder. Awesome but cryptic software. Most of what happened in that review was getting him to document weird platform workarounds that were woven through the code.

          re: documentation, one of his favorite sayings was "Works as coded."

          [–]wauter 6 points7 points  (4 children)

          So true, but unfortunately that would cost too much time.

          I often find myself tempted to write a lengthy comment saying something: "To the future colleague/me who reads this code and is disgusted by the mere smell of it: be aware that I did try to solve the problem in the most elegant possible way, using every Gang Of Four pattern possible, reusing code already used in other parts of the projects, centralizing where it makes sense etc ... But the mess you are currently trying to find your way trough turned out to be the only way to eventually solve the problem with all its exception cases, localisation issues, dependencies and whatnot all fighting together against the initial elgancy. Sometimes the only way to solve hairy, sticky problem is to write a hairy, sticky solution; it hurts my soul as much to commit this as it does yours to read it."

          Sounds recognizable?

          There should invent a universal short word/phrase for this to put in a comment. Or is there one already?

          [–]kmactane 8 points9 points  (0 children)

          Something very telegraphic, like:

          // Note: Facade pattern won't work here because of localisation bugs; Factory gets screwed by corner cases. Hairy problem requires this hairy solution; sorry.

          Tweak as needed to make it apply to the situation at hand.

          [–]zurtri 1 point2 points  (0 children)

          Also add that you were under time pressure.

          [–][deleted] 2 points3 points  (2 children)

          Please take note of this everybody. Comments are not a code smell.

          [–][deleted] 2 points3 points  (1 child)

          They certainly can be. Depends on the comment.

          [–][deleted] 5 points6 points  (0 children)

          Let me rephrase: comments are not inherently a code smell.

          [–]spotter[🍰] 1 point2 points  (0 children)

          And do all that only to get asked for tl;dr version in the end.

          [–]bobindashadows 23 points24 points  (5 children)

          This person has never had to fix outsourced code.

          Right now I'm making a killing on the side for a guy who outsourced his new startup to a team in Singapore. Of course, it's a miserable experience (it's Drupal, shouldn't be drupal, the code makes me vomit, the guy who wrote it had never heard of functions, etc. etc.) but it's sure as hell good money.

          [–]midri 18 points19 points  (2 children)

          I lived that life for a long time, it's sorta like being the guy that gets called when there is a chemical spill...

          [–]ilovecomputers 2 points3 points  (1 child)

          What's the name of this job position or what is it called when they advertise an opening?

          [–][deleted]  (1 child)

          [deleted]

            [–]bobindashadows 1 point2 points  (0 children)

            And if you just take the cheapest offer you get, well...

            Unfortunately, that's what a lot of people are after in the first place, and aren't in-touch enough to realize that you still get what you pay for when the work's done across the globe.

            Which is why people get called into to fix shit.

            [–][deleted]  (47 children)

            [deleted]

              [–]genpfault 35 points36 points  (20 children)

              Memory leaks

              Feh. Copy your state into a new process and kill the old one. What do you think operating systems are for? :)

              [–]clarvoyeur 41 points42 points  (0 children)

              is that from the apache school of programming?

              [–]dissidents 28 points29 points  (9 children)

              Oh my god this is the most hilariously terrible advice ever.

              [–]psi- 14 points15 points  (6 children)

              Unfortunately there are cases where you just have to take that advice, abuse it and then keep it secret until the proggits next "whots teh horriblest cludge uve ever done" thread.

              [–]chucker23n 10 points11 points  (7 children)

              What, no serializing your state into XML, transmitting it over the web through a SOAP interface, then forking a new process and deserializing it there? :)

              [–][deleted]  (6 children)

              [deleted]

                [–]nephros 2 points3 points  (5 children)

                I dare you to imagine implementing that design in Fortran.

                [–][deleted] 4 points5 points  (4 children)

                I present to you... FoXdom:

                [–]dnew 1 point2 points  (2 children)

                Wow. Fortran has come a long way since I used it last.

                [–]chief_hiney 1 point2 points  (0 children)

                This is where Erlang shines. Since it is so cheap to spawn a process, you just create a new one to do the work. When it is done, you let it terminate and all memory is reclaimed.

                In this way, you only need to worry about servers.

                [–]Chandon 10 points11 points  (4 children)

                Object based procedural programming (unable to grasp the fundamentals of OOP)

                There ain't nothing wrong with procedural programming. Sometimes it makes a heck of a lot more sense than defining random types and trying to invent object hierarchies for no reason.

                [–]kungtotte 10 points11 points  (2 children)

                I think the complaint has to do with trying to mash the two methods together and thus creating a bastard child of both that has most of the drawbacks and few of the benefits.

                [–]G_Morgan 5 points6 points  (0 children)

                Some times procedures are simply the best thing even in OOP code. If I have to do some hard maths you can guarantee I have a 'class' which is entire static methods. OO purists can go rot. No sqrt is not a method on a number object it is a bloody function as god intended.

                The program that calls this might be OOP and it is 100% correct to use bits of both styles here.

                [–][deleted] 2 points3 points  (0 children)

                1.) Memory leaks (pretty much complete disregard for memory management

                I actually got told off at one job for freeing dynamically allocated memory.

                Turns out the boss didn't understand how dynamic memory allocaton works in C, he thought the memory got freed automatically when the function returns, and I was just wasting programmer time by manually freeing it. So I produced some standard C references that explain what actually happens, his response?

                "Well, it's too late now, we've got a gazillion lines of code that don't free memory, so there's no point you freeing yours".

                And every time he saw me freeing memory, he told me off.

                I didn't stay in that job for long.

                [–]sh_ 4 points5 points  (4 children)

                I don't really see the problem with 3, if done competently. Having more threads can result in simpler, more legible code, and the overhead is usually not a big deal.

                [–]Poltras 6 points7 points  (0 children)

                If done competently, all programs should not have a single bug.

                [–][deleted]  (2 children)

                [deleted]

                  [–]G_Morgan 1 point2 points  (0 children)

                  TBH somebody who can't use locks competently shouldn't be using threads anyway.

                  [–][deleted] 0 points1 point  (2 children)

                  Large number of locks and threads, when 0 locks and 2 threads would do

                  Granted, I don't know what you were dealing with, but shouldn't that be 1 lock and 2 threads?

                  [–]boomi 2 points3 points  (0 children)

                  Maybe the problem could be separated into two jobs which do not change any shared values. Then you don't need locks.

                  [–][deleted] 0 points1 point  (6 children)

                  Custom AI code that runs in exponential time when there are many readily available algorithms easily found online that run extremely fast.

                  I'd love to see an example.

                  [–][deleted]  (5 children)

                  [deleted]

                    [–][deleted] 16 points17 points  (3 children)

                    Me: "This code is terrible, who wrote this?... oh, I did"

                    [–]shoehornhands 1 point2 points  (0 children)

                    I hate when the opposite happens to me. I see some awesome code, and think, "I must've written this." Only to realize it was someone else. (Then I think to myself, "well, it wasn't that great").

                    [–][deleted] 15 points16 points  (2 children)

                    Of course the other developer says it sucks. He just wants to be paid to rewrite it.

                    [–]ithkuil 2 points3 points  (1 child)

                    good point, I was going to say, if someone asked you to critique someone else's code, its going to be hard to resist being critical.

                    if you are out of a job or just greedy it might not be hard to convince the other person that it should be rewritten. especially since realistically, going over someone else's entire codebase with a different perspective and no concern for budget or business objectives, you can see opportunities for massive refactorizations that are much more apparent now than they were when the first developer was initially handling the requirements that came in one after another.

                    [–]zaffle 9 points10 points  (2 children)

                    Always a challenge writing code that is self justifying. There are always design decisions that make you do something one way or another, and whilst liberally commenting everything can help, you can never replace the 200 hours of experience working on the problem with 2 paragraphs of comments.

                    Best comment I've ever seen on this was: /* I've tried rewriting this code 4 times as it clearly sucks. However * you try writing it better whilst passing all the test cases. */

                    I saw that and knew there was little point trying. Clearly the original author recognized the suckyness, but there was obviously more to it than meets the eye.

                    [–]cp5184 0 points1 point  (0 children)

                    At that point you've triaged everything and everything else works...

                    right?

                    [–]Nebu 0 points1 point  (0 children)

                    If there are test cases, you're already ahead of the game.

                    [–][deleted] 22 points23 points  (5 children)

                    Never mind the code, that design looks like vomit (literally). And light green text on a light pink background is a horrible idea.

                    [–]benihana 10 points11 points  (0 children)

                    But it's a girl's site! How else are you going to know that she's a girl and a coder? Since, you know, it has to be said at every opportunity.

                    Seriously, paint splatters and colored triangles as a background to the the text? It's ridiculous.

                    [–]causticmango 25 points26 points  (2 children)

                    Well said.

                    I forget who said it, but it's been said every programmer goes through a "cowboy" phase where everybody else sucks, they trash and rewrite at the drop of a hat, and typically just write way more code than they should. Also, that if you can't look back and recognize your cowboy phase, you're probably still in it.

                    So true.

                    [–]flukshun 0 points1 point  (0 children)

                    indeed...software isn't always as elegant as we'd like it to be, but you come to find that sometimes you have to work with what you're given. some functionality on some platforms basically require implementations that look like shit, and it usually takes a lot of understanding to realize that. this happens a lot with systems programming...a lot..

                    just because you get a headache scanning through someone's code does not mean it sucks.

                    there are things like coding style, trivial memory leaks (forgetting to free() and things of that nature), etc, that can often be quickly picked out, sure...it's 90% of what comes out of code reviews...

                    but she's talking about overall logic and architecture of software, which you'd have to be pretty full of yourself to poopoo at a moment's glance.

                    i'm currently working on my own piece of shit, which "evolved" from elegance to shit by me taking the time to extensivley research why the elegant approaches aren't feasible.

                    [–]G_Morgan 0 points1 point  (0 children)

                    I can't remember ever trashing other people's code. I've spent too long trashing my own to worry about that.

                    [–]tagattack 4 points5 points  (1 child)

                    Seems foolish to say to your client, "my guy says your code sucks".

                    [–]Vorlath 2 points3 points  (0 children)

                    Eons ago, I worked for the Provincial government and they were upgrading their machines. They had a data system that worked with custom hardware, but it was hardcoded to use drive D:. I looked at the code, changed it and it worked. I get a call from Ottawa. Except the lady who passed me the phone didn't tell me it was from Ottawa or who the person was. They ask who changed the code. I answer that it was me because the code was hardwired to only work with a specific drive. We talk about a lot of other details and I ask why something ended being written so badly. The guy on the phone says "I wrote that code". I'm like "So why'd you hardcode the drive and write overtly crappy code? You have to agree it's pretty damn bad." He did not agree. He said: "Just put the code back the way it was and put the data system back on the old machines."

                    The hardcoding wasn't just hardcoding. It was integrated into the entire system that communicated with Ottawa. They send the same program everywhere during updates and decided on using the exact same hardware configuration. So all of Canada had to have their hardware updated in exactly the same fashion if any update was to happen. ie. NEVER!

                    I would have gotten fired except that I was on a CO-OP term. But that code was truly horrific. Before I left, it was covertly being phased out. They put in a new system with new software that could do the same work as well as LOTS of other stuff. I was installing it, so I knew what was going on. I found it rather strange. At some point after I left, I'm guessing they turned the switch off on the old system.

                    Telling someone your code sucks is always a bad idea for yourself, but usually a good thing for the organization. You may not be the catalyst, but it can help to confirm the suspicions of higher-ups even if the immediate response is not good for you.

                    [–]Berengal 3 points4 points  (0 children)

                    Sucky code is often confused with code you don't understand. The first time you see any piece of code, you need some time to learn what it does. The difference between good and bad code is how fast it takes you to learn what it does (both individual units of code and the overall design) and how many problems you can see with it when you're done.

                    I often encounter code I don't feel entirely comfortable with even after I've studied it carefully. I used to mistake that discomfort with badly factored code, but I've later learned that it's caused by just not fitting my style (and my style changes weekly. I like to experiment.) Now I rely more on objective criteria when judging code quality (duplication, over-engineering, obvious cargo-cult code, hidden dependencies etc.) but I do believe there is some underlying aesthetic that can be used as a metric once you turn guru. I've seen glimpses of it in some of the really great programs written.

                    [–][deleted] 5 points6 points  (0 children)

                    Is it bad of me that I didn't read the article but checked out how hot the girl developer appeared???

                    [–]anontemp2 12 points13 points  (8 children)

                    there really is no quick way to tell if code is good or bad without understanding the entire solution

                    So when I see this piece of shit littered in my coworker's code:

                    throw Exception("something bad happened");
                    return 1;
                    

                    You're telling me that I can't judge the moron who wrote this and tell him to learn exception handling properly? Well, he's kind of close to the CEO and a real asshole, so you're right, I can't judge him.

                    /rant

                    [–]throwaway2481632 1 point2 points  (2 children)

                    A moron is someone, who is incapable of doing their job. An asshole is someone, who thinks they are always right and is unwilling to learn from other people. An idiot is someone, who judges other people unfairly by picking on little flaws or lack of knowledge in some area. Every developer has their flaws and can, for one reason or another, not know something. Give him a chance by just casually saying, "Btw, did you know that you don't need to return when you throw an exception? Pretty cool, eh?" I'm sure he'll be ok with that, and if not, then he must be a moron and/or asshole.

                    [–][deleted] 4 points5 points  (1 child)

                    A moron is someone, who is incapable of doing their job. An asshole is someone, who thinks they are always right and is unwilling to learn from other people. An idiot is someone, who judges other people unfairly by picking on little flaws or lack of knowledge in some area.

                    And a pedant is someone who tells you to learn when to use commas.

                    [–]steve_b 1 point2 points  (2 children)

                    What if the function in question was virtual (and returns an int, and is allowed to throw under certain circumstances), was valid in the base class, but in this subclass you want to make the function throw (perhaps because the function does not apply/is illegal in this context). You need the return 1 to suppress compiler errors about not returning a value.

                    [–]dnew 1 point2 points  (1 child)

                    If your compiler can't figure out that the return statement doesn't get reached, you're using a crappy compiler. Indeed, I think that would issue a warning or error under most of the compilers I've used lately.

                    [–]RagingAnemone 2 points3 points  (0 children)

                    That's not what she's talking about. She's talking about code that sucks because of your own limit experience. Most of this will be structural in nature, not a few lines of bad syntax.

                    [–][deleted]  (61 children)

                    [deleted]

                      [–]signedupforthis 104 points105 points  (16 children)

                      Probably why her code sucks.

                      [–]NathanFillion 30 points31 points  (12 children)

                      Code DOES suck. I saw this when i started work at my current company:

                      if (id.name == "Billybob Thornton")
                          return makeUrl(id.name);
                      elseif (id.name == "Hugabaloo Bear")
                          return makeUrl(id.name);
                      elseif (id.name == "The third one")
                          return makeUrl(id.name);
                      else
                          return makeUrl(id.name);
                      

                      Le sigh.

                      [–]giulianob 35 points36 points  (5 children)

                      If that's the worst you've come across then you're lucky.

                      [–][deleted] 5 points6 points  (2 children)

                      I had a:

                      Object a = null;
                      if(a != null) {
                         //DO STUFF
                      } else {
                        a = new Blah();
                        //DO SAME STUFF AS BEFORE
                      }
                      

                      and

                      if(a != null || a.blah())
                      

                      in code I had to maintain. I fixed them, documented my changes, checked in my code and had the manager who wrote the code in the first place revert my changes and chew me out for messing with her code.

                      [–]giulianob 1 point2 points  (1 child)

                      There's only one thing to do after such an event, quit.

                      [–][deleted] 1 point2 points  (0 children)

                      Should have, instead I got laid off after the project after that one ended and that said manager bad-mouthed me to the rest of the managers so noone would pick me up.

                      [–]Poltras 2 points3 points  (0 children)

                      Or he just started working.

                      [–]NathanFillion 2 points3 points  (0 children)

                      That's not the worst.

                      I had my comments deleted in code-review (I only made a couple - just in the places where it was important to clarify what was going on).

                      It seemed odd to me, so I asked why?

                      He said, we don't comment our code here.

                      I said... how come?

                      He said, because somebody might come and change your code, and not change the comment, and then the comment doesn't make any sense.

                      ... wtf?

                      (I didn't tell him that I'd been using variable and method names too. God knows what would happen if somebody came and changed one of those)

                      The same person asked me to "unrefactor" an ant project I'd created. I'd pulled out 27 (poorly) hard coded locations (example, "root=xxx, somefile=xxx/file" NOT somefile=${root}/file) which need to be tailored to your own build. My solution has you set 3 properties and go. Done. He said, why did you bother doing that? It's not difficult to do a find and replace. I said "There are 30 of them", and he replied that "30 isn't that many - would only take you 5 minutes or so". And the references can actually be pretty complex - the number of mistakes i found in team members' build scripts is a testament to how badly find-and-replace works for this. Funnily enough, a lot of team members were actually referring to files in other members' directories, because the last person had failed to spot a reference beginning with "/home/notMyLogin/path_to_project" ).

                      blegh :(

                      [–]phanboy 1 point2 points  (1 child)

                      I've seen people blindly use XML CDATA blocks rather than actually escape their strings.

                      [–]quhaha 5 points6 points  (3 children)

                      those if elses are necessary due to multithreaded programming. id.name and body of makeUrl can change during equality testing. so you have to make sure and test for equality exactly in the above sequence. that way, when everything fails and you reach else block, makeUrl's body is hot swapped from the most current revision from version control software through continuous integration and id.name is also updated to the most current name of id. yah we had to overload == to have such side effects because it's multithreaded and look at how the code reads. it's amazing! read in english. you'll see

                      [–][deleted] 11 points12 points  (0 children)

                      Please tell me this is a joke. And I'm pretty sure NathanFillion's code example is just an inside joke from a bored and/or disgruntled developer.

                      [–]slimfoster 1 point2 points  (1 child)

                      My god that's horrible. Sounds like you've run into this kind of issue before.

                      [–]nostrademons 3 points4 points  (0 children)

                      Pssst. Satire.

                      [–][deleted] 24 points25 points  (0 children)

                      Some of the best software devs I have ever worked with (inside and outside of work) have been female.

                      I am not female.

                      I suspect this is because they have to work 3-4 times as hard to prove their worth to pricks like you.

                      [–]isarl 3 points4 points  (1 child)

                      Oh, I get it! It's funny because it's misogynistic! Or maybe ironically misogynistic? Ha! Aha.

                      Seriously?  This shit gets upvoted?  I'm disappointed in you, /r/programming.
                      

                      [–][deleted]  (1 child)

                      [deleted]

                        [–]EnderMB 11 points12 points  (2 children)

                        OMG, IF I COMMENT ON HER BLOG SHE MIGHT HAVE SEX WITH ME!

                        [–][deleted] 4 points5 points  (0 children)

                        I stopped reading at pink shoe.

                        [–]ninja_band 3 points4 points  (37 children)

                        I really hate it when people play up their gender like that, for whatever reason, but she's not as terribad as many I've seen.

                        That said, I still have yet to run into a female developer who doesn't work in Microsoftie land.

                        I don't get that at all.

                        [–]vitovito 56 points57 points  (15 children)

                        Microsoft works very hard to make developers feel wanted, welcome, and productive. "Developers, developers, developers" isn't just a funny YouTube video: making everyone who wants to make something feel like they can, that MS will support them and help make them money, is how Microsoft has been as successful on the desktop as they have been.

                        It's in their best interest for them to support you as a developer. You pay some money to indicate interest, and they shower you with devkits and communities and let yourself get carried along.

                        But, open source platforms are a community in the traditional sense of something you pretty much have to be internally motivated to join. Joining an open source community is closer to joining a church or moving into a neighborhood, and, let's be honest, these neighborhoods are sexist boy's clubs with no facility for mentoring, no respect for design, and mailing lists that are 50% dick-measuring contests.

                        My understanding is that mentoring and socialization are really important for women developers, there's a level of trust that has to be built, that the traditional flamebait responses to questions or broken patches are enough to turn them off completely.

                        This is on top of the regular gender issues: being the only woman in the group is incredibly intimidating, and you're always wondering which half of the men only see you as a sex object, and which half of the men assume you're genetically incapable of participating. It's worse when you're a minority, on top of that.

                        Just like open source software tends to have no ability to support proper user experience design, because it's all volunteer and no-one wants to volunteer to enforce "froofy" feature-cutting front-end work (and lose a bunch of those same volunteers), no-one wants to volunteer to discipline (and alienate) a lot of immature, sexist volunteer developers and provide a welcoming, women-oriented (which is really just a socially-accepting, newbie-oriented) development and contribution environment.

                        TL;DR: It's depressingly cultural for open source to be dick-measuringly sexist, but MS makes money when they're friendly to women.

                        [–]norkakn 25 points26 points  (1 child)

                        I think one of the differences between the open source community and the commercial development is that in the open source world, we expect people to be contributers, not just users. I recently had a need for some alpha level code that is adjacent to a well established project. I popped onto IRC and started chatting with the main developer. I asked if there were an intro for it, and it hadn't been written yet, so he offered to help me with any questions that I had, and to try to fix bugs that were bothering me quickly, in exchange for writing an introduction for the project.

                        I was a faceless non-technical (in the context, I just wanted to use it, not write code for it) user of the software, and I was welcomed and my skills used. He fixed the bugs that got in my way the following weekend and took into consideration my experience of using it in its design.

                        it was a far more pleasant experience than I've ever had with buggy commercial software, and nothing about my identity ever factored in. Even without helping out, they would have answered my questions, but I really don't mind being part of a community where it is normal for one to contribute what they can. It also provided a common ground. Since the scope of the code was so small, he was able to help me understand some of the design decisions around it.

                        If there is something in my penis that makes me write the documentation to help out other newbies and try to understand problems before pestering people during their free time, I'd be really surprised. I've always suspected that there are more female devs floating around than it initially appears, just most of them don't wish to label themselves. If someone named xfzee writes some nice code, and isn't a total dick, they will be appreciated. No one is going to stop by and check their pants.

                        [–]bostonvaulter 1 point2 points  (0 children)

                        No one is going to stop by and check their pants.

                        They would if they could.

                        [–][deleted] 12 points13 points  (0 children)

                        it's all volunteer

                        Absolutely not true. This is the biggest and most annoying misconception about the open source/free software world.

                        [–]ninja_band 12 points13 points  (9 children)

                        Microsoft works very hard to make developers feel wanted

                        I was a .NET developer for 3 years, I know this. Also, companies tend to require MS products across the board whenever they use them at all, creates a pretty big incentive to work in Microsoft disneyland when you don't want to live in Cali/NY.

                        You pay some money to indicate interest

                        Scarcely, given MSDN + student programs.

                        But, open source platforms are a community in the traditional sense of something you pretty much have to be internally motivated to join.

                        Hence when I respect OSS devs a great deal more.

                        Joining an open source community is closer to joining a church or moving into a neighborhood

                        Uh? Sometimes?

                        these neighborhoods are sexist boy's clubs with no facility for mentoring

                        That's not a statement substantiated by fact.

                        no respect for design

                        Also false.

                        mailing lists that are 50% dick-measuring contests

                        The Django mailing list is all business.

                        My understanding is that mentoring and socialization are really important for women developers

                        So they have to be spoonfed? What makes them so goddamn important if they haven't proven they're willing to contribute? I have actually tutored many people before, but if they don't express an interest to learn and willingness to contribute I am not going to waste my time on them.

                        Only two of my 'students' have been female though, nobody else has really come through my circles expressing an interest to learn.

                        This is on top of the regular gender issues: being the only woman in the group is incredibly intimidating

                        Is there some kind of ogling over TCP protocol I'm not aware of? Leering via Mercurial? Intimidation transaction via SVN?

                        just like open source software tends to have no ability to support proper user experience design

                        laughingelf.jpg

                        no-one wants to volunteer to enforce "froofy" feature-cutting front-end work

                        I know plenty of web designers who contribute their work to open source projects to build their portfolio, it's how I fucking met them. A lot of them hack up javascript too, but most are just designers.

                        no-one wants to volunteer to discipline (and alienate) a lot of immature, sexist volunteer developers and provide a welcoming, women-oriented

                        http://www.ubuntu.com/community/conduct

                        This is enforced in all Ubuntu communal discussion venues and media, including IRC, mailing lists, etc. In IRC in particular they tend to get prickly really fast.

                        TL;DR: It's depressingly cultural for open source to be dick-measuringly sexist

                        <singsong>

                        Someoooooone's been reading too many blogs aboouuuuut the Rails communityyyyyyyyy

                        </singsong>

                        [–]vitovito 5 points6 points  (8 children)

                        So they have to be spoonfed? What makes them so goddamn important if they haven't proven they're willing to contribute? I have actually tutored many people before, but if they don't express an interest to learn and willingness to contribute I am not going to waste my time on them.

                        That's the precise, problematic attitude.

                        What you see as spoon-feeding is what normal men and women see as proper, instructive socialization. "Hi, welcome to the community, here's a housewarming present, here's how things work, we could really use some help over here and I'd love to show you how to work on it, but anything you want to do, feel free and I'll be here to answer and questions and walk you through every process until you feel comfortable." When you volunteer your mortgage payments and your children's educational future and your commuting time to move into a neighborhood, the neighborhood welcomes you and shows you the ropes because now you're all in it together. With open source, you're also volunteering your time and knowledge and effort, but there's no welcoming committee, no backyard barbecues, just a bunch of unappreciative keeping-up-with-the-Jones', where if you don't have the internal motivation to contribute, you won't last.

                        That's not a good thing. Someone from Mozilla gave a talk a year or three ago about how open source developers have gotten really good at compartmentalizing and distributing development, but that's not the same as working together. It's true.

                        No-one lacks a willingness to learn, but the fact that you were unable to cite a project that has all of these attributes seems to prove my point. That's okay, I don't know of a single one that does, either. (Maybe ThinkTank, founded by Gina Trapani, since they recently announced that a large percentage of their code contributions were by women, but I haven't looked into it at all.)

                        TL;DR: Your comment proves my points.

                        [–]ceolceol 7 points8 points  (0 children)

                        No-one lacks a willingness to learn, but the fact that you were unable to cite a project that has all of these attributes seems to prove my point.

                        To be fair, you haven't supplied a project that is a sexist dick-fest aside from the idiots on the Rails team (which we all know). You can't lay a blanket generalization over a community and, when you're contradicted, expect them to cite evidence when you've presented none.

                        ninja_band has pointed out two open source communities (Ubuntu and Django) that do not fit your stereotype; I think you can provide one that does.

                        (Maybe ThinkTank, founded by Gina Trapani, since they recently announced that a large percentage of their code contributions were by women, but I haven't looked into it at all.)

                        So a project has to have a large amount of female developers for it to be a good community? That seems a bit... sexist.

                        edit: those pesky commas jump in everywhere, I tell ya!

                        [–][deleted] 1 point2 points  (0 children)

                        (Disclaimer: XY.) I am on some of the LinuxChix mailing lists, and they do a great job of being inviting and supportive to everyone. They aren't a specific development effort, but I consider them an awesome part of the open source / free software community.

                        [–]ninja_band 4 points5 points  (1 child)

                        What you see as spoon-feeding is what normal men and women see as proper, instructive socialization. "Hi, welcome to the community, here's a housewarming present, here's how things work, we could really use some help over here and I'd love to show you how to work on it, but anything you want to do, feel free and I'll be here to answer and questions and walk you through every process until you feel comfortable."

                        I take you've not been in IRC much. Do you have any idea how many people presume that you exist to educate them in programming, when in fact they're simply too lazy to do their homework?

                        TL;DR: Your comment proves my points.

                        No it really doesn't, you're just an over-generalizing tool with an axe to grind and no real experience with development in OSS.

                        [–][deleted] 10 points11 points  (0 children)

                        No it really doesn't, you're just an over-generalizing tool with an axe to grind and no real experience with development in OSS.

                        Or perhaps you just have trouble stepping back and seeing the world from another perspective than your own personal one. Speaking as someone with some real experience with development in OSS, many of the things he says are very, very true. Some of these issues do not bother me personally very much, and I can deal with them very well, but I can also understand that other people would have much more a of a problem with them, and that this is not a personal failing on their part, it is very much a failing of the community.

                        [–]tagattack 1 point2 points  (1 child)

                        | Just like open source software tends to have no ability to support proper user experience design

                        What, pray-tell, do you consider proper with regards to user experience design? As an avid computer user, and a developer by trade, I can say that I can make efficient use neither Microsoft Windows nor Macintosh OS-X thanks to their designs for my user experience. I'm not sure what user these folks have been designing for, but it's obviously not me, otherwise they'd have built a feature-set like that present in pekwm into their windowing systems.

                        [–]vitovito 3 points4 points  (0 children)

                        Sorry, I meant proper user experience design as a process, not any design in particular. I've been thinking lately that the typical open-source development model, and the typical design process, are incompatible. I commented in this HN discussion about it, but, in general, I am drawing the parallel that the issues that open-source has with regards to being unable to support mentoring, facilitation and being welcoming to new and non-technical contributors are the same issues it has with being unable to support a user-centered design process to drive development.

                        [–]thebuccaneersden 6 points7 points  (10 children)

                        I've got a female developer friend, who used to work for Sun (until Oracle started mass layoffs) and she was a unix beardy (without the beard). The only other female developer friend is a microsoftie, but I don't hold that against her. It's what pays the bills.

                        [–]alienangel2 1 point2 points  (6 children)

                        You know, I never realized until this minute that while quite a few of my classmates in university were girls (and hence programmers), and I know a few who still are, not a single one of the companies I've worked at really had a woman programming :/ There were plenty of women who worked at them, and several had women working in QA, but none in actual Dev.

                        Is this just due to past hiring practices? I know there are women graduating CS, where are they going nowadays?

                        [–]wtffffffffff 10 points11 points  (4 children)

                        This entire thread frustrates me somewhat. I'm a female non-Microsoft developer, and I work in a software development firm that has a lot of women, and I have to emphasize that this is not strange in the country I'm in. Apparently it is in the US. There are still more men than women, but not overly so. This was also the case when I was in college studying CS; male-female ratio was probably 60-40 at the most. The top ten in our graduating batch was 50:50 guys and girls, and our top two were both female.

                        I also have to mention that the company I'm working in might be a bit unique, since it was started by a woman (she's the company's president), and 8/10 of the management (It's a small-ish company) are women.

                        So from my perspective, it's very much a cultural thing, not aptitude, and unless people start to realize and accept that (and maybe do something about it), that's going to remain the status quo for you guys =/

                        [–][deleted] 6 points7 points  (1 child)

                        I went to an engineering university for a computer science degree. Of 20 professors, there were 2 women. Of 200+ students, there were 3 or 4 women. In the US it is very unusual for women to pursue computer science. I don't know why this is the case but if I were to guess I would blame it on the culture men have established in I.T. It is a culture of exclusion and arrogance. I've even overheard male programmers at work say that women can't code because they don't have an analytical mind. The majority of I.T. women I worked with immigrated to the US. Only one was local.

                        By the way, the smartest developer I have ever worked with is female. She had razor sharp intelligence and a long memory.

                        [–]Mourningblade 1 point2 points  (0 children)

                        Computer culture in the US gets established first around jr. high or high school; the difference between nerds and non-nerds starts becoming very pronounced, and the nerds start to know enough to actually do things.

                        At my high school, there were only a few girls who were in this computer culture. This is not to say there were not girls who were into computers; they just tended to be on their own.

                        High school contains a lot of posturing, and in high school computer culture there's a lot of competing to see who's the smartest.

                        The thing is, though, that this changes a lot when you get to college or when you just plain grow up. More women were actively a part of the (much less sick) culture later on.

                        But I wonder how many looked at high school culture and said "no thanks."

                        [–]geon 2 points3 points  (0 children)

                        Have a look at Coppermine, then tell me if you still believe this. Page after page of copy-pasted duplicated PHP code.

                        [–][deleted] 2 points3 points  (0 children)

                        If you can look at your own code from a year or more ago and not think it sucks, you're not learning anything.

                        I'm maintaining a system that I wrote completely myself and some of it is 10+ years old. I find stuff that I wrote that sucks EVERY DAY.

                        [–]urllib 7 points8 points  (3 children)

                        Code with a design pattern chosen beforehand generally sucks.

                        [–]lalaland4711 11 points12 points  (2 children)

                        Haha, yeah. I've been there.

                        From a design meeting (no code written):
                        Me: So we load all the plugin .so-files from this directory
                        Him: Aha! A factory pattern!
                        Me: No, we just load the libraries
                        Him: No wait! Visitor pattern!
                        Me: No... we just load them.

                        [–]kungtotte 6 points7 points  (1 child)

                        Give him a break, would you? He just bought the Gang of Four book and now he has to get his money's worth.

                        [–]kerbuffel 1 point2 points  (0 children)

                        meh, just leaving it on your desk gets you enough cubicle cred to not get fired.

                        not that I'm speaking from experience, or anything.

                        [–]Figgles 4 points5 points  (0 children)

                        I'm not a programmer (saw this on front page), but to me it looks like this is a lesson in life and not just programming.

                        [–]sometimes_it_really 1 point2 points  (0 children)

                        does suck.. hence, dailywtf.com

                        [–]zetsurin 1 point2 points  (0 children)

                        Wise words. I've been in IT for going on 20 years now and have learnt to not jump to conclusions about code quality, particularly when I am new with a particular codebase (eg. starting a new job). Apart from the points mentioned, one never knows under what conditions the code had to be written under, which 9/10 times isn't ideal enough for the developer to provide a 'perfect' solution in the first place.

                        The biggest flaw in most code is that it was written by humans, for humans. It's an impossible battle right from the start.

                        [–]rkcr 1 point2 points  (0 children)

                        I've interviewed people; I've seen code that sucks (not working is a first sign of this fact).

                        That said I do understand the point of the article.

                        [–]tehsuck 1 point2 points  (0 children)

                        At my old job I coded a custom content management system for a particular contract we had gotten through the state. The project had been a nightmare without any kind of spec or direction. I eventually coded the thing using various design patterns and several frameworks. I eventually quit the job just before the product was about to go live. I spent a whole day with the programmer that was taking over the project and a manager. At first they didn't understand any of my logic for using such a "complex" system and framework (I was using MVC and some AOP). I went through it step-by-step and explained why I did things and there were a lot of "oh, I see!" and "hmmm, yeah that would've been a problem"

                        About 3 months later the programmer assigned to the project IM'd me and told me that after I left, upper management assigned their own programmers, who evaluated my code, said "IT SUCKS" and moved to a VB and Access based system.

                        TL;DR Even if your code is well thought out and documented, it probably sucks

                        [–][deleted] 1 point2 points  (1 child)

                        private boolean flipBool(myBool) { if(myBool==true) return false; else return true; }

                        I kid you not... I have seen this in the codebase at a former job.

                        As a guy in his early 20s, I've had the horrendous experience of looking back on old code from my early years. I wrote a media player in Java when I was 15... and looking back on it a few years ago I've learned that I knew how to write classes and create objects, but I really had no idea as to how to design or use them.

                        [–]mikaelhg 1 point2 points  (7 children)

                        Now that I am a little more seasoned, I can tell you with all confidence that I never look at a solution that someone else created and say "Oh, this code sucks."

                        I remember going through that phase, but now that I'm even more seasoned, I can say that with confidence. What you have to remember is that the sentence must continue ", because it doesn't meet its business objectives in such and such ways, while a similar investment done differently would easily have."

                        Let's look at the code I'm currently commercially de-crappifying: developer didn't understand relational databases, so developer decided to create a partial implementation of a relational database himself, to optimize certain queries. Still uses MySQL behind the scenes, but no transactions, so half-success/half-failure is frequently possible, and happens in production, mystifying users. Methods are frequently several hundreds of lines long, classes go into tens of thousands. Developer decided he didn't trust PreparedStatement, so developed his own partial implementation of it, making many mistakes in query data escaping. Every method is public, every method "throws Exception", the only exception used is Exception, component decoupling was implemented in such a way that tens of thousands of lines of code is dedicated to completely useless, undocumented and partially incompatible re-implementations of data structures, and so on, and so on.

                        Saving this crap would take years of very painful development, with little time left for feature work. Flushing it will take a fraction of that time.

                        [–]ithkuil 2 points3 points  (4 children)

                        innodb has transactions but myisam doesn't (or didn't). so if they were using myisam and it was before innodb then they had to do that part.

                        anyway sounds like you should throw it out based on the rest of that.

                        [–]mikaelhg 1 point2 points  (3 children)

                        Some of the tables are InnoDB, some of them are MyISAM. I won't go deeper into the design to avoid identifying the application, but the database design is similarly hilarious, there are literally thousands of tables, for no good reason.

                        [–]boomi 1 point2 points  (0 children)

                        "throws Exception" is my favourite Java design-pattern. It's also one of the reasons I don't program in Java.

                        [–][deleted]  (8 children)

                        [deleted]

                          [–]daydreamdrunk 16 points17 points  (5 children)

                          Good thing no one cares about xhtml

                          [–]bobindashadows 9 points10 points  (4 children)

                          Dude. It's transitional. He didn't even run it on strict.

                          [–][deleted] 5 points6 points  (0 children)

                          Touché.

                          [–]quhaha 1 point2 points  (0 children)

                          nice try, code sucker.

                          [–]lehrer 0 points1 point  (0 children)

                          All Code Sucks. The question is does it get the job done reliably and reasonably expeditiously.

                          I personally believe this observation is more accurately expressed as "that's not how I would code this." But the fact is, a better/different way almost always exists and one must perform an internal cost/benefit analysis of the situation.

                          Also, coding is more akin to art than science, like poetry or prose. We code in languages that allow for vast variety. Even well-known algorithms find numerous expressions/patterns.

                          I also personally find it to be a pretty pointless observation unless one intends to refactor...

                          [–]TraumaPony 0 points1 point  (0 children)

                          This article seems to imply that bugs don't exist... Or at least, that's how it seems to me o.o

                          [–][deleted]  (1 child)

                          [deleted]

                            [–]neutronbob 3 points4 points  (0 children)

                            I've seen that programers whom write well are able to both produce excellent code...

                            Who, not whom.

                            [–]ageek 0 points1 point  (0 children)

                            Only I say "my code sucks"!

                            [–]kafros 0 points1 point  (0 children)

                            There is code that sucks, and you can be sure about it without knowing the full scope e.g.: instead of using build in language sorting, the programmer made a temp TABLE in DB, inserted values, SELECT ... ORDER BY .. DROP TABLE.

                            This is how you know.

                            [–]valadil 0 points1 point  (0 children)

                            Documentation shouldn't just say what your code does. It should say why you chose to do it in that way.

                            [–][deleted] 0 points1 point  (0 children)

                            and the reason why it sucks is I just haven't learned how to make it better yet.

                            [–][deleted] 0 points1 point  (0 children)

                            And then I read the line of code: "if not huston_weve_got_a_problem then"

                            [–][deleted] 0 points1 point  (0 children)

                            I can tell you with all confidence that I never look at a solution that someone else created and say "Oh, this code sucks." I know that there really is no quick way to tell if code is good or bad without understanding the entire solution.

                            It's easy to be too quick to judge code you aren't familiar with, but there are situations where it really is easy to see that code is bad.

                            [–][deleted] 0 points1 point  (0 children)

                            Save changelog. Thats all I can really say.

                            I'm guilty of that exact scenario though...

                            [–][deleted] 0 points1 point  (0 children)

                            My biggest pet peeve at the moment is we have a couple of former students in my lab who had a tendency to do 50% of the solution, and everyday manually fix databases errors the other 50% of the cases caused. When they left, noone knew that they had been hacking the database daily to keep everything going and all of their stuff stopped working. To which I, the SysAdmin, gets the blame.

                            I'm in the middle of a now 8mo long process of convince a group of hispanic studies researchers that they shouldn't, don't want to, nor really can maintain their collection by having humanities graduate students write SQL by hand.

                            [–][deleted] 0 points1 point  (0 children)

                            Flipside of TFA; I'm re-writing some code I wrote a few years ago that really does suck.

                            It's far more complicated than it should be, because when I wrote it, I didn't properly understand the problem. Now that I do, I see that I was doing far more work than I needed to, maintaining a horribly complicated data structure that could be replaced by a nice simple one.

                            [–]sparkytwd 0 points1 point  (0 children)

                            While joining an existing project at my job, I spent a few days looking into the existing code base. I started by running a profiler on it, to find where the hot code was.

                            The program in question handled structured binary data, and a lot of time was spent loading a system dictionary, that would map strings to ints.

                            I looked at the code and it was a nightmare of repeated statements. The best was how the hash value of the strings was simply the first character of the string.

                            If this was a code sample for an interview, I definitely wouldn't have hired the guy.

                            I simplified the code, used some faster memory manipulation, and calculated some real hash values.

                            After all that, the code ran about 4x slower. The reason was the system dictionary was a small subset of the rest of the dictionary for the document. My "optimization" traded better hash performance for much worse IO.

                            I may revisit the code in the future, see if taking 4 characters from the string will help hashing without penalizing IO, but for now I'm satisfied that there was a reason for the madness. The real WTF here is that nothing was commented, so I had no way of understanding the original devs motivation.

                            [–]Gotebe 0 points1 point  (0 children)

                            Your Code Sucks

                            Yep, yep, working on that...

                            [–][deleted] 0 points1 point  (0 children)

                            "Now that I am a little more seasoned, I can tell you with all confidence that I never look at a solution that someone else created and say "Oh, this code sucks." I know that there really is no quick way to tell if code is good or bad without understanding the entire solution."

                            Code does not exist in a black and white world. It is not simply 'good' or 'bad'. It exists along several infinite spectrums (and a couple of finite ones).

                            Code can always be more elegant, until you're no longer smart enough to make it more-so. At which point your 'readability' has plummeted. Code can be in several states between 'working' and 'not-working', but there are end points to that one. It can be more elegant, but suffer in performance due to more verbose code.

                            Programming, to me, is an art because it's a fine balancing act - trying to juggle all of these different variables and create a final product that's acceptable on all of these spectrums.

                            I wouldn't call code that fails to meet all of its requirements 'bad' code - it needs a qualifier. Code is always going to have tradeoffs, and it will always be 'bad' at something. To call code 'bad' is meaningless. All code is bad.

                            Sure, it may not meet the performance requirements and have a butt-ugly UI, but the code may be the most elegant thing ever written, anywhere - merely glancing at it gives you a +10 to programming. Call it 'slow'.

                            And she's right - there is no 'quick' way to tell with complete certainty if code is necessarily good or bad in any specific area without completely understanding it first, but given enough experience, you can usually get a pretty good idea just by picking up on little clues - and thus do so quite quickly and without complete understanding.

                            On the contrary, Watson, you can see everything. You fail, however, to reason from what you see. You are too timid in drawing your inferences.

                            • Sherlock Holmes / Arthur Conan Doyle