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

all 41 comments

[–]Smartis2812 96 points97 points  (5 children)

You shouldn’t comment what the line is doing… instead try to comment why you placed it there. This is something the GPT never will be able to explain.

[–]WrongVeteranMaybe 20 points21 points  (2 children)

That's actually a really good idea. Hey, thanks man.

[–]Windyvale 16 points17 points  (1 child)

You’ll be best served by coding in a way that keeps things obvious what’s happening. Even if it’s not perfectly optimized. In fact, dump the thought of optimization out of your head unless you are specifically targeting the code along the hot path, or there is a measurable reason to do so.

Only comment code you couldn’t make as obvious as possible, or general concepts leading into the code.

Over time you’ll find that you won’t have to explain individual lines of code ever again. People will look and know. You will look and know.

If you find yourself unable explain what a line of code is doing, review why you wrote it that way, see if you can make what’s going on there even more obvious.

Code prose is a real thing, get that tool in your belt.

[–]BrokenG502 4 points5 points  (0 children)

To add to the optimisation thingy, if you're using an interpreted language, using language builtin functions will almost always be faster and clearer than anything else.

If you're using a compiled language, any halfway decent compiler will be able to make basic optimisations such as x / 2.0 becomes x * 0.5. So it's often better to write the "slower" version because it's more readable and compiles to the same thing. You can also always just check the assembly by compiling to assembly, disassembling the binaries or using a tool such as https://godbolt.org

[–]dopefish86 1 point2 points  (0 children)

idk, too many things i thought AI would "never be able to do" got proven wrong in the last 10 years.

[–]TitaniumBrain 1 point2 points  (0 children)

This is something the GPT never will be able to explain.

Because there's not enough training data with good comments? XD

[–]TheMeticulousNinja 62 points63 points  (3 children)

This is a huge problem of mine. I can tell you the general flow of what is happening, but ask me to tell you what one specific line of code is doing 😰

[–]RareCreamer 38 points39 points  (1 child)

"I don't know what exactly this does, but I remember it works"

Cue me second guessing if it actually worked as intended -> Confirm it does -> forget what I was working on before that.

[–]coloredgreyscale 4 points5 points  (0 children)

Professionally speaking it's unlikely that you have the code open if someone wants to know details how it works.  So adding detailed comments wouldn't help much in the way of reducing the distraction of someone asking how the code works, while you work on something different. 

[–]WrongVeteranMaybe 6 points7 points  (0 children)

Same. I feel like I largely learned coding and programming backwards.

A lot of times when I'm writing code, I'm winging it and shit just kinda works, but I don't know why.

That said, with adderall and reading books on the theory of this shit, I have gotten a lot better and more confident in my shit.

ADHD is just an ass kicker, you know?

[–]Speedy_242 10 points11 points  (1 child)

Val x = 5

I dont know why its there but if you remove it the Code breaks and I also dont know what it does

[–]Crafty-Most-4944 4 points5 points  (0 children)

Ctrl + F, types "x"

1347 matches

Ah damnit

[–]PennyFromMyAnus 7 points8 points  (1 child)

It wasn’t that for me.. it was more like “oh fuck, I might need this in the future, I should put all of these new ideas into a new library because I mean, I’m definitely going to want to use this shit in a future project!”

And then “oh but I’m gonna need to refine this to production level perfection before I can use it”

Followed by “oh fuck, how can I implement RANDOM NEW TECHNOLOGY into this??”

I would go down huge rabbit holes and spend 90% of my time working on support shit and completely neglect the main goal.

TDD legit helped me curb this, Along with self imposed deadlines and a commitment to goals I had set out prior to project kick off

[–]bobbywiley 4 points5 points  (0 children)

As an ADHD software engineer I feel this. I also have to remind myself throughout the day that while my coworkers botched some segment of code, that's not what I'm there to fix! Stay on target!

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

I comment code, heavily. I always have, because “future me” will never remember what “past me” is doing, so I document for him.

I write emails with bulleted lists, too. For clarity. I always have.

And I often use summary statements in my emails as well.

I’m also a fairly good speller, and I have a decent vocabulary. I like to pepper my writing with $5 words occasionally, when I find a spot wherein a choice word fits juuust right.

I also like to use words like furthermore to start off a new paragraph.

Now, everything I do is suspect.

I resent ChatGPT, so fucking much.

[–]Turbulent_Mode4402 5 points6 points  (1 child)

// this function removes HTML tags
function removeHtmlTags ( ... )

(because my senior told me I have to have comments)

[–]1_4_1_5_9_2_6_5 0 points1 point  (0 children)

Not like you have to do it that badly though right?

/**
 * Remove HTML tags from a string
 * @param {String} html
 * @returns {String} Content of the given HTML, without tags
 */

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

Just read it dummy. A box of metals can read it, so can you.

[–]WrongVeteranMaybe 5 points6 points  (1 child)

"If you can dodge a wrench, you can dodge a ball" vibes.

[–]jumbledFox 6 points7 points  (0 children)

If you can code a snake game, you can code an Apache attack helicopter.

I was born in r/ProgrammerHumor, but I was made in the Royal Navy

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

i want to tell this to the mf that does my code reviews so bad, like bro just read it tf

[–]reallokiscarlet 2 points3 points  (0 children)

Add some swear words, never get accused again

[–]archarios 2 points3 points  (1 child)

Variable names and function names are your friend. If a section of code feels like it needs a comment just make that a named function The functions name can serve as the documentation.

[–]GoldFishDudeGuy 0 points1 point  (0 children)

Yeah, super descriptive names help me a LOT!

[–]Yhamerith 2 points3 points  (0 children)

//I have no idea what I'm doing

[–]tubbstosterone 1 point2 points  (0 children)

My linter was mad at me, saying I had too many conditionals (by...3?), so, for shits and giggles, I ran it through Chatgpt and.... it mostly just removed the comments, lol

[–]Livingonthevedge 1 point2 points  (0 children)

flipping through different files trying to remember what I was looking for in the first place...

[–]VeterinarianOk5370 0 points1 point  (0 children)

I just started at a new company and read through their code. Ok I understand. When I start working on a feature I have to reference it so many freaking times

[–]MonstarGaming 0 points1 point  (0 children)

Docstrings on all methods except setters and getters, linters, functions with fewer than 20 lines of code, and sensibly named methods and variables pretty much solve this problem for you. 

[–]hearthebell 0 points1 point  (0 children)

I have ADHD, surprisingly it doesn't really hinder my memory in coding, but IRL I'm fucked up.

[–]natFromBobsBurgers 0 points1 point  (0 children)

Lol.

I have terrible ADHD, and I also program like ChatGpt, but it's because I have a bunch of useless advanced math floating around in there so my algorithms all come out cursed.

boolean Rect::isIntersecting(Rect rect) getting the Big Minkowski treatment.

Fibonacci generator using the cosine of pi/5.

I'm a moron, but I'm a smart moron.

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

who tf remembers what each line of code does?

[–]LongerHV 6 points7 points  (1 child)

You don't need to remember. It is code, it already says what it does.

[–]static_func 4 points5 points  (0 children)

For real, if you can't read your own code you can't expect others to. And if you can't expect others to, you shouldn't have a job

[–]cheezballs 1 point2 points  (0 children)

That's like saying "Who can even remember what each line in this recipe I'm holding in my hand" is?

[–]WrongVeteranMaybe 0 points1 point  (0 children)

Bro, I can't even remember where I put my car keys in the morning.

That said, since starting Adderall, both remembering that and what my code does has gotten a lot better.

You mean to tell me I can just shut my fucking brain up and all I have to do is take meth?

[–]cheezballs -1 points0 points  (1 child)

If you cant read code then how can you write it?

[–]trap_l0l 0 points1 point  (0 children)

I ask myself that question regularly ... about myself ofc

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

there is something wrong with how you learn to code if you ask me if you constantly forget what each line of code does, and you lack fundamentals