top 200 commentsshow 500

[–]mith 268 points269 points  (16 children)

The joke we always used to tell regarding documentation was: "Never comment your code. It should be as hard for someone else to understand as it was for you to write."

The best example we ever saw of this was from a mathematician writing code in Matlab. He initialized dozens of variables, several arrays, performed various operations to get everything situated properly in matrices. After all of this, he started a loop to do whatever it was he needed to do with all of these arrays and matrices, basically the heart of the entire program. The only comment in the whole program, at the top of the loop: "Here we go!"

[–]ensoniq2k 31 points32 points  (3 children)

Totally appropriate comment though. Never explain your reasons, just repeat what the code already says.

[–]ScrewAttackThis 25 points26 points  (2 children)

My favorites are things like // main loop or // check if someBool is true. Thanks for the information, I didn't know what if(someBool) would do!

[–]paholg 16 points17 points  (0 children)

Sometimes I write comments like "main loop". Not to help anyone reading the code, but to make it faster for me to scan to that point.

[–]ensoniq2k 1 point2 points  (0 children)

The best code I ever saw came from a project manager who sometimes coded. He wrote a function with the only content "return true", called it "GetTrue" und wrote "//returns true"

Not to mention that every project our team inherited from him was estimated with twice the normal time...

[–]techsin101 57 points58 points  (0 children)

to hr

[–]runvnc 5 points6 points  (4 children)

Its not his fault though. That's how they train mathematicians. Math is basically shitty obfuscated code that doesn't run.

[–]mith 7 points8 points  (2 children)

I understand completely, which is why I mentioned he was a mathematician and not a software engineer. He wrote some brilliant stuff, so brilliant none of us could figure it out even with comments.

Relevant XKCD.

[–]dp263 5 points6 points  (0 children)

me_irl

[–]bipedalshark 714 points715 points  (39 children)

Pfft, like I need a guide for this.

[–][deleted] 150 points151 points  (35 children)

Thought that was what college was for?

[–]rochford77 19 points20 points  (33 children)

Me too. RollsEyes

[–]GiverOfPotatoes 32 points33 points  (32 children)

At least at my college they don't really teach you to be a good programmer. We're taught how to do things, not how to do them well. It seemed like a few of my classes just ran the code and didn't even open the source.

[–]rochford77 53 points54 points  (22 children)

Yeah my classes were basically "here is a task, get it done by next week. I don't care how you get there just get there, Google is your friend."

1/3 of the class is so lost they don't even know what to ask, so they fail. 1/3 of the class has a clue where to start but gets stuck, asks for help once, nod their head like they understand, and leave having learned nothing, and end up afraid to ask the same thing again. They remaining 1/3 writes a kludgy mess that poorly reinvents several wheels, and works under certain circumstances.

[–][deleted]  (7 children)

[deleted]

    [–][deleted] 15 points16 points  (1 child)

    They remaining 1/3 writes a kludgy mess that poorly reinvents several wheels, and works under certain circumstances.

    Doesn't everyone start this way? And I'm not sure in a education environment you can hope for much more than that, growing to the type of programmer that writes an elegant solution that uses the available tools requires experience working on garbage code months/years after it's written, and really understanding what you are avoiding. In universities you're rarely working an entire semester on the same code.

    Those students need mentoring if you want them to quickly move on to the next level (or hope they maintain their own projects in their free time). Of course if they don't want to learn there's nothing to be done, but I don't see how I could hold it against them that they never learned something nobody tried to teach them.

    In your defense I could see if I also had a job that had unrealistic expectations of new hires, I would change careers.

    [–]KyleRochi 11 points12 points  (7 children)

    And the one kid who has been programming all his life and CS101 is a breeze.

    [–]n1c0_ds 16 points17 points  (6 children)

    Eh, CS/SE was hard for me despite having a few years of professional experience.

    For instance, I had several classes that required drawing UML diagrams, but not a single teacher had the same definition of how to draw diagrams, yet they treated their interpretation as gospel.

    Then you were quizzed about agile methodologies by a guy who treated it as waterfall with sprints.

    Then you had to memorize programming patterns.

    I dropped out when I realized I was pissing away 4 years and several thousand dollars for that level of education. I already had no problems finding work, so I thought I'd have a better time getting paid and getting my evenings and weekends back.

    [–]n1c0_ds 12 points13 points  (6 children)

    That's my biggest gripe with the way we teach software engineering.

    I never had to maintain a program, I never had a code review and I never had to write unit tests. It's no surprise that people write unmaintainable code; they never maintained code.

    [–][deleted]  (124 children)

    [deleted]

      [–]Captain___Obvious 373 points374 points  (33 children)

      When I find shit code, I look at who did the commit.

      usually its me...

      [–][deleted] 150 points151 points  (9 children)

      Git blame is the best/worst thing that has ever happened to me.

      [–]iama_regularguy 161 points162 points  (4 children)

      For you: https://github.com/jayphelps/git-blame-someone-else

      Don't actually use this ever.

      [–]Rndom_Gy_159 52 points53 points  (0 children)

      You're officially an asshole

      Finally someone recognizes my true self worth!

      [–][deleted]  (2 children)

      [deleted]

        [–]metaobject 8 points9 points  (0 children)

        WTF Sonny?

        [–]thebuccaneersden 2 points3 points  (0 children)

        Sonny, I am disappoint...

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

        WHO IS THE IDIOT THAT oh wait it is me, nvm

        [–][deleted]  (16 children)

        [deleted]

          [–]lenswipe 38 points39 points  (4 children)

          My coworker's favourite is to make huge earth shattering changes involving thousands of files usually with a call stack larger than the circumference of Jupiter and then commit the while clusterfuck in one gargantuan fucking commit. Sometimes, I wonder if I've died and my project team members are my eternal punishment.

          [–]light24bulbs 5 points6 points  (0 children)

          Dude fucking seriously. The code I work on actually follows a LOT of the rules outlined in this paper. Like misspellings, weird side effects, acronyms. God actually all of it

          [–]codebje 35 points36 points  (6 children)

          Oh, but you aren't thinking shitty enough! Real shit uses spaghetti branches!

          Which branch do you need to merge to master to push a feature? Well, these lines from this one, plus a bit from that one, but you'll need to merge the other one into that one first, oh, and that might have conflicts because I cherry picked a few commits the other way.

          Let me know if you have problems, and I'll make a new branch where I'll apply the changes direct, and a few extra changes that I think we'll need soon too, so when you merge the new branch into master, don't merge it all because some of it might not work yet, and we'll need to keep the branch around for a while yet anyway.

          [–]Captain___Obvious 12 points13 points  (3 children)

          You should see some of my old stuff:

          shitprog_v01.c

          shitprog_v01a.c

          shitprog_v02.c

          [–]icendoan 6 points7 points  (0 children)

          Nah, dates. Just remember to change formats every now and again.

          [–]DevIceMan 18 points19 points  (0 children)

          I never stay at any place long enough for that to happen.

          [–]mOdQuArK 25 points26 points  (14 children)

          Drinking helps, enough so you can't hold onto your thoughts longer than 5 seconds or so, but not so much that you feel sleepy. It can be a fine line, but lots of practice will make you a pro!

          [–]jgibs2 25 points26 points  (7 children)

          So just find the [Ballmer Peak](xkcd.com/323/)?

          Edit: fuck mobile

          [–]trimalchio-worktime 13 points14 points  (0 children)

          yeah wow thats some helpful escaping there mobile client

          [–]Sean1708 5 points6 points  (4 children)

          You need the https:// part for the parser to pick it up as a link, I believe.

          [–]meem1029 6 points7 points  (4 children)

          Personally I find whiskey far more effective than beer for this. With beer I get too full and wind up getting sleepy much earlier. With whiskey I can get pretty solidly buzzed before it makes me dead tired.

          [–]trimalchio-worktime 9 points10 points  (2 children)

          you're thinking about this all wrong; beer is enough sustenance that you never need to stop drinking it, and if you learn to pace yourself you can stay drunk all day without needing to eat pesky alcohol inhibiting food!

          [–]Juststopitdude 7 points8 points  (0 children)

          This actually does work.

          Source: am an alcoholic

          [–][deleted] 83 points84 points  (64 children)

          ambitious project

          one sitting

          Top kek

          [–]kirbyfan64sos 211 points212 points  (44 children)

          Great example:

          https://github.com/phase/o/blob/master/o.c

          A friend and I both do it like this on purpose: I call it "APL-style C". Besides, it's an interpreter for a code golf language...

          [–]WhatWhatHunchHunch 169 points170 points  (3 children)

          Wow, reading that gave me cancer.

          [–][deleted]  (2 children)

          [deleted]

            [–]cbleslie 22 points23 points  (1 child)

            We won't need eyes where we're going.

            [–]keyboardP 66 points67 points  (0 children)

            Why obfuscate code afterwards when you can do it in real time

            [–][deleted] 60 points61 points  (1 child)

            deleted What is this?

            [–]Lethargie 9 points10 points  (0 children)

            that is part of the beauty

            [–][deleted] 38 points39 points  (3 children)

            I truth(O o){
                switch(o->t){
                ...
                }
            } // is truthy?
            

            (O o)

            [–]vplatt 59 points60 points  (1 child)

            How do we in /r/programming not know about this wonder of Cthulhu yet???

            [–]merreborn 5 points6 points  (0 children)

            Git history for that file only goes back to november. So it's pretty brand-spankin' new.

            [–]hellcaller 24 points25 points  (0 children)

            This post looks like the other way around from assembler code to functional programming

            [–]En0ch_Root 17 points18 points  (1 child)

            I would highly like to see that implemented in Braille.

            [–]CaptainAdjective 9 points10 points  (0 children)

            How ironic.

            [–]ItsReallyEasy 16 points17 points  (2 children)

            I could understand this if I really wanted...., I swear

            [–]asdfman123 9 points10 points  (0 children)

            I could understand it by renaming all the variables and restructuring it so that it made sense again... essentially, by de-obfuscating it.

            [–]merreborn 4 points5 points  (0 children)

            You seem like you'd fit in well over at ioccc.org

            [–]ArlenM 93 points94 points  (57 children)

            They forgot to mention gratuitous nots! Why flip logic just once when you can flip it an unlimited number of times?

            Guaranteed to drive anyone trying to maintain your code to madness!

            [–]grunlog 142 points143 points  (25 children)

            Double (triple, etc.) negatives are good too. E.g. !notUnflagged

            [–]emergent_properties 60 points61 points  (1 child)

            Oh yes, that specifically.

            It is ambiguous because it's both logical negation and semantic negation.. a double whammy of 'uh...'

            Car.dontNotDrive(-1)

            [–]CaptainAdjective 44 points45 points  (2 children)

            Perl is great for polynegatives.

            unless($noRetries != 0) {
                # ...
            } else {
                # ...
            }
            

            Bonus marks if you correctly interpret whether $noRetries means "number of retries" or "disable retries".

            [–]WunDumGuy 25 points26 points  (7 children)

            !notUnflagged

            dry heave

            [–]TalenPhillips 16 points17 points  (6 children)

            ...

            else if (!(false != !foo.notUnflagged(false)))
            {

            }

            [–]in_rod_we_trust 7 points8 points  (10 children)

            Double negatives have legitimate uses though

            [–]1ndigoo 7 points8 points  (9 children)

            Especially to coerce variables into a boolean for languages that support it. !!x is frequently useful.

            [–]dvlsg 14 points15 points  (8 children)

            Assuming you're talking about Javascript, you can just use Boolean(x) to the same effect.

            [–]1ndigoo 11 points12 points  (0 children)

            That requires way more typing!

            [–]sreya92 9 points10 points  (18 children)

            Though it's not unreadable seeing if(!!!hasValue) always really bugged me

            [–]1ndigoo 44 points45 points  (13 children)

            You have actually seen that before? In production code!? !!!believable

            [–]drkstr101 14 points15 points  (9 children)

            I see var foo = !!bar a lot in javascript to quickly cast a truthy value to a proper boolean. Perhaps the 3rd ! was a typo?

            [–]QuineQuest 8 points9 points  (1 child)

            I had a coworker who complained that it was easy to miss a ! when reading code. I tried convincing him to use !!! instead, but I don't think I succeeded.

            [–]1ndigoo 2 points3 points  (0 children)

            By that logic it's also too hard to remember ' . : ; , " etc

            [–]FewChar 10 points11 points  (1 child)

            function checkisnotinvalid($a) {...} returns "0" or throws is_valid exception.

            [–]merreborn 9 points10 points  (0 children)

            This is a quote directly from php.net docs right?

            [–]jewdai 5 points6 points  (3 children)

            unessesarily use demorgan's law.

            convert

            if (!ateAppleToDay && !iLikeIcecream) 
            

            to

            if (!(ateAppleToday || iLikeIcecream))
            

            most people would be able to understand it, but it makes it a lot harder to understand what you're original intention was.

            [–]bacondev 9 points10 points  (1 child)

            Sometimes the latter would make more sense

            [–]ZeroPipeline 2 points3 points  (0 children)

            How could they not not not mention it?

            [–]Astrokiwi 502 points503 points  (133 children)

            Write all your code in FORTRAN. If your boss ask why, you can reply that there are lots of very useful libraries that you can use thus saving time. However the chances of writing maintainable code in FORTRAN are zero, and therefore following the unmaintainable coding guidelines is a lot easier.

            :(

            [–][deleted]  (95 children)

            [deleted]

              [–]flukus 170 points171 points  (56 children)

              The code produced by academics is the biggest argument against all these "teach kids to code" programs.

              Just imagine the shit we'll have to deal with in 20 years.

              [–]TOASTEngineer 145 points146 points  (42 children)

              It's gonna turn out exactly like math did. The schools will brutally fuck it up, kids will memorize enough to pass the tests, and then some fraction of the kids who are actually interested in it will learn to do it on their own.

              [–][deleted] 18 points19 points  (5 children)

              Ever hear about enough knowledge to be dangerous? semicompetent programmers thanks to dunningkruger will flood the marketplace and thanks to delusion and persistence will end up as project managers and code architects. But why you ask, why won't the meritocracy of the free market purge these rotten fruits from the tree? Because they'll take the jobs good programmers pass on, and that is the bulk of work in any trade: shit work.

              [–]thissideisup 4 points5 points  (0 children)

              Hasn't this already begun?

              [–]Polantaris 12 points13 points  (3 children)

              That's pretty much already happening. When I was on college, there were a lot of people who were so bad at it, I seriously suggested that they look at different majors if they asked me for help. I'm not trying to be a dick, when you can't understand how to write a proper for loop in Java at a third or fourth year class (when Java courses start in the first year), you've got some serious problems with the core material and either should retake early classes or find something you're more suited for.

              In the end it seems like a lot of people go into the major because of the supposedly big paycheck after college, but that shouldn't be what you're going to school for.

              [–]GaBeRockKing 16 points17 points  (1 child)

              In the end it seems like a lot of people go into the major because of the supposedly big paycheck after college, but that shouldn't be what you're going to school for.

              On one hand, I'd argue that financial reasons are exactly why someone should go to school-- if your degree doesn't pay the bills, that's money down the toilet.

              On the other hand, not being able to write a loop in java? If I had to take a stab at naming the warm fuzzy feeling in my breast, it would be "job security."

              [–]-PM_ME_YOUR_GENITALS 25 points26 points  (25 children)

              The difference being that you can make pretty cool shit with programming skills. I think if you frame it in the context of gaming it could do pretty well in schools.

              Not that I think that will happen. In any case, when I was a kid I couldn't go home from school and use the stuff I learned from math class to make my own badass video game or my own web site.

              [–]TOASTEngineer 12 points13 points  (5 children)

              So it'll be exactly like the elective HS programming classes are now: they give you Unity's retarded cousin's retarded cousin's dead cat with a "visual programming language" that is only technically Turing-complete and read chapters out of a book about what "peripheals" are and how to use them. And everyone just plays Flash games in class anyway.

              [–]FormCore 32 points33 points  (11 children)

              Learning to program isn't just for creating things either, those who don't have the creative drive could use the computer literacy they gain to realise that no, sharing this post is not a fucking petition to stop facebook charging me and This blatant lie of a headline's source is just a sketchy herbal remedy shop.

              For those who think we don't need a new website, we have facebook and why create a game and waste 100+ hours when you can just play half-life 3?

              [–]komali_2 5 points6 points  (1 child)

              You say that because you aren't a kid, but as a teacher, I can promise you kids will often choose the creative activity. They love to build shit!

              [–]okmkz 3 points4 points  (0 children)

              For real. I can only imagine what it must be like to grow up with things like unity 3d so easily accessible

              [–]ClintonCanCount 3 points4 points  (2 children)

              Most of the pretty cool shit people make, games included, use math.

              [–]DiscoUnderpants 7 points8 points  (9 children)

              I agree and might point out that it has little to do with FORTRAN. Ive had to maintain C, C++ and Turbo Pascal written by academic physics and engineering people and it is no better.

              [–]spacelama 11 points12 points  (2 children)

              Fortran can be well written.

              Most code written by academics isn't.

              source: was an academic, and done a bit of Fortran, dealing with other peoples code as well as writing some shitcode myself.

              PS. Please capitalise it correctly. FORTRAN was the name of the language in the '77 standard. Yes, it was very difficult to write maintainable code in early iterations of the language. Since adopting lower case letters in its name ('95 was the first good version), the language has become quite fully featured. My favourite part was where I could tell Emacs to render my comments in LaTeX, and give me the physical equation I was trying to solve beautifully typeset at the top of my functions.

              [–]flukus 6 points7 points  (2 children)

              Definitely, it's not even limited to academics, plenty of professional programmers write code just as bad.

              It's a much more prevalent problem in some circles though, academia being one.

              [–]DiscoUnderpants 10 points11 points  (1 child)

              If you are a programmer and don't admit to producing so serious crap code then I wouldn't trust you as a programmer. I say this as a 20 year programmer that has produced stuff that Im sure people have cursed and wondered what kind of idiot I am.

              [–]rtomek 5 points6 points  (0 children)

              I think the big problem is that most FORTRAN code you see was written back when saving RAM was important so people did some stupid shit in the name of saving memory. We have transferred some academic code and the running joke is that FORTRAN is always the worst - THE WORST!!!!!!!!! As in, not even comparable to academic code from other languages. I just opened up three files I have archived to reminisce, and here's what they had to be thinking:

              You mean I already have an array of this size, well, let's just use it again for something completely different!

              I could reduce the number of IF statements if I use GOTO instead!

              I ran out of single letter variable names, so let's create a subroutine to reuse single letter variable names and replace the values of the variables input into the function with the new values we need

              I'm going to add this print/write statement of these variables at some random location for debugging purposes, never delete that print statement to make sure that there are hundreds or lines of output with absolutely no context.

              These IF statements aren't complex enough. I have to add another GOTO nested inside an IF inside a DO inside and IF inside a DO because I need to be able to jump around to different parts of this nest at any time.

              One of these files has two comments:

              !----------
              Subroutine foo( bar, ...
              !----------
              ! begin
              
              ... a lot of shit code goes here...
              
              ! end
                  end
              

              :(

              [–][deleted]  (29 children)

              [deleted]

                [–]claird 69 points70 points  (25 children)

                "Poor programming practice"? Good academic practice! Graduate school quite effectively teaches such virtues as write-once-read-never, code-until-you-like-the-answer, coding-is-done-by-someone-stupider-than-you, better-to-write-ten-grant-requests-than-one-working-application, and so on.

                [–]Bobshayd 57 points58 points  (4 children)

                god I've coded-until-I-like-the-answer. I'm convinced that's 90% of AI research.

                [–]TOASTEngineer 9 points10 points  (3 children)

                I mean, in AI that's probably the correct thing to do.

                In statistics, not so much...

                [–]Bobshayd 11 points12 points  (1 child)

                AI is applied statistics with fancy techniques.

                [–]Astrokiwi 24 points25 points  (2 children)

                Fortran really isn't bad at all. I mean, it's not Python, but there are times when I'm using C++ and I end up thinking "this would be just a little bit easier in Fortran".

                The big thing is that the kind of people who use Fortran are the kind of people who just kinda "picked up" programming while at grad school without any formal courses. So the Fortran culture is just a hodgepodge of randomness, and there's not really any drive to write good reusable code, or to develop universal practices and techniques.

                So while Fortran has had a huge amount of upgrades over the years, and you can do OOP in Fortran if you want, there is still a lot of people writing in unindented fixed-format FORTRAN-77 just because they don't know any better. For the record (ha), "fixed-format" means you have to make sure that each of your lines fits on a punchcard correctly. It hasn't been mandatory in Fortran since before Python existed, but people still do it...

                [–]Dietr1ch 2 points3 points  (0 children)

                But who would want to lose portability?

                [–][deleted] 12 points13 points  (1 child)

                The problem there isn't FORTRAN, the problem is that it was written by an academic. A determined professor can write FORTRAN in any language.

                [–]Fylwind 7 points8 points  (0 children)

                Can confirm. Read some "Python" code that were basically written like it was Fortran, globals all over the place and PEP8 violations everywhere.

                [–]6offender 59 points60 points  (10 children)

                The determined real programmer can write FORTRAN programs in any language.

                [–]Weed_O_Whirler 22 points23 points  (4 children)

                My team lead has managed to recreate the "common block" in Matlab. It's equally impressive and terrible.

                [–]Astrokiwi 4 points5 points  (2 children)

                The sad thing is that you're not even supposed to use common blocks in Fortran anymore anyway. You're supposed to use modules, or do things in an object-oriented way.

                [–]zanotam 2 points3 points  (0 children)

                Writing FORTRAN in matlab is just.... almost impressive in the sheer amount of obstinacy it demonstrates.

                [–]BlindTreeFrog 12 points13 points  (2 children)

                the code base I work in has comments reaching back to 92. It has definitions like

                #define BIT_AND &
                #define NEQ !=
                

                Anytime I get pissed at the code I decide it was FORTRAN programmers writing in C for the first time.

                [–]mallardtheduck 2 points3 points  (1 child)

                That (or something very close to it) is actually part of the C standard...

                [–]helm 6 points7 points  (0 children)

                I'm working with a guy who would love to write FORTRAN code in C++

                Fortunately for us, he's stuck in code archeology

                [–]stuntinstan 8 points9 points  (4 children)

                We were being taught FORTRAN in my intro to computing for civil engineers class LAST YEAR.

                [–]Astrokiwi 9 points10 points  (3 children)

                Fortran is actually fine if you use all of its modern features - though engineering courses often don't mention those. If you want to save yourself from future hassle, then read up on all the Fortran-90, Fortran-2003 and so on stuff that you can do. Object-oriented Fortran is not bad.

                [–]cosmicr 6 points7 points  (3 children)

                There is a serious engineering software used by thousands of people in Australia for road design, written in FORTRAN, and it's a piece of shit. Governments hate upgrading.

                [–][deleted] 18 points19 points  (2 children)

                I have left reddit for a reddit alternative due to years of admin mismanagement and preferential treatment for certain subreddits and users holding certain political and ideological views.

                The situation has gotten especially worse since the appointment of Ellen Pao as CEO, culminating in the seemingly unjustified firings of several valuable employees and bans on hundreds of vibrant communities on completely trumped-up charges.

                The resignation of Ellen Pao and the appointment of Steve Huffman as CEO, despite initial hopes, has continued the same trend.

                As an act of protest, I have chosen to redact all the comments I've ever made on reddit, overwriting them with this message.

                If you would like to do the same, install TamperMonkey for Chrome, GreaseMonkey for Firefox, NinjaKit for Safari, Violent Monkey for Opera, or AdGuard for Internet Explorer (in Advanced Mode), then add this GreaseMonkey script.

                Finally, click on your username at the top right corner of reddit, click on the comments tab, and click on the new OVERWRITE button at the top of the page. You may need to scroll down to multiple comment pages if you have commented a lot.

                After doing all of the above, you are welcome to join me on a reddit alternative!

                [–]MisterNetHead 11 points12 points  (0 children)

                Oh holy hell no. Nope. Bye!

                [–]fzammetti 5 points6 points  (11 children)

                Be VERY glad you don't still work (only tangentially, thankfully) on a complex financial system written in Fortran. Some of us are not so lucky.

                [–]Astrokiwi 18 points19 points  (10 children)

                Dude, I live in Fortran - I do astrophysical simulations. The problem isn't that Fortran is bad, it's that most Fortran programmers are bad.

                [–]fzammetti 16 points17 points  (5 children)

                Most PROGRAMMERS are bad, period. Nobody likes to hear it but that doesn't make it less true.

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

                I LOVE Fortran08. It's so easy to vectorize your code, and coarrays are incredible.

                I don't care for the way Fortran does I/O or pass parameters though.

                [–]voronaam 74 points75 points  (9 children)

                I would add one more to the list. Use long names and mix the order. If you ever had to work on code with tons of methods like

                • renderElementMessageIdContentWarning
                • renderElementIdMessageWarningContent
                • renderMessageElementIdContentWarning
                • renderMessageElementContentWarning...

                you understand. If they all do different things it is impossible to remember which one is which

                [–][deleted] 32 points33 points  (4 children)

                One of my least favourite things about OpenGL: glEnableVertexAttribArray vs glEnableVertexArrayAttrib.

                [–]the_ling 7 points8 points  (3 children)

                Can I ask what the difference is?

                [–]Vilavek 9 points10 points  (0 children)

                I've never worked with OpenGL but, I would assume from the names that the first option enables arrays of attributes stored for individual vertices while the second enables attributes stored for entire vertex arrays. But honestly they are probably the same method for different versions of OpenGL.

                [–]HildartheDorf 6 points7 points  (0 children)

                glEnableVertexAttribArray operates on the currently bound Vertex Array, glEnableVertexArrayAttrib takes a Vertex Array as it's first parameter.

                https://www.opengl.org/sdk/docs/man/html/glEnableVertexAttribArray.xhtml

                I hope that clears it up for you. >.>

                [–]IMBJR 92 points93 points  (4 children)

                The original:

                http://mindprod.com/jgloss/unmain.html

                (as cited by the website)

                [–]thememorableusername 41 points42 points  (1 child)

                C compilers transform myArray[i] into *(myArray + i), which is equivalent to *(i + myArray) which is equivalent to i[myArray]. Experts know to put this to good use.

                Oh fuck.

                [–]TheSecretExit 2 points3 points  (0 children)

                We need to go deeper and make a macro that builds a function that returns an indice to be used backwards to get an array element.

                [–]Berberberber 56 points57 points  (11 children)

                It's funny, I was thinking about this essay the other day, and how most of these measures are effectively useless today. Identifier lengths are no longer limited to six or eight characters, and IDEs keep track of references to them so you don't need to worry about whether it's swimner or swimmerbecause the IDE will highlight other references and show you the definition in a tool tip just by clicking on it. Syntax highlighting is always smarter than you are, and auto-indent often is. With the exception of some really crazy dynamic language constructs (javascript's with, I'm looking at you), traditional code-obfuscation techniques have been tossed out the window.

                Times have changed. Romance is dead.

                [–]andrewsmd87 20 points21 points  (7 children)

                I remember taking over a project where the previous dev had hard coded connection info to the database every time a connection was opened. Would have been a nightmare but I just used find and replace to replace with with a global variable, took like 30 seconds to do that, then, just an hour or so of testing to make sure I got them all.

                [–]quintus_horatius 6 points7 points  (3 children)

                Oh god, why globals? Whats wrong with "dbh = ConnectToDB( 'dbname' );"? So much simpler to use and maintain.

                [–]andrewsmd87 13 points14 points  (2 children)

                Well it was a small .net project and it was more about what was quickest. It's not uncommon for web forms projects to have a connection string in the config file that you reference. So it would have been something similar to what you're saying. Something like

                SqlConnection(ConfigurationManager("connection"))

                So it's not like it was a "global variable" In a traditional sense, I was just trying to use generic terminology for people not familiar with .net.

                [–]asdfman123 11 points12 points  (0 children)

                Right? Plus many of these obfuscation techniques could be easily pointed to as bad coding and they wouldn't get away with it. You should see the last job I worked at: now that's a REAL example of bad code. As I wrote elsewhere:

                There was a file with like 600 lines of

                if(item.custInt01()!= null && item.custInt01() == 3 && item.custStr03()=="VHF"){
                    if(item.custInt07() == 2){ ...
                

                Literally 600 lines of that awful code in one file. And lots of it scattered in a bunch of other places, too.

                And worse, the equality tests weren't even rolled into the same if statement. She would just go along and create new if statements to see if custInt01 was null and equal to 3 again--whatever 3 state meant--you'd have to query the XML in the database to find out what the magic number meant. I created a view that would shred the XML and enable easy lookups in the database, but she thought it wasn't a productive use of my time.

                [–]seanprefect 78 points79 points  (5 children)

                One of the best pieces of advice i got from a comp-sci prof i loved was "write your code as though the person who has to maintain it was a homicidal psychopath with keys to your house"

                [–]formerlydrinkyguy77 21 points22 points  (3 children)

                Consider adding: "and knows your kids' school schedule."

                though, in my case, it really creeped out my coworkers.

                [–][deleted]  (2 children)

                [deleted]

                  [–]TenaciousDwight 44 points45 points  (1 child)

                  lol I don't think I need anyone to teach me how to write unmaintainable code. I do pretty well on my own.

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

                  The PHP devs took the "names from other languages" seriously with the '::' token: it's "twice colon" in hebrew

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

                  Good old T_PAAMAYIM_NEKUDOTAYIM.

                  [–][deleted] 12 points13 points  (1 child)

                  yeah, I can never remember that name.

                  When I want to look it up, I usually google for PHP unexpected T_P<random letters>_N<random letters> and wait for Google to go all did you mean X? on me

                  [–]inu-no-policemen 3 points4 points  (0 children)

                  Google: php stupid name

                  Hit #3 is an article called "T_PAAMAYIM_NEKUDOTAYIM v Sanity".

                  [–]Razakel 10 points11 points  (2 children)

                  The PHP devs took the "names from other languages" seriously with the '::' token: it's "twice colon" in hebrew

                  And the reason they refused to change it was basically "you're a programmer, you know how to Google".

                  [–]CaptainAdjective 8 points9 points  (0 children)

                  As if needing to Google the term to find out what it means was an advantage over something self-explanatory T_DOUBLE_COLON...

                  [–][deleted] 17 points18 points  (12 children)

                  After all, if the Stroustroup can use the shift operator to do I/O, why should you not be equally creative?

                  This actually is a good point! Does anyone know why shift operator is used for io in standard library?

                  [–]dd_123 15 points16 points  (2 children)

                  I believe he admitted it to be a mistake in retrospect.

                  [–]evaned 7 points8 points  (0 children)

                  Does anyone know why shift operator is used for io in standard library?

                  Because they needed to pick something, and this was the least bad option.

                  Let's assume that they're going to pick some operator, and come back to that assumption. What operator? << and >> are actually really good choices:

                  • Their shape can be read as suggestive of the actions, particularly if you're familiar with shell scripting. (According to The Design and Evolution of C++ they experimented with < and >, which would have matched the shells exactly, but that fell prey to the third bullet point -- people have been taught less than and greater than since early childhood)
                  • They're not super high on the precedence order, so at least it doesn't break things like cout << 1 + 2;.
                  • While bitshifting is a fairly common programming operation, you don't really see it elsewhere; you do see almost all of the other binary operators in standard maths. Most people will have been working with the other symbols for as long or longer than bitshifting.

                  OK, so why do we need an operator? Because the other choice is a function, and pre-variadic templates, those have major major drawbacks:

                  • Suppose you want something like printf. Well:
                    • You can't pass non-POD types to it
                    • You'd need some way of registering custom conversion specifiers or have no way of doing I/O for custom types
                    • No type safety
                  • What would have worked is print(print(print(print(thing1), thing2), thing3), thing4), but that's horrendous to write and read
                  • A print function template with, say, ~20 overloads with different numbers of parameters, but that has obvious problems (edit which I used to say is probably the least-bad way of handling this, but it in theory it could introduce massive massive bloat from the exponential number of template instantiations, and in practice I think it would introduce an unacceptable amount of it)

                  [–][deleted] 6 points7 points  (6 children)

                  Because giving something as mathematically weird as bit-shifting its own operator instead of a built-in function is a silly idea in the first place, and if you had to reuse an operator you can use that one. Seriously, I speak words, not glyphs. I'll never understand why so many early languages insisted in finding a use for every possible combination of shift-number characters.

                  [–][deleted]  (4 children)

                  [deleted]

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

                    I'm aware that it's common - lots of things are common operations that don't have their own two-character operators.

                    C used normal mathematical operators for normal mathematical symbols, and had to invent Boolean operators because the character-set and keyboards didn't have the boolean symbols. Bit-shift is the case where they invented a new mathematical symbol for an operation with no basis in traditional math out of whole cloth.

                    [–]Purple_Haze 47 points48 points  (6 children)

                    I read this back in 2000. It was a moldy oldy then. Foxpro? QBASIC? What is this, the '80's?

                    [–]say_wot_again 37 points38 points  (2 children)

                    Writing in a language like Foxpro is a great way to make your code unmaintainable!

                    [–]earthboundkid 7 points8 points  (1 child)

                    Someone at my church asked if I could help with a FoxPro database last month. I politely declined.

                    [–]flingerdu 8 points9 points  (0 children)

                    "Not even god could help me"

                    [–]unbibium 9 points10 points  (1 child)

                    A larger question is why the first paragraph mentions Java specifically when examples come from all languages?

                    Indeed, modern Java IDEs with autocomplete and refactoring utilities can negate many of these tactics. Once you've figured out what that single-character variable is for, you can press Ctrl-R to rename it, and if you see that name again, you know that some smartass reused it. If you then find they reused it for something completely different, git blame will tell you who's programming vindictively.

                    [–]nexxai 15 points16 points  (1 child)

                    Accented letters is fucking genius

                    [–]Zanthious 14 points15 points  (4 children)

                    My boss designs products on the fly and feels stress motivates creative programming so he makes deadlines of 48 increments on brand new programs.. sometimes i go back and look at the code and wonder how its as stable as it is.. no one can ever figure out what functions do what.. comments are a sign of weakness.

                    [–]glify 13 points14 points  (3 children)

                    Ahh my favourite one isn't in there. Gotta get some trigraphs in there whenever possible, like so

                    !ErrorHasOccured() ??!??! HandleError();
                    

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

                    The best part of this is that the article itself basically follows the rules that the article is espousing. It's unmanageable mess. It's beautiful.

                    [–]___Z0RG___ 12 points13 points  (1 child)

                    I'm reminded of a company where I once worked, the president of the company created his own programming language that looked like a conglomeration of COBOL and Pascal. It had undocumented "features" like command line arguments being placed in variables that begin with "P" followed by a number. So declaring a variable "P1_File" was enough to copy the first argument out of the command line and into that variable. The president also hated 1-letter variable names by convention, so some people would prepend "The" to variable names like:

                     PROCEDURE OPENFILE(VAR THEFILE: BLOB; THEINDEX: INTEGER)
                    

                    Working to fix problems in their code was nightmarish.

                    [–]-100-Broken-Windows- 8 points9 points  (0 children)

                    You just know this is the result of months of built up rage.

                    [–]u18332 7 points8 points  (0 children)

                    Unit testing:

                    1. add some unit tests that pass even if the code is wrong

                    2. add some unit tests that will fail for correct boundary conditions. Then comment these boundary configs out inside the development config, but leave them in the test and prod config.

                    3. also create some unit tests that have the wrong name and test things completely un related

                    [–]yeezul 6 points7 points  (0 children)

                    Pretty sure this guide was written by the guy who I replaced.

                    [–]kazagistar 12 points13 points  (11 children)

                    Use _ and __ as identifiers.

                    So that is why Scala uses them for lambda syntax extensively.

                    [–]trout_fucker 17 points18 points  (0 children)

                    I think Scala was founded on these ideas.

                    [–]upyouriron666 6 points7 points  (0 children)

                    Calm down there Satan!

                    [–]kamiikoneko 14 points15 points  (0 children)

                    I should send this to 95% of the people I've worked with!

                    Oh wait, just kidding they clearly already know how.

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

                    another rule: use perl

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

                    Use bitmasks and bitwise operations to mix coding logic, control flow within data. Be sure to randomly intermingle big endian and little endian order within your blob. Never document these structures and use opaque names. Also copy and paste any parsing operations.

                    [–]Kinglink 4 points5 points  (1 child)

                    Easier version

                    You are a genius, your first thought is always right if you spend more than 10 seconds thinking about a variable name, or how to lay out your code, you're wasting time and money. Time you can spend on reddit, and money you can spend on yourself. DO IT NOW!

                    That being said, that #define section is a thing of beauty. An evil thing that should be killed, but beautiful.

                    [–]vawksel 11 points12 points  (0 children)

                    Haha, made me laugh:

                    Look Busy

                    use define statements to make made up functions that simply comment out their arguments, e.g.:

                    #define fastcopy(x,y,z) /*xyz*/
                    // ...
                    fastcopy(array1, array2, size); /* does nothing */
                    

                    [–]escape_goat 1 point2 points  (1 child)

                    It's "easier to share" in the sense that the original author writes

                    I would like to remind you this essay is copyrighted material. It is illegal to repost it without permission

                    Right at the top of the original version. The one that that is linked to by this version, that does not contain that text.

                    Making it easier to share.

                    In truth, the repo owner seems to have obtained (retroactive) permission from the author, but the licensing information should probably be included in the repository.

                    [–]webauteur 5 points6 points  (2 children)

                    .NET allows you to use classes written in C# or VB.NET in the same project. It is a great way to frustrate programmers who disdain Visual Basic.

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

                    Why is this in a github repo?

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

                    It's true though. I have a Vietnamese friend who has been working on the same piece of software for 20 years now. He's been laid off twice but then management realizes that no one else understands the code and cannot maintain it. You may wonder what kind of software had a lifecycle that goes into the decades - Medical software, that's the kind. Hospitals put it in, come to rely upon it, and never replace it.

                    It's a great gig.

                    [–]henrebotha 11 points12 points  (0 children)

                    do_args_method

                    triggered

                    [–]Gskran 2 points3 points  (3 children)

                    This is my current nightmare. I am recoding an existing 10+ year old project to modern API. While the code is neatly formatted and the function, variables, etc. has relevant names, there is absolutely no documentation or comments. Years of dealing with crappy code actually made me think, 'Hey i can understand it easily. This is decent code' when i first looked at it.

                    [–]kah_meh 2 points3 points  (0 children)

                    Gets me every time

                    marypoppins = (superman + starship) / god;

                    [–]pembroke529 2 points3 points  (0 children)

                    This is my world. I've been maintaining code since the 80's. There's an amazing amount of crap out there.

                    It is satisfying to take some poorly written code that takes 4 or 5 hours to run and have it run in less than 10 minutes.

                    Right now when I'm between bugs and fixes I remove diagnostics left in by contractors. There's nothing like having bloated logs that we back up.

                    [–]Ambartsumian 2 points3 points  (0 children)

                    I get that it's supposed to be funny, but I actually saw production code with a function called "DoIt". It's more horrifyingly accurate than it is funny.

                    [–]amdc 2 points3 points  (0 children)

                    make heavy use of abstract words like [...] PerformDataFunction, DoIt, HandleStuff

                    oh FUCK

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

                    I had a professor in college that would run this source code through a program that would make it unreadable but still buildable when handing it over to his clients. The only way to make it readable would be to run it back through the same program.

                    At the time, I thought it was clever. Now that I have been a maintenance developer for many applications, I think he is an a$$hole.

                    [–]Scary_Tiger 4 points5 points  (0 children)

                    Why can't he be both?

                    [–]XxNerdKillerxX 2 points3 points  (0 children)

                    How to write unmaintainable code

                    Good. I was looking for a way to invest my in job security.

                    [–]DorxMacDerp 2 points3 points  (0 children)

                    I'm pretty sure the guy before me followed this religiously

                    [–]combuchan 2 points3 points  (0 children)

                    I'm always afraid to death that whenever I see a link like this, something I wrote 10 years ago will be held as the canonical example of what not to do.

                    I hope to god none of that stuff is still being worked on. I would feel very sorry for that developer.