programmer_humor

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

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.

jettrscga, in Programposting

“No style” hits hard. Hadn’t they done enough damage already?

reverendsteveii, (edited ) in Bill is a pro grammer

`//Get CustomerInfo from CustomerRepository by Customer ID or else throw an CustomerNotFoundException

public CustomerInfo getById(String customerId) {


<span style="color:#323232;">return customerRepository.getById(customerId).orElseThrow(new CustomerNotFoundException());
</span>

}`

This is the kind of pointless comment I see in my codebase all the time. Best I can tell, a couple of my coworkers like to plan out their code using comments, then backfill in the actual executable code. That’s fine, but they leave the comments in when they add no value.

` public static LocalDate parseEndDateFromString(String dateString) {


<span style="color:#323232;">    try {
</span><span style="color:#323232;">
</span><span style="color:#323232;">        String[] split = dateString.split("-");
</span><span style="color:#323232;">
</span><span style="color:#323232;">        //In order to get the last day of the desired month, we go to the first day of the next month, account for rollover, then subtract one day
</span><span style="color:#323232;">
</span><span style="color:#323232;">        int month = Integer.parseInt(split[0]) == 12 ? 1 : Integer.parseInt(split[0]) + 1;
</span><span style="color:#323232;">
</span><span style="color:#323232;">        return LocalDate.of(Integer.parseInt(split[1]), month, 1).minusDays(1);
</span><span style="color:#323232;">
</span><span style="color:#323232;">    } catch (Exception e) {
</span><span style="color:#323232;">
</span><span style="color:#323232;">        throw new RuntimeException("Invalid date format - must be MM-YYYY");
</span><span style="color:#323232;">
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">}`
</span>

Stuff like this, otoh, is where comments are useful. The required format is obvious from the error message, the param and return from the method signature, the only part that requires a comment is the fiddly logic of accounting for the edge case where month == 12 and the rationale behind how we determine the last day of the month. As a rule, comments are for why something is being done, if it’s not obvious, and for magic numbers. Code should tell you what code does.

edit: can anyone spot the bug that I introduced with that parseEndDateFromString() method?

CJOtheReal, 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

Comment your code but only with numbers and then write a manual

Rinox,

Yeah, proper documentation is not done with comments in code, but it’s a project in and of itself. Proper documentation is also fucking hard and I have no idea how people (in open source projects) can do it. It’s so fucking boring and tedious, especially when there are a million interesting problems you could tackle instead. Mad respect for people writing documentation, seriously.

I also hate writing comments and prefer to just write out everything in code.

CJOtheReal,

I write the shit in the explanation before programming it, its a way to construct a code in human language and logic, with my manual you could program the exact same program in another programming language. (i cant show it because what i program is company secret, including the manual) and yes its kinda boring but everyone is grateful for it and for the things i do i need to make shure its never failing, so its checked by several different people, and such a manual helps a lot for everyone.

pkill,

yep. Good code is self-documenting and syntax highligting and having longer sections folded up may help more than having to process some greyed out text. But comments are still useful for generating proper autocompletion and avoiding having to skim through you '“self documenting code”. Also it helps greatly with TDD and maintaining good coding practices. For example if you need a numbered list to reliably sum up what some function does, it’s often a good sign that it should be broken into a couple smaller ones.

AnUnusualRelic, in Walking Desk Is More Annoying Than A Standing Desk
@AnUnusualRelic@lemmy.world avatar

Isn’t this bad for the Ethernet cables?

Hazzia,

Just get a wireless ethernet adapter (which exists and I loathe the fact that it does)

Valmond,

If they are straightened out they might not be able to mingle/mix-up.

kubica, in Walking Desk Is More Annoying Than A Standing Desk
@kubica@kbin.social avatar

The kind of walker I want for when I'm older.

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

magic_lobster_party, 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

Bill writes spaghetti code.

Bill is not smart.

Don’t be like Bill.

drew_belloc, in Programposting
@drew_belloc@programming.dev avatar
killeronthecorner, 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
@killeronthecorner@lemmy.world avatar

Bill never revisits his code.

Bill is a contractor smart.

Socsa,

Bill changes jobs every two years to outrun the crushing weight of institutional responsibility.

mp3,
@mp3@lemmy.ca avatar

A technical debt escapist.

Potatos_are_not_friends,

NGL that is one of the best parts about being a contractor.

So many hackjobs. Sorry maintainers.

killeronthecorner,
@killeronthecorner@lemmy.world avatar

We all envy you more than we hate you

graycube, 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 hate fixing other people's code. It is one of the reasons I don't like letting an AI write my code first draft either.

Prunebutt, 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

Comments are lies that will happen sometime in the future

Comments are always overlooked if gode gets refactored. Language servers can’t/won’t parse them and they’re easy to overlook.

If you name your functions/variables clearly, put complex logic into clearly named functions and keep the same level of abstraction in every function (which never exceeds roughly 50 lines), you hardly need any comments, if any.

Comments are for behavior that’s not possible to convey clearly through code.

Archive,

If a block of code needs a comment, then you can easily move that block into a function and summarise the comment into a name for that function. If you can not easily move a block of code into a function, then you may need to rethink your design.

This isn’t always true of course, but it’s a good mindset to have.

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.

PunnyName, 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

Remembered*

Bill DID forget.

towerful,

Classic comments.

Code is spaghetti.
Comments describe what it used to do.
Comments are no longer relevant.

Comments should be about how/what a code block does something.
Not what a line of code does

drolex, 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

Wow this job has massive amounts of unnecessary stress, I wonder what the cause can be.

The cause is me, 6 months ago.

(Written for comedic purposes only. Managers are my single source of stress)

agent_flounder,
@agent_flounder@lemmy.world avatar

Me: writes code^1, doesn’t comment

Me, six months later: what idiot wrote this shit?!

  1. Only developer on project
drolex,

Time to plan a 3-day workshop with yourself at the pub to get it together

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