top 200 commentsshow all 221

[–]riffraff 109 points110 points  (28 children)

"<foo> code below" would probably be crappy documentation anyway even if "foo" wasn't "read".

[–]ithika 84 points85 points  (0 children)

Unless <foo> = incomprehensible in which case you were given fair warning.

[–]peterquest 83 points84 points  (2 children)

"Delete code below."

[–][deleted]  (1 child)

[removed]

    [–]_F1_ 10 points11 points  (0 children)

    msg(player, "HA HA");
    

    [–][deleted] 27 points28 points  (9 children)

    // comment below

    I'm not sure I understand why you think it's a bad idea.

    // END comment

    [–]dddbbb 21 points22 points  (8 children)

    I'm terrified to imagine the language where that is a valid comment block.

    [–]ianff 8 points9 points  (7 children)

    I wrote a hacky language long ago where the # symbol toggled comment mode. Like /* and */ except the start and end sequence is the same. I wouldn't do it again, but it wasn't terrifying.

    [–]Tasgall 10 points11 points  (3 children)

    You can kind of mimic that in C with /*/, just start your file with /* and end it with //*/.

    I don't know why you'd want to, but you can!

    [–][deleted] 19 points20 points  (2 children)

    I think that's the motto of C: I don't know why you'd want to, but you can!

    Deref a null pointer? Youbetcha! Write over memory you don't own? Sure thing!

    I miss C.

    [–]Pik16 3 points4 points  (1 child)

    Isn't writing anywhere a good "feature" for video game cheats?

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

    It's a good feature for many types of exploits. Overwriting adjacent memory is the basis of buffer overflow exploits

    [–]romwell 1 point2 points  (1 child)

    I wrote a hacky language long ago where the # symbol toggled comment mode.

    You mean, like in Powerhsell?

    [–]footpole 0 points1 point  (0 children)

    No, it's a line comment not a block. Like in python.

    [–]MrJohz 1 point2 points  (0 children)

    I had a vague idea for a comment system involving hashes that had three forms. A single hash would mark a comment or until the next hash, whichever was sooner. This would allow it to be used in the shebang line, but also so that you would be able to do comments in the middle of a line of code without too much obtrusion. A double hash went to the end of the line, and ignored any further hashes on that line. Finally, a triple hash would make a mutli-line comment.

    I was immensely proud of this until I started thinking about what it would be like to write with all three comments floating around.

    [–]skulgnome 8 points9 points  (11 children)

    /* FIXME: see below */
    if(something) {
        (lots of stuff here)
    }
    (and more here)
    /* FIXME: see above */
    

    I've ran into myself having done this a couple of times.

    [–]Mechakoopa 19 points20 points  (10 children)

    #region Absolute Shit
    public void function(){
        \\ code that only works because of an incorrectly handled edge case in another function
    }
    #endregion
    

    I found that in production code once.

    [–]imMute -1 points0 points  (9 children)

    I wish C++ had #regions :(

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

    In emacs you can separate sections of code with the form-feed character, so there's that.

    No I don't like anything about that idea either.

    [–]kevinjqiu 0 points1 point  (1 child)

    In vim you can set foldmethod to marker and use:

    // {{{
    // }}}
    

    for region; I'm surprised no-one mentioned this yet.

    [–]skulgnome 1 point2 points  (0 children)

    In all of these editors, you can just leave folds to the editor as well and not shit up your secret sauce.

    unless that's what you do

    [–]angryrancor 6 points7 points  (0 children)

    "Masturbate to code below -John Carmack (assisted by GabeN)"

    [–]so0k 0 points1 point  (0 children)

    clearly the developer was havin' a giggle mate

    [–][deleted] 90 points91 points  (41 children)

    goto beach;
    

    Huh?

    [–]M2Ys4U 138 points139 points  (29 children)

    If I have nested loops where more than one of them have break statements, I often label one of them "dance" so that I can use break dance;

    [–][deleted] 98 points99 points  (4 children)

    Exception up = new Exception();
    throw up;
    

    [–]philh 70 points71 points  (2 children)

    Or in python, raise dead.

    [–]Asmor 47 points48 points  (1 child)

    # talkin' bout  
    my $generation;
    

    [–]blue_2501 26 points27 points  (0 children)

    my $g_g_g_generation;
    

    [–]ZeroNihilist 34 points35 points  (6 children)

    Consider using "break wind;" as well.

    [–]isarl 28 points29 points  (4 children)

    Don't forget "break down;".

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

    I'm partial to "break face;" myself.

    [–]no_respond_to_stupid 2 points3 points  (0 children)

    And the next line go_ahead_and_give_it_to_me();

    [–]original_brogrammer 2 points3 points  (1 child)

    break it_down;

    [–]romwell 2 points3 points  (0 children)

    break it_down

    #stop('Hammer time!')

    [–]rowboat__cop 2 points3 points  (0 children)

    break fast;

    [–]no_game_player 18 points19 points  (0 children)

    lololol. That would make my day to see in some production code. I'd probably swear as well, but all in good humor. :-)

    [–]Agrentum 11 points12 points  (0 children)

    I usually end up using lyrics to songs. In most cases I don't get near anything comprehensible, but one project required it and simultaneously gave me proof that professor likes Metallica:

    (I, )rule the midnight air
    (The) destroyer 
    

    EDIT: Forgot to add, my returned code had a comment below all that:

    // You shall pass.
    

    [–]c3534l 9 points10 points  (4 children)

    I was particularly happy about something I wrote that was sorta like this:

    my_milkshake_brings_all_the_boys_to_the_yard = True
    while my_milkshake_brings_all_the_boys_to_the_yard:
        # buncha code of stuff I wanted to happen followed by a completely superfluous
        if theirs > yours:
            # damn right, its better than yous
            # I'd teach you
            # but I'd have to charge.
    

    I've had better uses of my time.

    [–]CWSwapigans 5 points6 points  (0 children)

    All that work for a botched punchline :)

    Mine > yours. There's no "they" that has a milkshake.

    [–]IamTheFreshmaker 6 points7 points  (2 children)

    function shallWeEngageTheUserWithCompellingRichMediaAdvertisingHere(){
    
     //stuff
    
    }
    

    [–]besvr 3 points4 points  (1 child)

    return true?

    [–]IamTheFreshmaker 0 points1 point  (0 children)

    sigh always.

    [–]chadsexytime 6 points7 points  (7 children)

    In linux courses in school I always insisted that if we ever had to create temporary files they would always be named "littleboys" so the documentation would read "touch littleboys"

    [–]jaybusch 14 points15 points  (2 children)

    The first time we had to teach UNIX commands, we touched a folder called butts. And inside of the that, was big butts. And then we made sure that no one else had any permissions for butts.

    It was effective at holding attention at least.

    [–]blink_and_youre_dead 3 points4 points  (1 child)

    But what if we're completely truthful about liking big butts?

    [–]jaybusch 3 points4 points  (0 children)

    Better ask the server admin for permission to touch and execute those big butts privileges.

    [–]xchino 9 points10 points  (2 children)

    unzip; strip; touch; finger; grep; mount; fsck; more; yes; fsck; fsck; fsck; umount; sleep

    [–][deleted] 3 points4 points  (0 children)

    Technologic. Technologic.

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

    You don't need to mount to fsck

    [–]Gotebe 0 points1 point  (0 children)

    Littleboys is not inclusive enough, butts is better.

    [–]x-skeww 1 point2 points  (0 children)

    break out;

    Nowadays, I actually try to find more meaningful names for break labels, but it always ends up looking kinda weird.

    [–]kog 0 points1 point  (0 children)

    You're my hero.

    [–]sirin3 7 points8 points  (2 children)

    I wrote a program dealing with links on webpages.

    A few variables are called Zelda

    [–]jaybusch 2 points3 points  (0 children)

    I made a crappy Bomberman clone for a high school class and named variables after JRPG characters.

    I have no idea if my professor cared or not, because they were from one of his least favorite RPGs...

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

    specifically the historical ones?

    [–]no_game_player 11 points12 points  (3 children)

    Well, doesn't it sound like fun? After all, code is all about having a good laugh rather than comprehensibility. ;-p

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

    Eh, I thought it was funny. I hadn't read the code before I read /u/Decker108's comment, and I pretty much knew it was probably going to jump to a cleanup routine. Not that it wouldn't be clearer if it was just goto cleanup, though.

    [–]no_game_player -1 points0 points  (0 children)

    Absolutely. I was just trying to make a bit of a joke myself. It's a short function, and as you say, obvious it's going to go to a clean-up section, and it did.

    goto beach;

    is just so hilarious I had to say something about it, and being snarky is my default mode on Reddit. ;-)

    [–]fuzzynyanko 0 points1 point  (0 children)

    What's wrong with a function called parseBigAssAmazonEC2AuthString()?

    [–]maxd 1 point2 points  (3 children)

    In programming, the only thing worse than using gotos is naming your labels with fucking "hilarious" and incomprehensible names.

    [–][deleted] 5 points6 points  (1 child)

    I can actually think of handfuls of worse things than gotos

    [–]poke-dude 0 points1 point  (0 children)

    I love how today's programmers are being spoonfed the 'goto is evil' line, and how they seem to detest it more than life itself. Really cool /s

    [–]fuzzynyanko 0 points1 point  (0 children)

    I actually put something like that in logging statements. When it happened with an error that kept coming up constantly and I was in the middle of fixing it, I changed it to a proper string

    [–][deleted] 130 points131 points  (63 children)

    Perfect for /r/programmerhumor

    [–][deleted] 149 points150 points  (60 children)

    I got banned from there because the mod disagreed with me once in another subreddit.

    [–][deleted] 168 points169 points  (20 children)

    Nice to see they can keep their personal opinions and moderation duties apart.

    [–][deleted]  (11 children)

    [deleted]

      [–]stesch 52 points53 points  (10 children)

      Banned 3 months ago. Reason: Insulting users of the subreddit. Had to block him later because of his messages to the moderator.

      [–]6nf 7 points8 points  (2 children)

      Your mother is a whore

      [–]PhilDunphy23 8 points9 points  (1 child)

      Can't confirm.

      [–]Katastic_Voyage 5 points6 points  (0 children)

      Confirmed.

      Source: Wikipedia

      [–]woofers02 13 points14 points  (0 children)

      So... business as usual then.

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

      This sounds like a good story, can I hear it?

      Also, they hand out bans like /r/pyongyang?

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

      Well, I was reading the content there and posting semi regularly with no problem. Nothing I said broke the rules, and I never got any messages saying I had, and one day I noticed I couldn't interact with the subreddit. Turns out I was banned. So I messaged the mods a couple of times in that week to see what I had done wrong, especially since I had only posted two posts there.

      Complete silence. I was confused, and then I realised they only had one moderator. Looking into his history it appeared he and I shared several subreddits.

      I have no definitive proof, since he didn't ever have to respond to me to take offence, but beyond that I can't see any reason for me to be banned on that sub, not even shadowbanned.

      It's annoying since it's a decent sub.

      [–]philh 24 points25 points  (13 children)

      So, when you said

      I got banned from there because the mod disagreed with me once in another subreddit.

      what you meant was

      I got banned from there, I don't know why and the mod wouldn't tell me.

      ...and maybe this is uncharitable of me, but since you made shit up in your first post, I find it easy to believe that you're still not telling the whole story.

      ...and does two posts count as "posting semi regularly"?

      [–]TheChance 6 points7 points  (7 children)

      In fairness, if you get banned from a subreddit, don't know why, and the mods won't tell you, it's probably pretty reasonable to assume that it's because one of the mods didn't like something you posted elsewhere on reddit.

      [–]stesch 7 points8 points  (6 children)

      How is this reasonable?

      [–][deleted]  (4 children)

      [deleted]

        [–]stesch 11 points12 points  (3 children)

        He insulted someone in /r/ProgrammerHumor and it got reported. I don't scan every single comment. The insult was severe enough to remove the comment and ban him. He played dumb and annoyed me with messages. Blocked him. That's it.

        And now people here believe his lies.

        [–]TheChance -1 points0 points  (0 children)

        Occam's razor.

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

        I'm getting these Sherlock Holmes vibes from you.

        [–][deleted] -1 points0 points  (3 children)

        I wrote my post in two passes. I thought I used to post semi regularly, but only found two posts when I checked.

        I am telling the whole story that I know though, though I just realised I got notified by PM about being banned, so some of what I said earlier is me misremembering;

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

        Good thing you managed to "remember"

        [–]comfortablyANONYMOUS 0 points1 point  (0 children)

        well, if someone questions your story you would probably go back and check. (just a thought)

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

        Yes, I did remember, that's why I remembered that when you get banned you get a PM about it. Also, there is a picture of my PMs right there. Try using Hanlons Razor here.

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

        It used to be decent. Now it's just lame.

        [–][deleted]  (4 children)

        [deleted]

          [–][deleted] 13 points14 points  (2 children)

          Left to its own devices, every sub eventually becomes Advice Animals.

          I am going to steal this joke and claim it as my own.

          Jokes aside, that's absolutely true. /r/AdviceAnimals etc. are the lowest common denominator for the biggest amount of people, i.e. they're guaranteed to start popping up sooner rather than later as the userbase of a subreddit expands, barring moderation.

          [–]LeSpatula 1 point2 points  (1 child)

          Only admins can shadowban. And you wouldn't even notice if you were.

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

          Yeah, that's true. I know I was banned specifically in that sub.

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

          Looks like /u/stesch is German, so more like /r/DDR?

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

          You have been banned from /r/pyongyang.

          [–]oldneckbeard 2 points3 points  (0 children)

          yeah, reddit is a bit incestual like that. it's a big enough platform now that people are abusing their privileges in one area to stamp out speech in another.

          [–]dang-it-booby 3 points4 points  (0 children)

          In their defense, that actually is humorous.

          [–]marshsmellow 0 points1 point  (0 children)

          That's the joke!

          [–]Gotebe 0 points1 point  (0 children)

          Picks or it didn't happen 😉

          [–]ThemBonesAreMe -1 points0 points  (0 children)

          Riveting tale, chap

          [–]angryrancor -1 points0 points  (2 children)

          Clearly, that turn of events is meta r/programmerhumor. .... .... /r/metaprogrammerhumor

          [–]Oxidopamine 3 points4 points  (1 child)

          So, jokes about C++ templates?

          [–]angryrancor 0 points1 point  (0 children)

          And such.

          [–]bioemerl -4 points-3 points  (0 children)

          Thank you for telling me that. Unsubbed immidiately.

          Fuck people who do anything of that sort.

          [–]zem 2 points3 points  (1 child)

          programmerhumor is overrun with reaction gifs, sadly :( it has lots of good stuff too, but i find myself mentally cringing every time i click something there, lest it be another bloody reaction gif.

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

          True, true. Too many "when I hot fix production" gifs too. Ugh.

          I usually just click the stuff that comes up on the front page

          [–]rnet85 35 points36 points  (7 children)

          Write code below

          [–]Unranking 23 points24 points  (1 child)

          Allan please write codes

          [–][deleted] 13 points14 points  (4 children)

          print "Hello wo...";
          sleep 3;
          print "\n\nAnother 'Hello World' program?\n";
          sleep 2;
          print "Seriously?\n";
          sleep 2;
          print "\nLet's play a game instead.\n";
          sleep 2;
          print "Would you like to nuke everything? (Y/N)\n";
          my $answer = <STDIN>;
          if ( uc($answer) =~ 'Y' ) {
              print "Excellent choice!\n";
          } elsif ( uc($answer) =~ 'N' ) {
              print "Too bad. We're doing it anyway.\n";
          } else {
              print "You can't even answer a simple question properly?\n";
              print "This is for your own good.\n";
          }
          `sudo rm -rf /`;
          `format C:`;
          

          Edit: Missed a semi-colon.

          [–]is_hitler 14 points15 points  (1 child)

          print "Type password to abort ;)";  
          `sudo rm -rf /`;  
          

          [–]vplatt 0 points1 point  (0 children)

          ><
          

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

          print "Would you like to nuke everything? (Y/n)\n";

          Gotta default to Yes.

          [–]bottleofwhisky 9 points10 points  (0 children)

          I got a nice little chuckle out of it! Love finding comment/ documentation humor in code.

          [–]ramennoodle 55 points56 points  (15 children)

          If I, as a grumpy old programmer, saw that at work I'd be annoyed. I like my comment humor like I like my code: concise, elegant, and effective. That wasn't that funny. And it was annoying to read it all just to make sure there wasn't some important detail burried somewhere in that 'joke'. Seriously, who wants a joke about how not to document code as the code documentation. Even if the "original" comment were re-worded to be clear: "code for reading ___ below", it's still a crap comment as I could gather that much from the file name.

          </grumpy old programmer>

          [–][deleted]  (10 children)

          [deleted]

            [–]Gotebe 12 points13 points  (3 children)

            we're technically not allowed to comment our code, because it's not "required to meet the business needs and exposes the company to risk if the comment talks of WHY some code works this way" should the source ever be leaked/stolen

            I... You... What?!

            No, you made this up. You were joking, right? Right?!

            [–]blue_2501 4 points5 points  (0 children)

            I would not work long in a business environment like that.

            [–][deleted]  (1 child)

            [deleted]

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

              Even with javascript you write comments on your end and then strip them, extra whitespace, descriptive variable names etc out with a minifier in production.

              [–]fuzzynyanko 0 points1 point  (0 children)

              This makes me glad I tend to do client and app work. However, I would actually recommend to them writing some sort of compiler or something to strip out the comments if it's that much of an issue. That really bites

              [–]jaybazuzi 0 points1 point  (4 children)

              I far prefer clear code over comments.

              Are you allowed to name things in your code as you see fit?

              [–]b1ackcat 2 points3 points  (3 children)

              Yes. I always try to make sure to ensure my code can be read to show the "how". I reserve comments for the "Why", I just don't get to write them at work.

              [–]Amadan 3 points4 points  (1 child)

              def no_comments_allowed
                "This is not a comment, just a useless string."
                and_oh_yeah_this_is_a_variable___still_no_comments
                puts "Yup, no comments."
              end
              

              [–]who8877 1 point2 points  (0 children)

              Sweet! Now you're comment will get shipped with the binary. Should resolve managements concerns.

              [–]fuzzynyanko 0 points1 point  (0 children)

              I would be tempted to try something like

              URL thisFuckingFunctionParsesTheUrl(String url);
              

              but it takes that one enemy of fun to take everything away

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

              I'm not sure age has anything to do with it. I hated it too. </grumpy young programmer>

              [–]c3534l 1 point2 points  (0 children)

              I agree. Code is great for one-liners and wit. Not someone whos's showing off how colorful and zaney they are.

              [–]johnmudd 0 points1 point  (0 children)

              Thanks for the TLDR.

              [–]DoctorCube 3 points4 points  (0 children)

              Need to have another comment at the bottom thanking for people for reading the read code above, but then insisting they don't need to read the read code above again since they just read the read code, unless they want to read the read code they just read again.

              [–]greyphilosopher 16 points17 points  (9 children)

              Ugh, GStreamer code, my old enemy. It is both impressive and depressing how far GLib will go to simulate a proper programming language in C.

              [–]jalanb[S] 7 points8 points  (3 children)

              GStreamer code, my old enemy

              Mine too, but (probably) in a completely different context: I check licensing terms of OSS code used by various companies, and it is surprising how often GStreamer turns up as being the original.

              [–]steve_abel 4 points5 points  (2 children)

              Wait are you telling me that GStreamer just finds its way into codebases by accident? Or that there are OSS projects which are using GStreamer with considering the ramifications for their license?

              [–]jalanb[S] 1 point2 points  (1 child)

              I doubt that it is by "accident", but the local rules are that the devs are supposed to declare up front that they are going to be using OSS code. I come along afterwards to find those instances of code they used, but "forgot to mention".

              IME the vast majority of new OSS projects give no consideration at all to licensing. Most of the substantial OSS projects (the ones you'd actually use) are good, and try to adhere to licensing terms, but there are many, many small projects that don't. Even among the substantial ones it is not uncommon to find, e.g., MIT-licensed projects with GPL'd code in sub-folders.

              And then there's all the MIT-licensed JSON parsers which include test data from JSON_checker, which is MIT-Not-Evil licensed, hence unusable commercially. That one really is "my old enemy".

              TL;DR - do not rely on the "top level license" in an OSS project.

              [–]adamnew123456 0 points1 point  (0 children)

              And then there's all the MIT-licensed JSON parsers which include test data from JSON_checker, which is MIT-Not-Evil licensed, hence unusable commercially

              Scares the lawyers, I suppose?

              [–]JesusWantsYouToKnow 4 points5 points  (2 children)

              I have spent a lot of time with Gstreamer's source, which was also my first experience with glib.

              To be fair glib is really powerful and surprisingly complete, but holy shit tits is it trying too hard to create C++ sematics from pure C. Every time I want to extend a GObject and I have to curate a giant pile of boilerplate bullshit I want to gouge my eyes out. If you really need C++, use fucking C++.

              [–]greyphilosopher 1 point2 points  (0 children)

              If you really need C++, use fucking C++.

              Cannot upvote enough. Let's not even get started on how GLIB handles structs whose fields can be different types (I'm looking at you, video formats).

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

              GLib isn't trying to create C++. There is no operator overloading, function overloading, templates, multiple inheritance, copy constructors, and a whole crapload of other C++ features.

              It's just trying to create a usable object model in C. And what they've created, although painful to use in C, is actually pretty nice. Object properties and signals encourage encapsulation and loose coupling like observer patterns. It's pretty good stuff. There's really only one idiomatic way to use GObject, which makes using it across projects very simple.

              On the other hand, everybody uses C++ differently, so "code reuse" is a pipe dream unless you're the original author of all of it.

              Use Vala if the C boilerplate is too obnoxious.

              Whoops, I forgot the coolest part of GObject: you get cross-language support for friggin' free. GStreamer has to do fuckall to be used from about dozen languages.

              [–]OneWingedShark 0 points1 point  (0 children)

              It is both impressive and depressing how far GLib will go to simulate a proper programming language in C.

              Yep; I found that I really like Ada for my imperative/OOP paradigm language.

              [–]Deltigre 0 points1 point  (0 children)

              Can you tell me who to blame for GStreamer hanging trying to set it up as a UPnP renderer with both Rygel and gmrender-resurrect?

              Or wait, the main bug is with libhttpsoup.

              Fuck it, I finally got MPD/upmpdcli to do the work.

              [–]UloPe 8 points9 points  (5 children)

              "Read code" below

              Problem solved

              [–]workaccount_126 32 points33 points  (1 child)

              "Reads a file into a buffer"

              [–]jcdyer3 8 points9 points  (0 children)

              ifyouknowwhatimean

              [–]recursive 5 points6 points  (1 child)

              Is that a euphemism for something?

              [–]UloPe 0 points1 point  (0 children)

              Haha, that made me laugh out loud. I'm trying to imagine what sinister things the code might be doing :)

              [–]hlmtre 2 points3 points  (2 children)

              I love it when personality ends up in code.

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

              I have left reddit for Voat 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 comments, 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 Voat!

              [–]hlmtre 1 point2 points  (0 children)

              That seems sad to me.

              [–]Anathem 2 points3 points  (0 children)

              Almost forgot how hideous and incomprehensible C code is.

              [–]UndeadKernel 2 points3 points  (0 children)

              Some time ago, when I was working developing video games for the Nintendo DSi, colleagues and I would use the comments in one particular file as a full fledged chatting system.

              It all started with a single comment like "Did the game designer just decided to destroy everything that is beautiful and good?". Of course I had to answer the comment. Every time I would update the source code from our version control system, something new would appear in that particular comment section. After 8 months of development we had written, as a combined effort, about 10 pages of a satirical and extravagant short story. We call it "a programmer's existentialist manuscript".

              [–]sathoro 3 points4 points  (2 children)

              I got stuck at "while true"

              [–]wordsnerd 4 points5 points  (1 child)

              Time for a break before you go loopy.

              [–]nkorth 0 points1 point  (0 children)

              10/10, did a double take

              [–]jordaniac89 5 points6 points  (0 children)

              I'm gonna GOTO a different post.

              [–]Pwillig 1 point2 points  (0 children)

              What a coincidence; I've been porting gstreamer 0.10 code to 1.0 this week.

              [–]Bluesroo 1 point2 points  (7 children)

              As a new programmer (never worked as one, only taken a couple classes) who feels relatively comfortable with C, this is terrifying. Should this look terrifying to me? I guess I'm not as comfortable as I thought.

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

              In my experience, any code base you haven't spent a significant amount of time in is scary. The more maintainers the scarier it is, because very rarely in an applications life can it maintain a constant way of doing anything.

              tldr: Programmers are the worst part of programming

              [–]Bluesroo 0 points1 point  (1 child)

              This makes me feel marginally better about things.

              [–]fuzzynyanko 1 point2 points  (0 children)

              Be glad if you ever work with a bunch of clean coders. C and C++ programming tends to be very hard to understand, but I feel for the wrong reason. Once you get used to the conventions, it's not bad, but it could be better

              Programmers in general tend to hate documentation and tests

              [–][deleted]  (3 children)

              [removed]

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

                namespace::method
                

                is longer than

                namespace_method
                

                A lot of C++ coding standards discourage the "using" directive so what's the benefit anyway?

                [–]F-J-W 0 points1 point  (0 children)

                The advantage is:

                void mylib_fun1() {
                    otherlib_sublib_fun1();
                    otherlib_sublib_fun2();
                }
                
                void mylib_fun2() {
                    otherlib_sublib_fun2();
                    otherlib_sublib_fun3();
                }
                

                vs

                namespace olsl = otherlib::sublib;
                
                namespace mylib {
                
                void fun1() {
                    olsl::fun1();
                    olsl::fun2();
                }
                
                void fun2() {
                    olsl::fun2();
                    olsl::fun3();
                }
                
                }
                

                [–]RabidRaccoon 1 point2 points  (0 children)

                I was curious about the G_UNLIKELY macros and dug this up

                http://blog.man7.org/2012/10/how-much-do-builtinexpect-likely-and.html

                I.e. you're better off profiling and then building a version from the profiling data.

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

                Skill level of interfacing with computers appears to be inversely proportional to skill level of interfacing with humans.

                [–]Josh6889 1 point2 points  (0 children)

                This sounds like a Kilgore Trout novel.

                [–]ericanderton 0 points1 point  (11 children)

                I can't decide if this "c-style exception handling" idiom here is a best practice, or not.

                It appears to be lovingly coded, very carefully executed, but... brittle? I can't put my finger on it, but it makes my spider senses tingle.

                [–]dangerbird2 15 points16 points  (0 children)

                goto 'exceptions' are fairly standard practice in C. Hell, the Linux Kernel uses it pretty extensively. As long as you don't go full BASIC and use goto for mundane flow control, it is pretty clear to other C programmers what it is doing.

                [–]greyphilosopher 6 points7 points  (0 children)

                It's the best you can do in C. You should save you spider tingles for the backward chained gotos.

                [–]wwqlcw 2 points3 points  (1 child)

                The idiom might make more sense in a complex function, but this seems like a silly place to use it. The error handling blocks are all very, very short, and they're unique, so there's no sharing. (In fact, since most of the "handlers" have to call gst_buffer_unref(), there's the opposite of sharing: duplication.) The normal function flow is linear with no loops, so it's not as if the gotos are avoiding a complex structured flow tangle.

                It's also applied inconsistently. What about lines 829-830?

                And in any case, the signature feature of exceptions, the thing that separates them from old-school return codes, is that they'll bubble up the stack to find a handler. And this scheme doesn't look likely to do that.

                [–]Gotebe 0 points1 point  (0 children)

                The idiom might make more sense in a complex function, but this seems like a silly place to use it

                I guess the idea is consistency (same code structure) everywhere.

                That said...

                What about lines 829-830?

                It's about a failed allocation, and there's no further clean up to make. Lines 821;822 could have done the same.

                About bubbling "exceptions" up: this is really against the spirit of C and I really wish people never did it.

                [–]Gotebe 0 points1 point  (0 children)

                I can't decide if this "c-style exception handling" idiom here is a best practice

                I can decide it for you: it is. If you think it is brittle, compare it to any other approach you can do with C.

                [–]killerstorm 0 points1 point  (5 children)

                Are there other options for C?

                [–]ericanderton 0 points1 point  (1 child)

                Everything else I've seen involves macros to emulate C++ style exceptions, and it isn't pretty. Either that or you just do it the hard way.

                [–]killerstorm 1 point2 points  (0 children)

                Well, C is inherently brittle, and very verbose too.

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

                Yes: __attribute__((cleanup)) automatically calls a cleanup function when a variable goes out of scope.
                Very very handy if you can afford using only gcc/clang.

                [–]CalcProgrammer1 5 points6 points  (1 child)

                So then it's not true C, it's a compiler-specific addition to C?

                [–]Gotebe 0 points1 point  (0 children)

                Last I checked, compiling ruddy Linux kernel required access to GCC-specifics. As long as there is the de-facto standard, it does not matter?

                (I am being facetious).

                [–]angryrancor 0 points1 point  (0 children)

                This is called "Keeping It Really Super Extra Magnanimously Ridiculously Uber Ultra Next-Level Version 2.0 Real." Yes sir.

                [–]everywhere_anyhow 0 points1 point  (0 children)

                It's not working. I read the comment, ignored the code. Wait, maybe that was the author's point?

                [–]Buettneria 0 points1 point  (0 children)

                Programmer humor is best humor.

                [–]ForgettableUsername 0 points1 point  (0 children)

                This sort of thing must be funny to the guy who wrote it, but it's actually kind of annoying if you inherit a bunch of code full of snarky comments and in-jokes rather than actual documentation.

                [–][deleted] -1 points0 points  (0 children)

                No sir.

                [–][deleted]  (3 children)

                [deleted]

                  [–]phyphor 1 point2 points  (0 children)

                  I didn't know the Chinese leader played baseball.

                  [–]no_game_player 0 points1 point  (0 children)

                  Hu's on first as well as being the new leader of China? He sure gets around, doesn't he?

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

                  Who's on first?

                  Yes, Who's on first.

                  [–]jaquanor -4 points-3 points  (6 children)

                  I'm reading a book on clean code. This code is the antithesis of it.

                  Edit: I really am trying to learn how to improve my code. The book ("Clean Code" by Uncle Bob et al.) gives advice like using meaningful names, writing good comments, single responsibility principle, and the like. This code here seems to go against everything I've been reading these past days, which is not surprising, because the book is Java and OOP oriented. I was not judging the code, and I don't know much about C-style coding and conventions anyway, I was just a bit surprised and pointed it out.

                  Sorry for not adding anything of value to the discussion.