123
johnDoe
8y

!rant: Wondering how the hell you even graduated.

Comments
  • 27
    Let's be honest here. We've all written some nasty code Like this at least once when learning to program.
    Looking back on some of my old code and wondering what the hell I was thinking.
  • 30
    Man, what about 102?¿
  • 12
    @asgs ¯\_(ツ)_/¯ I guess he gave up.
    Could have done this (even more cancerous):

    Bool go = true;
    Bool wasEven = true;
    Int i = 2;
    Int ticker = 0;
    While(go){
    if(number == i){
    Console.writeline("your number
    Was even!");
    wasEven = false;
    go = false;
    }
    ticker++;
    i++;
    if(ticker >= 100000){
    Console.WriteLine("I give up");
    go = false;
    }
    }
    If(wasEven){
    Console.WriteLine("Your number
    Was odd!);
    }
  • 8
    @nicnaknic god please stop it hurts my eyes
  • 2
    @tisaconundrum then you learn about mod and think.... "Huh"
  • 5
    The sad thing is I found code similar to the above in production. Generated by a code generator the dev built because he thought he was smart to automate his work.
    As a side note: The code generator generated class names with more that 255 chars which made them a tad difficult to delete on Windows machines.
  • 0
    Jeez lmao
  • 2
    A fond memory of mine learning code was during my CS250 class, I wrote this monstrosity of a program to make a board game for my final. All prior assignments were around 100 lines of code for a solution.

    My solution for the final was 15k lines of code.

    Of that, the AI was a single function that was 9k lines of code. It also looped over itself roughly 32 lines per move :')
  • 1
    @aquaman the time before you learn how to properly implement class structures and effective method calling. Was your program terminal based? Or did you go with a UI?
  • 1
    @nicnaknic it was a c++ console program, I was tasked with making Halatafl with a rudimentary AI. I did utilize classes (poorly) but my tragically bad design decision was storing the board as a single dimensional array. Since the board is shaped as a cross, I had the delusional thought it was a witty way to avoid nullchecking in the corners. Little did I know that the indexes would no longer align, and that I would have to hard code the AI for all 33 board positions.
  • 1
    @nicnaknic I think even if you're learning that's some pretty bad code IMO.
  • 0
    @rallport most definitely. One Google search and you would have saved a hell lot of time
  • 0
    It's so ugly it's kind of... beautiful?
  • 5
    I remember one early lesson had me find out which of two numbers was smaller.

    My solution was to subtract one from the other, and check if the result was positive or negative (or zero).

    When I think of that, I wonder how I ever got not only a degree, but a job.
  • 1
    @UrsidaeGames That's how it's actually done in some assembly languages.
  • 1
    That is commitment.
  • 0
    @Grumpy Oh, really? That's really cool! I assume you just check the sign bit of the result?
  • 0
    @UrsidaeGames There are flags that are affected by the last arithmetic operation, so there's a negative flag and a zero flag.

    It's a long time since I did any assembly stuff (because hardware is so much faster these days), but having done it gives you nice insights.
  • 0
    @Grumpy Ah, okay. I've seen some Project Euler solutions written in x86 which have piqued my interest in learning assembler.
  • 0
    So a challenge: the most beautiful solution! Go!
  • 2
    @antons
    If(num % 2 == 0){
    Console.WriteLine("your number was even!");
    } Else{
    Console.WriteLine("your number was odd!");
    }
    Easy enough
  • 1
    When the !rant is a rant.
  • 0
    @peterbetos how is it a rant?
  • 1
    @nicnaknic in last 'if' condition it should be
    if(!wasEven)
  • 0
    @playmast3r that's the better way of doing it yes. How ever I'm making fun of bad programming techniques. Also I messed up, the i++; should be i+= 2; or the sloppy way. i = i + 2;
  • 7
    @nicnaknic inline with ternary:
    Console.WriteLine("Your number was " + (num % 2 == 0 ? "even!" : "odd!"));
  • 0
    @gaben good one! I forgot about this method
  • 1
    @gaben God damn beat me to it..
  • 0
    Anyone seen my_first_calculator.py? It's on GitHub.
  • 0
    Explained to my gf what modulo (%) is en why this way was bad practice by using a manual example

    Its like writing a manual for a microwave naming every animal that you cant put it in.
    Instead of using one line saying,no animals
  • 0
    def even (number):
    return 0 == number % 2;

    bloody hell... This is a python one liner...
  • 0
    @antons couldn't resist necroposting. JS:
    console.log("The number is " + ["even", "odd"][userNumber&1] + "!");
  • 1
    @siljamicke havent seen that before, dont you mean %2? Instead of &1
  • 1
    @antons nope not really. A not so clever interpreter might actually do a division for that modulus operation, whereas the bitwise and operation is dirt cheap!
  • 1
    @antons to clarify a bit. Anding with 1 will give a number which will be either 0 or 1, coincidentally 0 when the number is even, and 1 when the number is odd. This then is taken as the index into the string array.
  • 1
    @siljamicke would make more sense to not use an array for this to avoid unnecessary memory allocation, no?
  • 0
    @gaben I'm not very proficient in JavaScript so maybe you're right in that there is a penalty for instantiating an array. But for amusement purposes I went for a oneliner without any if statements.
  • 0
    @gaben or maybe I didn't get how you meant. How would you have done it?
  • 1
    @siljamicke
    return num&1 == 0 ? "Even" : "Odd";
    if JS even has ternary operators. I don't use JS, so I'm not sure.
  • 1
    @gaben ah, but that is a function call! Those aren't so cheap either, are they? But ternary exists, right? Surely they must!
  • 1
    @siljamicke fair enough. Guess it would largely come down to whether the language is GC or not.
  • 1
    @gaben given that my array will be referenced INTMAX times, I guess the cache hits will be okay, and the array allocation will pay off 😋
    I'll put my money on the array over the function, GC or no GC. But then again, I'm a lousy gambler.
  • 1
    @gaben actually I was clearly wrong. Of course it is not called more than once occasionally. My bad, and I will mysteriously remove my bet from the table.
Add Comment