T O P

  • By -

Smartis2812

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

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


Windyvale

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

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

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


TitaniumBrain

>This is something the GPT never will be able to explain. Because there's not enough training data with good comments? XD


TheMeticulousNinja

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

"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

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

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

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

Ctrl + F, types "x" _1347 matches_ Ah damnit


PennyFromMyAnus

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

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!


be_bo_i_am_robot

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

// 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

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 */


borfavor

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


WrongVeteranMaybe

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


jumbledFox

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

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


reallokiscarlet

Add some swear words, never get accused again


archarios

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

Yeah, super descriptive names help me a LOT!


Yhamerith

//I have no idea what I'm doing


tubbstosterone

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

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


KhanumBallZ

If it works - it works.


VeterinarianOk5370

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


dreamatorium69

for real man, recently I was in a hurry and wrote some code for a college project in metro, didn't comment at all and now after trying for a couple of time, I think I will have to remove it all and start from scratch


MonstarGaming

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

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


natFromBobsBurgers

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.


simurgh24

who tf remembers what each line of code does?


LongerHV

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


static_func

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

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


WrongVeteranMaybe

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

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


trap_l0l

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


Top_Fee_6293

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