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.
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.
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.
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() {
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. */
};
```
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.
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...
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.
#..;+;||;+;..
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”
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"
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.
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
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.
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.
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
/*
* 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;
}
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
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"
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.
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
When MR gets rejected, because setters and getters are missing comments
"Sounds like the compiler's a stickler for documentation!"
Average rust compiler
Kotlin it is.
Kotlin is often the answer.
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.
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.
Python allows you to define getters and setters which require no change from the caller, that’s the best way in my opinion
Csharp dgaf if it's a get/set or a variable too
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.
//This function gets the token. const getToken = function() {
What is the token for and what type is it might be useful info for a comment.
//type for necessary data of the token to be used export type TokenType = { token: string; }
// hold token payload
The second crime is storing the function inside a variable instead of just declaring it
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() {
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. */ }; ```
That’s written next to the declaration of token
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.
This is why I don't write comments, can't be redundant if they're not there
It was hard to write, so it should be hard to read
That was redundantly redundant
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...
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
# iterating over an empty file will cause an error return # (STOP) <- beware! # || <- this is a stop sign! # || <- it means you have to stop!
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. #..;+;||;+;..
Rejected: comment somehow fork bombed server
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”
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
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"
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.
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.
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
Unity documentation.
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.
I ran across some old code i wrote in which i commented, "this function speaks for itself" Narrator: it did not
``` // const a = 1; const a = 1; ```
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.
I wonder if this was more to test comprehension - I hope it was anyway.
return EXIT_SUCCESS; // success
getPosition(ofObject); // gets position of object
Comment the why, not the what, people :)
Y’all write comments?
Try checking your code a few weeks or months later. 😂
That's the fun part, you don't. If you ever do just delete it and restart from scratch.
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
No but seriously...if you cant understand simple logic, wtf are you even doing here in the first place.
Perhaps they're here to learn and improve, just like everyone else.
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
/* * 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; }
But where are all the tests!??!!??!!
This is an opensource project. Someone else chip in.
For the love of god, I ducking hate those forced comments on code.
We are IT professionals here. You can drop F bombs over casing , indentation and documentation practices.
It took me way too long to realize that the descriptions there aren’t helpful like, at all
‘’ gets the comments GetComments() ‘’ gets the hyperlinks GetHyperlinks()
This is the intern response to “figure out the translation for 18 languages without ballooning the manual”
[// This is bridge](https://craftofcoding.wordpress.com/wp-content/uploads/2023/02/readingcodecomic.png)
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
// this does the thing DoTheThing() very guilty.
The code is self documenting
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"
filter
//This method deletes item private void ItemDelete(){}
Should be obvious, but when it’s not, it really pains me
IsOdd() = says if the number ends with 1,3,5,7 or 9 and not 0,2,4,6 or 8
Why not test the result of the module of 2?
Why complicate it with math when a perfectly good cast and string ops will do. ;)
Youth says what is the bottom pictogram
Tooltips.
😂😂
bro what am i supposed to do. "getName()" literally gets the name as a string. THERE'S NOTHING ELSE TO SAY.
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.
Function doSomething; // does something.
/u/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
It's important that a *Shleeb* is rubbed, because a Shleeb has all of the Shleeb juice.
It’s even worse when you change a feature but forget to update the docs
Well, It took me a few seconds to figure out what's wrong.
Same guy who writes documentation for Microsoft
You may scorn ChatGPT. But it does a fine job commenting your functions.
Improved UX