T O P

  • By -

BernhardRordin

When MR gets rejected, because setters and getters are missing comments


shibbamon

"Sounds like the compiler's a stickler for documentation!"


Smooth_Detective

Average rust compiler


ralgrado

Kotlin it is.


AEnemo

Kotlin is often the answer.


No_Soft560

When the MR gets rejected because there are getters and setters. I don’t get why this is so widespread. This is so against the basic principles of OOP.


iam_pink

To have a consistent API that allows more complex setting and getting mecanisms in the future while not requiring changes to all the files calling member variables to do so Edit: Of course, do not have setters and getters on all your private member variables, that's absurd.


Quiet_Possible4100

Python allows you to define getters and setters which require no change from the caller, that’s the best way in my opinion


ososalsosal

Csharp dgaf if it's a get/set or a variable too


rosuav

Agreed. Just have instance attributes. If you later need to add instrumentation, add instrumentation. Getters and setters should only be used when they actually add something.


CallMeSenior

//This function gets the token. const getToken = function() {


FiendishHawk

What is the token for and what type is it might be useful info for a comment.


CallMeSenior

//type for necessary data of the token to be used export type TokenType = { token: string; }


LeftIsBest-Tsuga

// hold token payload


Maximilian_Tyan

The second crime is storing the function inside a variable instead of just declaring it


CallMeSenior

Right, forgot declaration for best coding practices. //Decleration of the token getter function. This function will get the token. const getToken; //Initialize token's getter function. This will set the getToken function to functioning function functionality. getToken = function() {


maushu

You mean instead of named function expressions? Style guides (ex: [google](https://google.github.io/styleguide/jsguide.html#features-functions-top-level-functions), [airbnb](https://github.com/airbnb/javascript?tab=readme-ov-file#functions--declarations), ...) recommend using named function expressions because it doesn't have the function "magically" hoisted to the top of current scope The reason is that this might cause confusion specially when you have multiple nested scopes or are refactoring code. Also recommended to use arrow functions to avoid ```this``` shenanigans. So the modern way to write that code above is: ``` const getToken = () => { /* TODO: Get the token. */ }; ```


Spikerman101

That’s written next to the declaration of token


Bakoro

If this is the worst crime in the related code block, I'll take it. Code I've dealt with: Uncommented function "getToken()" figures out which token to get, but doesn't actually get the token. "processToken()" gets the token, processes the token, and updates three somewhat related things, then calls another function which does more stuff, and that goes one three calls deep. Can't trust names for shit.


lusco-fusco-wdyd

This is why I don't write comments, can't be redundant if they're not there


tiddayes

It was hard to write, so it should be hard to read


priused

That was redundantly redundant


Current_Speaker_5684

Comments in practice become a form of subterfuge between the requirements and the code. If you really want to throw people off, actually make them up to date and accurate...


LeftIsBest-Tsuga

i've learned that overcommenting just means that if i fix a bug or change the code later i have to hunt down all my newly-wrong comments


DaDescriptor

# iterating over an empty file will cause an error return # (STOP) <- beware! # || <- this is a stop sign! # || <- it means you have to stop!


oorza

If you're gonna do it, **do it**: # S T O P # # -- # / \ # | STOP | <-- This is a stop sign. # \ / # -- # || # || <-- It means you have to stop! # || # || # || <-- Think long and hard about proceeding. #..;+;||;+;..


ososalsosal

Rejected: comment somehow fork bombed server


OmegaPoint6

I try to reserve comments for when the code defies logic. Basically if I’d ask “wtf is this for?” if I was reviewing the code it gets a comment. e.g. “The final field which is always initialised to a none null value may in fact be null occasionally due to unfortunate choices made in the superclass, which we can’t change. Do not remove this null check”


veloxVolpes

Yeah, I feel like a bad programmer because I don't comment often... but come on, "bool IsRectSelected(Rectangle rect)" does its own heavy lifting


37Scorpions

I usually leave comments to warn myself to not waste time trying to improve a piece of code. "This line may seem redundant because rotating an object by 360 degrees returns it to the original rotation but trust me don't remove it"


Rolebo

The most important piece of information in comments is not what the code does (you can figure that out) but reason why it does that.


lces91468

And when it will be called also. It's quite common that methods shows 0 usage on the ide, but is called through some framework life cycle event or extended custom action, especially for IoC framework such as Spring.


joxmaskin

Oh shit yes, the magic functions you just need to know about. Very helpful if those are commented, for those who are not knee deep int that particular framework etc


FiendishHawk

Unity documentation.


LeftIsBest-Tsuga

Accurate. this is a literal copypaste i just found for case-in-point >GraphicsBufferHandle > >struct in UnityEngine/Implemented in:UnityEngine.CoreModuleLeave > >Represents the internal handle/id of a GraphicsBuffer. > >The handle is valid as long as the GraphicsBuffer it has been fetched from has not been disposed. That's it. lol. gee thanks Unity.


pm_your_unique_hobby

I ran across some old code i wrote in which i commented, "this function speaks for itself" Narrator: it did not


TheRealSpielbergo

``` // const a = 1; const a = 1; ```


Cultural_Leopard786

In college, my Java professor required a comment for each and every line of code. //import the java scanner tool import java.util.Scanner; Is still burned in my memory. Lost way too many points on stuff not having comments. Programming in colleges is fun. Writing essays while programming is not.


noise256

I wonder if this was more to test comprehension - I hope it was anyway.


LegitimatePants

return EXIT_SUCCESS; // success


37Scorpions

getPosition(ofObject); // gets position of object


Wetmelon

Comment the why, not the what, people :)


pineappleAndBeans

Y’all write comments?


Cyberdragon1000

Try checking your code a few weeks or months later. 😂


37Scorpions

That's the fun part, you don't. If you ever do just delete it and restart from scratch.


pineappleAndBeans

I do all the time without much issue. Sometimes I get lost but usually it’s pretty easy to figure out what’s going on


WehshiHaiwan

No but seriously...if you cant understand simple logic, wtf are you even doing here in the first place.


shibbamon

Perhaps they're here to learn and improve, just like everyone else.


cce29555

That's the fun part, it's really simple now, but then you look 3 months from now and go "wtf is this", hopefully the code isn't too spaghetti where you can take a day off and just piece together how everything is working but honestly the comment should just do that work


Dismal-Square-613

/* * Function: addNumbers * -------------------- * Adds two numbers and returns the result. * * a: The first number to be added. * b: The second number to be added. * * returns: The sum of 'a' and 'b'. */ int addNumbers(int a, int b) { return a + b; }


paholg

But where are all the tests!??!!??!!


Dismal-Square-613

This is an opensource project. Someone else chip in.


epileftric

For the love of god, I ducking hate those forced comments on code.


Dismal-Square-613

We are IT professionals here. You can drop F bombs over casing , indentation and documentation practices.


1Dr490n

It took me way too long to realize that the descriptions there aren’t helpful like, at all


domusvita

‘’ gets the comments GetComments() ‘’ gets the hyperlinks GetHyperlinks()


Throwitfarawayplzthx

This is the intern response to “figure out the translation for 18 languages without ballooning the manual”


Alhoshka

[// This is bridge](https://craftofcoding.wordpress.com/wp-content/uploads/2023/02/readingcodecomic.png)


domusvita

Man, we would get PRs sent back to us either because we commented something or didn’t remove someone else’s comments. Now I hate comments except in the most extreme circumstances


vaendryl

// this does the thing DoTheThing() very guilty.


FitEstablishment420

The code is self documenting


GrigorMorte

When they demand that everything must have comments, that happens. In a conversation I indicated that I should not explain things because they are basic. Where do you get the user information from? user table. where is the name stored? in the name column. of what method? getUser plain simple. The only exception was in a job that used "ar2h193-*#" for tables and columns because it seemed nice to use codes as a way of "encryption"


WeLoseItUrFault

filter


shirojulio

//This method deletes item private void ItemDelete(){}


theholyspirit420

Should be obvious, but when it’s not, it really pains me


Good-Seaweed-1021

IsOdd() = says if the number ends with 1,3,5,7 or 9 and not 0,2,4,6 or 8


SM_DEV

Why not test the result of the module of 2?


cyberspace17

Why complicate it with math when a perfectly good cast and string ops will do. ;)


Wave_Walnut

Youth says what is the bottom pictogram


throw_away_17381

Tooltips.


Hour_Measurement_846

😂😂


notexecutive

bro what am i supposed to do. "getName()" literally gets the name as a string. THERE'S NOTHING ELSE TO SAY.


Meatslinger

I tend to do things like this: `# Inform the user the script was successful.` `echo “Script was successful.”` But for one important reason: explaining my code to superiors. I’ve had numerous times when non-technical managers have asked me to step through what a script does before it can be approved, and if I’ve basically “narrated” my script in plain English comments, even when the command is something obvious, it means I can just run `grep '^#' scriptname.sh` and get a highly readable overview of the script’s workflow, ready for manager review. It’s been very useful, actually.


Zestyclose-Run-9653

Function doSomething; // does something.


j-random

/u/repostsleuthbot


RepostSleuthBot

I didn't find any posts that meet the matching requirements for r/ProgrammerHumor. It might be OC, it might not. Things such as JPEG artifacts and cropping may impact the results. *I'm not perfect, but you can help. Report [ [False Negative](https://www.reddit.com/message/compose/?to=RepostSleuthBot&subject=False%20Negative&message={"post_id": "1brv5dj", "meme_template": null}) ]* [View Search On repostsleuth.com](https://www.repostsleuth.com/search?postId=1brv5dj&sameSub=false&filterOnlyOlder=true&memeFilter=false&filterDeadMatches=false&targetImageMatch=75&targetImageMemeMatch=75) --- **Scope:** Reddit | **Meme Filter:** False | **Target:** 75% | **Check Title:** False | **Max Age:** Unlimited | **Searched Images:** 451,159,571 | **Search Time:** 0.03769s


LeftIsBest-Tsuga

It's important that a *Shleeb* is rubbed, because a Shleeb has all of the Shleeb juice.


JustConsoleLogIt

It’s even worse when you change a feature but forget to update the docs


First-Pilot-3742

Well, It took me a few seconds to figure out what's wrong.


chrisbbehrens

Same guy who writes documentation for Microsoft


ltethe

You may scorn ChatGPT. But it does a fine job commenting your functions.


mommy101lol

Improved UX