programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

MargotRobbie, in every damn time ...

In general, drunk me is the last person I would ever trust with literally anything.

It’s like waking up in the morning and reading your own drunk text messages.

psud,

Hits Balmer point, accidentally makes malware. A modern Jekyll and Hyde

TheFriendlyArtificer,

My wife got prescribed Ambien a few weeks ago. She took one, completely forgot about it, and 45 minutes later had a glass of wine with me while watching Taskmaster.

She then became convinced that she was actually on the show and went around the house asking me to time her doing random stuff. Th next morning she had zero memory and was floored when I showed her the video.

marcos, in every damn time ...

Trust the author? Are you crazy? Do you have any idea how many dumb mistakes I’ve caught the author doing?

flambonkscious,

They’re getting worse, too

(Assuming my experience is anything to go by)

akash_rawal, (edited ) in Need a rust version too.

You have rust.

You get a horse and arrive at the castle within seconds but the horse is too old and doesn’t work with the castle.

You remove the horse, destructure the castle and rescue the princess within seconds, but now you have no horse.

While you’re finding a compatible horse and thinking whether you should write your own horse, Bowser recaptures the princess and moves her to another castle.

odium, in every damn time ...

All the more reason not to

cmbabul,

I trust me to not steal from me, I do not trust me to write good code

rostby,

My code does exactly what I programmed it to do, not what I want it to do

HiddenLayer5, in Need a rust version too.
@HiddenLayer5@lemmy.ml avatar

You have Rust.

Forget rescuing the princess, that’s unsafe. Lock her down even more!

neurospice, in every damn time ...

Trust nobody, not even yourself

at_an_angle,

I don’t trust anybody. Hell, I don’t even trust myself. 🧛🏻‍♂️

xmunk, in every damn time ...

Random question… RPI, in my jargon, stands for role-play intensive, and it’s a category of MUD engines… are you working on such a project? Because I’m probably in the commit history, and that’d tickle me.

Pirasp,

It most likely stands for raspberry Pi, sorry to disappoint you…

xmunk,

Sadness, one can dream… one can dream.

SpeakinTelnet, in 10 months later bill revisits his spaghetti code. forgets absolutely everything and refuses to elaborate. this wouldn't have happened if Bill forgot to comment on his code

I don’t care how much you think your code is readable, plain text comments are readable by everyone no matter the proficiency in the programming language used. That alone can make a huge difference when you’re just trying to understand how someone handled a situation.

Fal,
@Fal@yiffit.net avatar

There’s nothing keeping the comments up to date with the code. Comments should be sparse and only on sections that aren’t obvious why they’re being done

Zagorath,
@Zagorath@aussie.zone avatar

Comments explain why, not what. Any comments that explain what a section of code is doing would probably be better off as separated methods.

Apart from basic documentation comments, like JavaDoc or C#'s XML documentation comments.

SpeakinTelnet,

There’s nothing limiting what a comment should be as far as I know.

As an example of what I mean, I’ve seen in a 10k+ lines python code a few lines of bit manipulation. There was a comment explaining what those lines did and why. They didn’t expect everyone to be proficient in bit manipulation but it made it so that anyone could understand anyway.

Zagorath,
@Zagorath@aussie.zone avatar

There’s nothing limiting what a comment should be as far as I know.

Nothing technical, sure. Just good coding practices.

lorty,
@lorty@lemmygrad.ml avatar

Then someone needs to change something about the code and doesn’t bother updating the comment. Now you still have uncommented code but with a comment that confuses instead of helping.

SpeakinTelnet,

IMHO the issue in this situation is not the comment but that the person updating the code didn’t do his job properly which shouldn’t be an excuse not to do it from the start.

xthexder, (edited ) in Walking Desk Is More Annoying Than A Standing Desk
@xthexder@l.sw0.com avatar

I feel like a treadmill desk would have been way simpler. Unless you like sun glare and spotty wifi.

sbv,

Okay, now put the whole thing on wheels. I can finally go grocery shopping during my scrum.

SinTacks,

Wolfram uses a walking desk but it’s more of a laptop support like a baby bjorn. I kind of want one but looks like they need a bit of customizing.

MostlyBlindGamer,
@MostlyBlindGamer@rblind.com avatar

There are also under-desk treadmills that you can use with an existing standing desk. You need to be able to raise it a bit higher though.

SinTacks,

The point would be to be outside. Were traveling right now and I can’t find the link but if you search for wolphrams life hacks type of thing there’s an article he wrote about it which was a fascinating read.

Personally I have an elliptical at home with a laptop stand on it and I love it.

felbane, (edited ) in Need a rust version too.

Rust: You declare the castle type as unsafe and then search for a crate with a rescue_princess function. You discover the princess you rescued is a femboy wolfkin named Pawws. You now have pubic lice and an inexplicable smug sense of superiority.

onlinepersona, in Bill is a pro grammer
philm,

Yeah, but unironic…

If your code needs comments, it’s either because it’s unnecessarily complex/convoluted, or because there’s more thought in it (e.g. complex mathematic operations, or edge-cases etc.). Comments just often don’t age well IME, and when people are “forced” to read the (hopefully readable) code, they will more likely understand what is really happening, and the relevant design decisions.

Good video I really recommend: www.youtube.com/watch?v=Bf7vDBBOBUA

Pickle_Jr,

Yeah, another way I’ve heard it phrased is comments are for explaining why you did things a certain way, not for explaining what it’s doing.

heikomat, (edited )

Exactly that! Everyone can See “what” is happening, the code is right there. But the code usually doesn’t tell you “why” that is happening - good comments help understand the authors intent and give context, so you don’t have to guess.

Good comments should explain the things that are not obvious.

Good comments more than once prevented me from accidentially undoing a fix.

nilloc, (edited )

Yup my comments are generally along the lines of:

  • I could have done this X way, but it ran slower
  • I was running out of time so this it’s mostly copied from (stack overflow url)
  • refactor when time allows

This is a side effect of doing lots of tiny websites , microcontroller code and mini web apps for under budgeted marketing projects with constantly changing designs and requirements that don’t need to last too long.

ChickenLadyLovesLife,

comments are for explaining why you did things a certain way

A while back I spent more than a year modifying my company’s iOS apps so that they would work properly with VoiceOver (Apple’s screen reader technology for blind people) and be compliant with FCC regulations for accessibility (and save us from $1 million per month fines lol). The thing about VoiceOver is that it’s bizarrely buggy (or was - maybe they’ve fixed the problems since then) and even when I didn’t run into VO bugs, the way that developers tended to architect these apps often made getting them to behave properly with VoiceOver extremely difficult.

I often had to resort to very strange hacks in order to get things to work, and I would always leave comments explaining what I had done for this. My manager was one of the new breed who not only thought comments were unnecessary in ALL cases but also thought comments were a “code smell” and indicative of professional incompetence on the part of anyone who used them. Whenever he reviewed my code, he would leave in the hacks (after trying and failing to fix the problems without them) but remove my comments. This resulted in many cases later of developers contacting me to ask me why some bizarre bit of code was in the app in the first place. I always referred them to my manager with an NMP (Not My Problem any more).

magic_lobster_party,

I think most people fail to understand what code smell really is. They think code smell means bad code. A code smell is actually an indication that something else might be bad with the code. The code smell itself might not be bad.

So when a code smell appears, it means you should identify the reason it exists and potentially fix it. In this case the bad code is a buggy external library, which is difficult for you to fix. Therefore, leaving the “code smell” is the best course of action.

Your manager was in the wrong and you were right to write comments.

zalgotext,

This resulted in many cases later of developers contacting me to ask me why some bizarre bit of code was in the app in the first place. I always referred them to my manager with an NMP (Not My Problem any more).

I hope this isn’t a real story. It would have taken you just as long to refer them to the commits with your comments still in, and run a git blame to show your manager took them out. Instead you just make yourself look unhelpful and incompetent.

docAvid,

Bold of you to assume they were using source control under that manager…

magic_lobster_party, (edited )

I’ve seen code that look like this:

int delay = 15 * 60; // 10 minutes

Even if the comment was on the same line someone forgot to update it. People just ignore comments.

Better solution is to write (in C#):

TimeSpan delay = TimeSpan.FromMinutes(15)

Much more obvious what the code actually means.

18107,

A better comment would be delay in seconds as that is the one thing not obvious from glancing at the code.

magic_lobster_party,

Or just name the variable delaySeconds if you really want to store it as an int. Bonus is that every use of the variable perfectly communicates what it is.

CCatMan,

Is the better way is a runtime performance hit. Does the compiler optimize this?

magic_lobster_party,

It’s probably a little bit slower, but there are other things more worth to optimize than to shave off a few microseconds from a 15 minute delay.

CCatMan,

Yeah, it adds up eventually when working with embedded platforms, but for PC stuff I agree.

magic_lobster_party,

If you’re working in embedded I guess you can probably make an inline function or a macro so it’s taken care of at compile time.

Anticorp,

Code comments are useful for browsing a script and understanding it at a glance. I shouldn’t have to scroll up and down across 700 lines of code to figure out what’s happening. It’s especially useful with intellisense, since I can just hover over a function and get a tooltip showing the comment, explaining what it does. It also helps when using functions imported from other files, since it’ll populate the comment showing me what parameters are needed and what each should be. Comments save time, and time is valuable.

astraeus, (edited )
@astraeus@programming.dev avatar

This mindset is good, but unfortunately enforces bad programmers to leave their undocumented code in critical places where someone eventually has to figure out what the hell they were doing or refactor the whole damn thing because they got promoted to middle-management and can’t remember why they even wrote it.

magic_lobster_party,

Chances are that the comments quickly turn out of date and become incorrect. Misleading comments is worse than no comments.

astraeus,
@astraeus@programming.dev avatar

We shouldn’t waste time documenting our code when we need so much of that time breaking our code

heikomat,

If the comments tell you “what” happens, then yes, they can geht outdated fast. The details of how something works can change quickly.

But comments documenting “why” something is done (a certain way) - explaining the intent - are probably valid for mich longer.

In the best case comments aren’t viewed as something that is seperate from the code, but part of it. So that if someone changes the code, the comments has to be checked aswell (if the explanation of “why” something is done actually changed).

ChickenLadyLovesLife,

This is something that is always stated by people who are opposed to comments, but I’ve never seen any such thing in practice. If being mislead by incorrect comments is so common, there should be a bunch of stories around about disasters caused by them - and I’ve never read a single such story.

magic_lobster_party,

I’ve seen it. That’s why I’m opposed to comments unless they really bring value (like explaining the why instead of the what).

ChickenLadyLovesLife,

I’ve seen it.

OK, so let’s hear your story about how misleading comments caused a major (or even a minor) problem.

magic_lobster_party,

One example was when a method's documentation said that it would throw a certain exception. Turns out it was actually throwing a different exception (deep into the code), so no wonder why we never captured it in time.

CowsLookLikeMaps, (edited )

Or you’re stuck within the confines of a horrible legacy system which the business will not allow you the time to refactor/rewrite but still want your code to be somewhat readable.

But in general, I agree with your argument. When writing from scratch or improving reasonably well designed code, often documentation could be replaced by breaking it up into another function or naming variable better. It’s a bit of a code smell for violating the SRP. And yet there are times that documentation is needed for the “why”. Things are nuanced I guess.

DaleGribble88, (edited )
@DaleGribble88@programming.dev avatar

I have such a love-hate relationship with that video. On the whole, I think that video is bad and should be taken down. The creator is arguing against a very specific type of commenting but is harassing comments in all forms. It even addresses as such with a 20 second blurb 2/3 of the way into video distinguishing between “documentation comments” - but doesn’t really provide any examples of what a good documentation comment is. Just a blurred mention of “something something Java Doc something something better code leads to better documentation” but doesn’t elaborate why.
It’s a very devious problem in that I don’t feel like any particular claim in the video is wrong, but taken within the context of the average viewer, (I teach intro. comp. sci courses and students LOVE to send this video and similar articles to me for why they shouldn’t have to comment their spaghettified monstrosities), and the inconsistent use of comments vs. code duplication vs. documentation, the video seems problematic if not half-baked.
In fairness, it is great advice for someone who has been working in the industry for 15 years and still applies for junior positions within the same company - but I can’t imagine that was the target audience for this video. In my experience, anyone who has been programming on a large-ish project for more than 6 months can reach the same conclusions as this video.

ChickenLadyLovesLife,

I’m from the camp that thinks if you’re trying to make a case (about any subject), you should start with your strongest point and work to your weakest point. Every argument I’ve ever seen against code comments starts off with the weakest imaginable points. Usually the first point made is sample code like “x = x + 1” with the absurdly unnecessary comment “add 1 to x” - as if that’s ever something that pro-comment programmers do. This video at least started off with a novel weak point (somebody using a comment with a magic number instead of making it a constant) although it’s just as weak as the “x = x + 1” argument.

potustheplant,

That’s like saying a book’s synopsis shouldn’t exist because you can just read the whole book. Sometimes comments can save you a lot of time and point you in the right direction.

BaardFigur,

Comments also helps explaining why certain non-obvious decisions are made. E.g. a workaround for a bug in a library

philm,

Nah, it’s not, code is modular (IME should be kinda tree-structured), a book is linear.

So the API should be in your analogy the synopsis. And I haven’t said, that there shouldn’t be any comments. E.g. doc-comments above functions, explaining the use-cases and showing examples are good practice.

potustheplant,

Books can be modular as well (ever heard of “Rayuela” by Cortazar?) But that’s beside the point. The analogy is fine and it works.

Vilian, (edited )

and if you need an unnecessarily complex code for performance sake?

hstde,

There’s a comment for you to explain the why.

Rule of thumb: code explains the how and what, comments explain the why.

philm,

Yeah that’s a good summary

magic_lobster_party,

Those cases are rare. Often the most basic solution is good enough.

If you have to write complex code, then you should write a comment (write the name of the algorithm for example).

Test_Tickles,

Rare?
Where do you guys work that all you do is write basic AI generatable code?
The only thing I can think is that you are a bunch of freelance devs who never have to maintain anything or add functionality to old code. Either that or you are all new and are just full of theoretical bullshit that you read on the internet.

magic_lobster_party,

So you implement A* type of algorithms every day in your work?

Test_Tickles,

Yes. I mean often enough that I wouldn’t call it rare.

You are a front-end js/ts devel, aren’t you? That makes sense. I can understand why you would have such a skewed view of programming. When everything you write is disposable and might be scrapped every 2 - 3 years, comments would seem like nonsense and a waste of time.

But that is definitely not everyone’s experience. More than half the code I have written has had a minimum 15 year life expectancy. Comments are essential to remember what I was doing in whatever random language I had to use at a given point. I might not comment on “x++;” but I sure as shit will on “x += (xDelta * yDelta + 31) / 32;” Actually, that’s not true, if the logic is complex enough for the rest of the code chunk, I might just comment on “x++;” to make it clear what x is in this case and why it needs to unconditionally be incremented here. Even if the reason seems ridiculously obvious right now. Because that shit might not be obvious at all in 10 years.

magic_lobster_party,

My job title is actually a data scientist. I’ve seen few pieces of code that couldn’t have been made more explainable by just using a more clear and concise naming of variables and functions. Don’t try to be so overly clever with your single letter variables and Greek alphabet. Just explain what it is with a good name.

If I’m lucky I get to write a cool new algorithm once per quarter or so. Usually it’s just a standard algorithm that has an explanation in a Wikipedia page, so I just give the name of the algorithm and a link to that page.

Most of the time we’re just doing basic data processing building on the preexisting solutions. These generally don’t need comments.

The worst code is usually when someone has tried to be overly clever (including myself). Often a simple and straightforward solution had been overlooked. Simple solutions are easier to understand and maintain. Anyone can just look at the code and get a sense of what’s going on without any comments. In many cases a simple solution has also more accurate and faster to compute.

In my work, having explainable results far outweighs anything else, and you don’t get that by writing difficult to understand code.

Awkwardparticle,

One day you will inherit a code base so bad that you’ll end up commenting old code just to make sense of it for yourself because nobody in the company has touched in a couple years and the last people that did no longer work there. It will be dangerously coupled, if you make the right change somewhere it will break everything else. It will be true spaghetti code where you spend 30 min just following a code path to figure out what and why an input into a function needs to be what it is to able to come out of another function in an exact format for anything to work.

Your so called comment standards and principals are fine if you are building something from the ground up, but the other 95% of the time, you do what you gotta do because your were blessed with a turd that is impossible to polish.

philm,

One day you will inherit a code base so bad that you’ll end up commenting old code

Will not be the case, I won’t take a job, where I have this situation (or I’ll quit pretty quickly)…

Yeah my “comment standards” (btw. as others mentioned here, I was unprecise/unlucky with the choice of words, I meant “comment the why” or doc-comments totally fine and should be aimed)

Your so called comment standards and principals are fine if you are building something from the ground up

Yes that was also targeted with my comment. But what you’re referring to is just missing documentation, and I think this should be done on a higher level. The “comment why” rule applies for spaghetti code non-the-less…

BeigeAgenda,
@BeigeAgenda@lemmy.ca avatar

Sounds very theoretical, my experience working on some 40 year old software full of business logic, where customer A got some feature but customer B needs it to work slightly different. Aka something approaching spaghetti.

Regarding old comments I have several times used ~15 year old comments by the original author, close to the actual code to piece together the use of that code, and if I can add my fix there.

In this setting You write comments for yourself, when you in two years need to fix a bug in the new code caused by your old code. And for the next developer that will look at your code decades after you left the company.

Sometimes you, against good practice, comment out a section, with a note why, because you know this will have to be re-enabled in a few months.

Report from the frontlines…

floofloof, (edited )

If you’re working with others, even simple code benefits from comments explaining what it’s intended to do. Sure you can read code and get a good idea of what it seems to do, but you can’t be sure that’s what it was meant to do, or why it was meant to do that. Having a quick statement from the author enables you to work faster. And if you find a mismatch between the comment and the code, it’s a smell that could mean a bug.

And for methods and functions it’s particularly helpful to have a description at the top. Many IDEs will pop this up when you’re using the method, so you can quickly confirm that it’s appropriate for your needs and get your arguments in the right order.

I even comment code for myself because it will save me time when I return to the project months later.

No comments would be fine if you could trust that everyone writes code that does what it’s intended to do and you can read code as quickly as you can read English. Maybe I’m a poor coder but I find neither of these is usually true.

philm,

Don’t get me wrong comments != documentation (e.g. doc-comments above function/method).

I probably was a bit unprecise, as others here summed up well, it’s the why that should be commented.

magic_lobster_party, in Bill is a pro grammer

x += 1; // Increases x by one

towerful, (edited )

// increase the dynamically allocated memory space of a word sized integer stored at the memory address represented by the symbol “x” by the integer 1 and terminate the instruction

Anders429,

Why the heck does it need to be dynamically allocated? Just put that puppy on the stack.

towerful,

That’s what it used to do.
But it was a bug, and the code has been fixed.

morrowind,
@morrowind@lemmy.ml avatar

Wait why is it dynamically allocated and why are you increasing the memory. Something is very wrong here

floofloof,

Found the bug. Thank goodness for comments.

Anders429,

Oh, is this what they meant by “commenting your code”?

ZILtoid1991,
@ZILtoid1991@kbin.social avatar

x++; // Move X position forward by one

There, I made that kind of comment more useful!

LostXOR,

x++; // Set x to the incrementation of the value of x
Much better.

Jakylla,
@Jakylla@sh.itjust.works avatar

// Move to the right

autokludge, (edited )
@autokludge@programming.dev avatar

…Years later
x += config.increment; // Increases x by one


<span style="color:#323232;">"""
</span><span style="color:#323232;">config.yaml
</span><span style="color:#323232;">increment: -2
</span><span style="color:#323232;">"""
</span>
pewpew, in Bill is a pro grammer
@pewpew@feddit.it avatar

Code looks better without comments

BaardFigur, (edited )

Comment smart, don’t comment every line like this

int i = 5; // Assigns the value 5 into the variable i.

Maalus,

Comment only in extraordinary situations, when something you read can confuse someone. And by that I mean the business logic, not that you used a method that’s confusing to people since they only know the basics of the language.

Sylvartas, (edited )

Honestly, after a few years of working with juniors (and being one myself before that), I have to disagree with the last part. Sure, it’s fine for solo projects but people’s programming skills can vary heavily. I know people who will pull the wildest C++ compile time tricks you’ve ever seen, but a pointer to a pointer would somehow break their brain.

stebo02,
@stebo02@sopuli.xyz avatar

I usually comment on whole groups of lines of code, so the goal of each part of the code is clear

RagingRobot, (edited )

I would disagree. I love to use comments to format my code and separate the sections. I think it’s so beautiful. Also I love when libraries have ASCII art in the comments at the top of the main file lol. It makes the code more fun in my opinion.

I went to college with a guy who would treat the code as art when presenting projects. His code was always beautiful. Not super functional but always beautiful. It always stuck with me. I want my code to always be functional and beautiful. Easy to read and a pleasure to work with. That’s my goal at least. Comments help with that.

Also it depends on what the code is for haha

EnderMB, in Bill is a pro grammer

Comments don’t describe the code. They describe the decision to use this business logic.

If you stick to good engineering practices, like small methods/functions, decoupling, and having testable code, you don’t often need many comments to show what your code does. I always recommend a method signature, though, because you can save a few seconds by just saying that a block of code does, rather than me needing to read exactly how you turned one dict into another dict…

MrSqueezles,

I agree for inline code comments, like, “# Save the sprocket”, right above the line that saves the sprocket. Does this include documentation? Because when I see a prepareForSave function that references 10 other functions and I just want to know, “Is this mutating and how is it preparing for save and when should I call it?”, having the author spend 15 seconds telling me is less time consuming than me spending 5 minutes reading code to find out. Anyone who has read API docs has benefited from documentation.

EnderMB,

No, commenting a function should be commonplace, if not only so that your IDE/editor can use the documentation when the signature is found elsewhere in your code.

Within a function, though, basically means that something gnarly is happening that wouldn’t be obvious, or that the function is doing more than it (probably) should.

Smoogs, in Bill is a pro grammer

Wow the comments here sounds like you’re all a bunch of antisocial nightmares to deal with in rL.

frezik,

That would be the type of people attracted to programming, yes.

nailbar,

I consider myself social. I’m a programmer because I love making things, and because I’m lazy, and I hate doing repetitive tasks.

DontTreadOnBigfoot,
@DontTreadOnBigfoot@lemmy.world avatar

Welcome to Lemmy

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmer_humor@programming.dev
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20975616 bytes) in /var/www/kbin/kbin/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php on line 171

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 393216 bytes) in /var/www/kbin/kbin/vendor/symfony/error-handler/Resources/views/logs.html.php on line 32