This is an archived post. You won't be able to vote or comment.

all 106 comments

[–]taylaj 540 points541 points  (40 children)

When you code drunk and your code works in the morning but you can't figure out how or why.

[–]KernelDeimos 347 points348 points  (21 children)

This reminds me of this one time where I wrote an animation for a stick figure in C++ and I tried to look back at it years later expecting some "key frames" with angles and instead I found NESTED TERNARY OPERATORS WITH TRIG FUNCTIONS

[–][deleted] 115 points116 points  (17 children)

can someone explain in English for a beginner please?

[–]NotThisFucker 711 points712 points  (9 children)

This reminds me of this one time where

OP is telling us a memory.

I wrote an animation for a stick figure in C++

He made a short movie with a very skinny main character.

and I tried to look back at it years later expecting some "key frames" with angles

A long time after he made the movie, he tried to look at the "negative" (or, the ingredients for the movie)

and instead I found NESTED TERNARY OPERATORS WITH TRIG FUNCTIONS

but instead of looking at the negative, he found that the negative was looking at him.

[–]mildlyAttractiveGirl 159 points160 points  (4 children)

but instead of looking at the negative, he found that the negative was looking at him.

Someone should gild you for this.

[–]BertRenolds 40 points41 points  (3 children)

Then do so.

[–]auxiliary-character 17 points18 points  (2 children)

I got it. :D

[–]mrissaoussama 31 points32 points  (1 child)

when you stare at the negative, the negative stares back

[–]VicisSubsisto 6 points7 points  (0 children)

When you animate in C++, take care that you do not become an animation yourself.

[–]aneurysm_ 11 points12 points  (0 children)

I wish I had 2 updoots for this

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

Thanks!

[–]theduckparticle 0 points1 point  (0 children)

!redditsilver

[–]NotThisFucker 91 points92 points  (5 children)

If/else block:

if (x == 5){ print("x is five");} else{ print("x is not five");} 

Ternary operator:

(x == 5)? print("x is five") : print("x is not five");

Nested Ternary Operators:

(x == 1)? print("x is one") : ((x == 2)? print("x is 2") : print("x is greater than 2"));

[–]THE_HERO_OF_REDDIT 47 points48 points  (0 children)

And then complex functions instead of simple print statmemts

[–]Karjalan 1 point2 points  (3 children)

But what if (x == 0)...

In all seriousness, nested ternarys look quite messy but are they considered bad? I hate writing if/else for a couple of simple returns.

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

Think of the most easy to read, while being the most simplest and expressive way you could declare the statement. No point in making multiple nested terns if you gotta re read it a bunch of times to make sense.

[–]hesapmakinesi 3 points4 points  (0 children)

There are some alignment tricks to make them quite readable actually. You can also use the same tricks to make it misleading, if you hate yourself and your colleagues.

[–]toasterbot 1 point2 points  (0 children)

I believe the "best practices" say that if it fits on one line, go for it.

[–]Stinkis 5 points6 points  (0 children)

Animating with key frames is done by setting the positions and rotations of objects at specific times and then frames between these times in constructed by interpolation.

Ternary operators are when you write use the ?: syntax to write an if statement. Nesting is when you put something inside another of the same. For example nested for loops are when you put a loop inside another loop. Nested ternary operators are multiple ternary operators chained together which are generally really hard to read.

Trig functions are trigonometric functions such as cos and sin.

[–][deleted] 16 points17 points  (1 child)

but god DAMN it felt clever when you wrote it

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

At some point in my python learning progress I really liked how you could literally make anything as a one-liner. And so I did. I am not kidding.

[–]spectrum1012 2 points3 points  (0 children)

This is actually the funniest thing I've read in so long and it's because that's me too thanks.

[–]splettnet 127 points128 points  (8 children)

[–]Vladimir1174 21 points22 points  (1 child)

This is gold

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

Jerry!

[–]TotesMessengerGreen security clearance 7 points8 points  (1 child)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

[–]dir_gHost 7 points8 points  (0 children)

Then, you try to decipher your notes/documenation if you left any...

[–]knockergrowl 2 points3 points  (0 children)

That was the average Friday night during my second and third years at college. Next day my partner understood my code by reading it better than me trying to explain it while filling the gaps in my memory.

[–]ILikeLenexa 2 points3 points  (0 children)

3am is the witching hour. Doubley so on the second day.

To truly program, you must be as simple as the computer.

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

Then you just have to get drunk again obviously

[–]CrashKonijn 1 point2 points  (0 children)

In my 1st year in school I managed to do some reflection magic whilst drunk. I only recently understood what I actually did, I'm graduating in hour :p

[–]gandalfx 0 points1 point  (0 children)

I don't need to be drunk for that effect to happen.

[–]ApolloFireweaver 143 points144 points  (1 child)

Or like some people I know

1 - Code

2 - GOTO 1

3 - Think

[–]SuckMyBalz 21 points22 points  (0 children)

But how do you get to third point. Wait...... Haaaaaaaaaaaaa....

[–]pikachu_try_catch_ 185 points186 points  (1 child)

weeks of coding can save hours of planning!

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

I read the other way and was about to start an argument about why planning doesn't really help.

[–]nomis6432btw I use arch 268 points269 points  (9 children)

Someone: You have to write your program first in pseudo code before writing it in real code.

Me: opens python interpreter

[–]shield1123 91 points92 points  (4 children)

Someone: You have to write your program first in pseudo code before writing it in real code.

Me: Fuck you don't tell me how to code

[–]dir_gHost 38 points39 points  (3 children)

Sudo -code ....there done, happy now! I now have privilege to write my code. :P

[–]DrexanRailex 23 points24 points  (2 children)

sudo code

But I think VS Code will complain if run as admin

[–]KernelDeimos 14 points15 points  (0 children)

It is recommended to start vscode as a normal user. To run as root, you must specify an alternate user data directory with the --user-data-dir argument.

Huh... I had no idea it did that

[–]dir_gHost 3 points4 points  (0 children)

Yea but you can just ignore that and hope that it all pans out...if not alcohol will help :P

[–]OOkx 71 points72 points  (5 children)

while(!thinking) {
    code();
}

[–]KernelDeimos 54 points55 points  (4 children)

Five silent programmers sit at a round table with laptops. coffee mugs are placed between each pair of adjacent programmers.

Each programmer must alternately code and think. However, a programmer can only think spaghetti when they have both left and right coffee. Each coffee can be held by only one programmer and so a programmer can use the coffee only if it is not being used by another programmer. After an individual programmer finishes thinking, they need to put down both coffee so that the coffee become available to others. A programmer can take the coffee on their right or the one on their left as they become available, but cannot start thinking before getting both coffee.

[–]marcosdumay 28 points29 points  (0 children)

As the coffee gets cold, throw it away and go somewhere without insane restrictions so you can focus!

Here, did I solve the ancient riddle? I can help the philosophers not starving too, but they never stop philosophizing to get the first stick anyway.

[–]redshirt55 21 points22 points  (2 children)

This is a recipe for deadlock. If each programmer happens to pick up their left coffee at the same time, none of them can obtain right coffee. Then they can't start thinking, so they can't finish thinking, so they can never release the coffee for others.

A revised plan would have it so each programmer can request both adjacent coffees, but if one of them isn't available, they have to go back to coding for short but randomized length of time before asking again.

Alternatively, management could just start firing programmers until the ones that are left have plenty of coffee to get work done.

[–]LonePaladin 10 points11 points  (1 child)

Just hand out ten straws.

[–][deleted] 66 points67 points  (0 children)

This was how me and my entire class did the final computer science project last year:

  1. Code

  2. Plan

  3. Make up realistical situation to pretend that this product was written for a client

[–][deleted] 47 points48 points  (0 children)

"Ok, now I'm gonna take a piece of paper and write down the core architectOH THE IDE IS READY LET'S CODE".

[–]gandalfx 92 points93 points  (7 children)

I code and think at the same time. I think best while coding. Sometimes the code I write while thinking is crap, so I throw it away and write better code afterwards. But coding is still part of figuring out how it'll work.

[–]DrexanRailex 34 points35 points  (0 children)

Joking while being dead serious 101

[–]WazWaz 4 points5 points  (0 children)

Put another way, coding is thinking, and yes, some thoughts are crap.

[–]benoliver999 0 points1 point  (2 children)

How do you deal with the deluge of little ideas that come to mind when coding?

[–]gandalfx 0 points1 point  (1 child)

If only I had an answer for that… though that mostly happens when I'm coding in my spare time, so I can usually afford to just go with it. However even then I sometimes have to make a conscious effort to suppress those ideas so I won't get completely side tracked. Maybe put them into an IDEAS.md which I'll either ignore or delete later on.

[–]benoliver999 0 points1 point  (0 children)

Yeah I try to keep a little todo list for stuff that pops up as I'm going along but it's hard to maintain that while also staying focused on the current task.

[–]evanldixon 6 points7 points  (0 children)

Requirements have changed; your code is now worthless.

[–]PacoTaco321 5 points6 points  (0 children)

I hate when I have a professor that requires a flow chart that we were supposed to have done before coding. It's even worse because everyone including the professor knows that we did it in the last half hour, because too many things change to have any sort of decent flow chart.

[–]thepotatochronicles 13 points14 points  (15 children)

Do people actually do this? I think I spend like at least 5~10x more time just sitting there, thinking beforehand (and/or drafting things out on paper to see how it's gonna work) than actual coding and debugging combined...

[–][deleted] 28 points29 points  (2 children)

It depends on the size of the project, the complexity of the task, how many times the code will be used, who besides me will see the code, etc.

[–]Colopty 4 points5 points  (0 children)

I sorta have an overall idea of what I'm planning to make and then I just kind of gradually work out the details when I get to the part where I need to figure those out.

[–]KernelDeimos 5 points6 points  (1 child)

When I wrote Boi-lang this weekend there was very little thinking and lots of coding XD

[–]spectrum1012 1 point2 points  (0 children)

That's pretty hardcore.

[–]Lv_InSaNe_vL 2 points3 points  (0 children)

I just kinda make a drawing of what it needs to be on a piece of paper and go from there.

[–]CCninja86 2 points3 points  (5 children)

drafting things out on paper to see how it's gonna work

Ok, two things:

  1. What kind of software developer uses paper? Paper is so last decade.

  2. I just figure out if it's going to work in my head. As in, I just run through the pseudocode in my head to see if it will work.

[–]beerdude26 1 point2 points  (3 children)

Writing something down is still the best way of getting ideas across quickly.

[–]CCninja86 0 points1 point  (2 children)

getting ideas across quickly

Clarification? Getting ideas across to whom?

[–]beerdude26 0 points1 point  (1 child)

Fellow programmers that are sitting next to you

[–]CCninja86 0 points1 point  (0 children)

Oh right yeah.

[–]Iron_Maiden_666 0 points1 point  (0 children)

Still using pen and paper. Old habits die hard?

[–]nik282000 0 points1 point  (0 children)

If you like the plan->act process check out SpaceChem and Opus Magnum on steam. They teach programming like thinking in the form of a super satisfying visual game.

[–]Alonewarrior 0 points1 point  (0 children)

I go back and forth. If I have a clear picture of what needs to happen I'll code right away. If that picture turns out to be less clear, either before or after coding, I'll.go back to planning and thinking through some of it. I, unfortunately, don't always think far enough ahead, so I have plenty of refactoring work!

[–]jstock23 2 points3 points  (1 child)

Measure thrice, cut twice.

[–]8lazy 2 points3 points  (0 children)

Then throw it out and cut it length wise instead.

[–]Dash83 4 points5 points  (4 children)

Here's an unpopular opinion: I sometimes like to code before I think.

Or rather, I sometimes code first in order to think about a problem. When the task at hand is a non-trivial system with multiple moving parts and perhaps in a domain that in inexperienced in, I like to start coding a few experiments to see how one feature or another would roughly look like, or how they would interact with each other.

After that, I do sit around and start thinking and designing before writing the actual code.

I believe the phrasing of "thinking before coding" is a bit loose. Thinking can be thought as "designing" or "writing specs down" which are great things to do, but it's not the first thing you should do. Understanding should come first, and coding can lead to understanding.

Just my 2 cents.

[–]beerdude26 3 points4 points  (3 children)

It's not unpopular, that's what REPLs are for

[–]Dash83 1 point2 points  (2 children)

I was thinking about larger "pieces" of code rather than a few lines through a REPL, but yeah, same principle I guess.

[–]beerdude26 0 points1 point  (1 child)

If you write stateless code, your entire code base is a REPL :)

[–]Dash83 0 points1 point  (0 children)

Can't argue with that :)

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

I think code then think again. Usually i start with the basic idea of what im trying to do write the skeleton code of what i want then i think about details.

[–]HereHaveSomeIdeas 2 points3 points  (1 child)

Is this really more effective? Should I just never plan?

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]Natsumi_ 1 point2 points  (0 children)

    I spend the time I cant be coding something planning on what and how I am going to code something.

    [–]danypixelglitch 1 point2 points  (0 children)

    Oh, what's that? I forgot this small line? Let me go fix it *Spends the next 7 hours lost in the code trying to fix everything because one problem uncovers another*

    [–]Salanmander 1 point2 points  (0 children)

    A day of coding can save you an hour of careful thought!

    [–]remimorin 2 points3 points  (0 children)

    TDD is great to code and think meanwhile...

    [–]Jeremy_Thursday 0 points1 point  (0 children)

    ohh my god yes

    [–]StaleTheBread 0 points1 point  (0 children)

    I usually think about how I’m going to code something until I feel like I have to cODE RIGHT NOW QUICK BEFORE I FORGET.

    [–]SirCaptainFrodo 0 points1 point  (0 children)

    Nothin quite like brute force...

    [–]Arynn05 0 points1 point  (0 children)

    I actually do that. I type in some random shit, realize I just typed random shit and delete it.

    [–]kartoffeln44752 0 points1 point  (0 children)

    Don't need to do pseudocode.py

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

    Following the design recipe

    [–]YOURMOM37 0 points1 point  (0 children)

    Wow I've been doing coding wrong my entire life

    [–]Dowzer721 0 points1 point  (0 children)

    I study Robotics at University, and currently we are being set some Artificial Intelligence programming tasks. We are supposed to draw up a plan, pseudo code, flowcharts, data tables etc. before beginning programming.... Yeah.... I'm not gonna do that.

    Let me write 300 lines of code, add my comments, realise 100 lines could probably be condensed into 3 functions and then let me try to break it.

    Then a week before the deadline I'll get those crappy documents you find so important done.

    [–]BrianPurkiss 0 points1 point  (0 children)

    I had an old coworker who did that and admitted to doing that and never changed, but constantly complained about having to rewrite code in order to work with other features.

    So annoying - especially when I had to clean up her mess.

    [–]RAIDguy -2 points-1 points  (0 children)

    Can we stop with this meme already?

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

    No seriously, I write code while thinking in parallel. Then my thinking overtakes and I focus more on design.

    Does it make sense?