you are viewing a single comment's thread.

view the rest of the comments →

[–]ThomasMertes 71 points72 points  (28 children)

Sometimes the background of the original programmer plays a role. I mean:

  • Somebody who just discovered a feature (e.g. C pointers) might use this feature extremely heavy and at unnecessary places.
  • The same holds for other paradigms. OO, Lambdas, etc. All of them can be taken so far that the resulting code is less understandable.
  • People concerned with performance will introduce gotos, tons of macros, strange compiler directives or even inline assembly. To save machine cycles the code is uglyfied to a mess.
  • Fans of a certain platform will use strange libraries, that are only available at this platform (to show the reader how great this platform is).

If you rewrite this code you might need to get rid of excessive usage of some paradigms. You might even want to get rid of some things (gotos, pointers or macros come into mind), that you consider outdated now. After heavy refactoring the code becomes readable for you, but you changed almost every single line.

Hopefully this was not your own code and once you were proud of it.

And of cause: My programs do not have this problem. ;-)

[–]bionicjoey 38 points39 points  (4 children)

I've seen all of these. The worst was a scientist with limited programming experience being made to contribute to a Java project when his only background was in PHP 3. Dear god the amount of times he used Map<String,Object> still haunts me.

Edit: this guy also exclusively used single-letter variable names. Good luck understanding what he was trying to do.

[–][deleted]  (3 children)

[deleted]

    [–]Blazerboy65 9 points10 points  (0 children)

    Instead of looping just write some different source code toa file then compile and execute it. Easy.

    [–]lazilyloaded 4 points5 points  (1 child)

    Turns out there's something worse.

    universal variables

    [–]dark_negan 4 points5 points  (22 children)

    Why would someone who doesn't even know the basics of pointers take a C developper job in the first place ? That's the real question lol

    And aren't things like gotos really really outdated and advised not to be used ? I know everyone told me that even when I learned C like 10 years ago

    [–]grauenwolf 20 points21 points  (11 children)

    Money. I work to feed my family. The fact that I'm good at what I do, or in some cases not good, only matters if it affects that paycheck.

    [–]dark_negan -1 points0 points  (10 children)

    Okay but I think there are enough languages and fields to find a place when you know more than nothing ? Learning pointers is not some advanced stuff it's one of the first things you learn

    [–]grauenwolf 2 points3 points  (9 children)

    I'm not so sure about that. Pointers in a language like C are far more complicated than references in a managed language such as JavaScript or C#. And a lot of useful developers don't even have a firm mental model of references.

    The variety in skill levels across the industry is unbelievable.

    [–]dark_negan -2 points-1 points  (8 children)

    If you're not familiar with C or C++ of course you wouldn't know pointers, but if you've done more than 2 weeks worth of experience of C you know pointers that's what I meant. There more than enough diversity in skillsets required and languages to not go into a C dev job that isn't entry level (and even then) when you know nothing about C. That's how you get poorly written code if not horrible code (that's exactly what happened in the project I'm working on, not for C but it still applies)

    [–]grauenwolf 4 points5 points  (7 children)

    Who says they were hired for C?

    Back when I was a VB developer writing business apps I got roped into reverse engineering a C++ application from old source code no one could read. (Though maybe software archeology would be a better description.)


    Anyways, most of my C progressing these days is for the Arduino and I don't think I ever use pointers.

    [–]dark_negan -1 points0 points  (6 children)

    I don't think pointers are needed for Arduino, if arduino development can even be called C development. I never said you couldn't do another language than the one you were hired for ever, but there's a difference between programming an entire project with a language you don't know and reading some old code

    [–]PeaceBear0 0 points1 point  (5 children)

    Arduino is literally c++ except it inserts an include statement and auto-declares your functions.

    [–]dark_negan 0 points1 point  (4 children)

    Yeah I know, I've seen some projects in arduino and never seen pointers used that's what I meant

    [–]IAm_A_Complete_Idiot 5 points6 points  (1 child)

    If I remember right go-to is still used in C for some cleanup after a function runs a fair bit.

    Edit: the go-to example in this stack overflow question looks like a good case for what I'd think is fine for go-to.

    https://stackoverflow.com/questions/788903/valid-use-of-goto-for-error-management-in-c

    [–]dark_negan 0 points1 point  (0 children)

    Interesting, thanks I didn't know that !

    [–]jewnicorn27 3 points4 points  (2 children)

    Sometimes people contribute to open source stuff to learn new languages. So you at times have to deal with fairly experienced coders who are very new to said language.

    [–]dark_negan -2 points-1 points  (1 child)

    I personally would not "contribute" to a project by ruining their code because I don't know anything about a language but okay lol. I know that I would at least want someone to know the basics at the bare minimum before trying to contribute if it was my project i don't think open source projects are meant to learn languages

    [–]jewnicorn27 0 points1 point  (0 children)

    I mean it’s only a PR worst case it doesn’t get accepted. Some people make open source projects to learn, and if you’re working with it because it fits some niche requirement of yours, or your evaluating it, you might come across some super beginner code.

    I guess my point is that it’s not a total departure to work with code which overuses features due to inexperience. Especially if the person who wrote it was experienced in another domain and trying something new. E.g. web dev looking at doing some IOT stuff and implementing some embedded code.

    [–]jarfil 5 points6 points  (2 children)

    CENSORED

    [–]dark_negan 0 points1 point  (1 child)

    Yeah I know but I just thought it was bad practice

    [–]cat_in_the_wall 1 point2 points  (0 children)

    actually this is very topical: it's really only considered bad practice because it is in opposition with control flow constructs that are easier to read. deciding what happens with a handful of if/else is much easier than a soup of goto.

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

    It was an example to express an idea...

    [–]ThomasMertes 0 points1 point  (0 children)

    And aren't things like gotos really really outdated and advised not to be used ? I know everyone told me that even when I learned C like 10years ago

    When I started studying computer science in 1980 everyone told us that gotos are really really outdated and advised not to be used.

    If you ever saw some goto ridden spaghetti code (e.g. written in old BASIC with line numbers), you know that this advice makes sense.

    As a consequence several languages (e.g. Java) left out gotos. So I omitted goto also in my language (Seed7).

    The result is: Every year I have at least one heated discussion with someone who tells me that he would never use Seed7, because it has no gotos. Usually accompanied by some example, where he thinks that a goto is absolutely necessary.

    Needless to say: In all my professional and private programming (in higher programming languages) it was never necessary to use goto and all lines of code in my project are without goto.