Honestly, I feel like this style of commenting is school's fault. They teachers often want this type of comment so they can be sure that the students understand what they wrote, but it is definitely NOT helpful in non-academic settings.
It's one of the first things I try to unteach newbies in the field.
I’m actually self taught! :) I just have a crazy habit of commenting everything. I like to separate chunks of logic so what I’m writing is crystal clear for my future self. But I sometimes just go overboard
I’m trying to stop this but I guess old habits die hard lol
Yeah! Just one liners to add structure helps I feel. I used to be way too specific with my comments, so I’m trying to cut back when it’s something I suspect could change in the codebase in the future
Often it is better to split methods up into many methods with descriptive names. This helps in a couple of ways. First, comments often become stale, meaning they don’t actually agree with the code. Another is it helps keep side effects between two sections of code to a minimum.
We have an OCR bot using ocr.space's API, but it's not very reliable. Some people use it as a basis for their transcriptions and just fit it into our formats & fix its mistakes, but I personally find it more engaging & pretty much just as fast to do it all by hand.
Happens to me way too often. Usually I write the logic as a sequence of comments and then fill the gaps with code. I don't always delete the comments...
Comments are a lot like signs & labels... They should be clear, concise, and cover the messy details...
That's a tad excessive though... As an aside, I've never understood why some coders seem to have this anti-comment mentality. All it seems to do is cause them and their successors more problems...
I read in some book while learning python that "comments line, only code tells the truth". I'm not against commenting, but it makes sense to me, to try to avoid obvious comments
For sure. You want the code as clean as possible. But it’s really critical to have proper documentation at some point throughout the code to let others know what’s happening where.
Y’know like if you’re building a library or package or whatever it’s really nice to have that inline documentation
/// <summary>
/// Does the alert
/// </summary>
/// <param name="b_reserved"></param>
/// <param name="s_text"></param>
/// <returns></returns>
function DoTheAlert(string s_text, bool b_reserved) {
alert(s_text);
}
// This does the alert
DotheAlert("Henwo"); // why this not do alert senior halp compiler bugy. i creat isue
You know when you look at the definition of a function in your IDE by hovering over the function name (or seeing it as you type)? That comes from well-structured XML comments.
Javadoc does this while being (kind of) readable in code.
And Rustdoc does this while being perfectly readable in code, since it just uses markdown, and has no conventions like always naming all parameters, which makes a lot more sense anyways.
I code like this sometimes, not when it's a single line, but when there's a lot of if/else imbricated I leave comments about what is done at that point in the code and what needs To be done.
I'm joking. I just thought it was funny to be tagged as "Swift" when it could be so many other languages. TBH I was thinking of the function format (which is nearly universal) but the comment format is a actually lot less common.
Swift isn’t too different in terms of comments to most languages. I’m a really big fan of /// for doc. comments in Swift though, which is a bit different. No xml required!
sometimes, I write comments first to highlight what code I'm going to write, and then do the actual code, when I do that I end up with such comments, because the comment existed before the code
AFAIK in this case the function is being called, not being written, so there's no point in saying this returns void, cause it isn't being assigned to any variable
Maybe, but it usually does more harm than good. It doesn't add any information, and inevitably someone will modify or delete the line without changing the comment.
If you want to visually separate it then a blank line should be enough.
I was thinking the code block above would be ~10 lines long and maybe contain a blank line or two as well. But at that point perhaps the code block should just be a function.
Anyways, of course in most cases a comment like this completely excessive, but I'm just saying that there may be cases where it does provide some value.
Sure in most cases just a blank line works fine. But if the code above also has some blank lines, then a comment would visually distinguish this as a new block where a blank line would not.
It's one extra thing for a dev to read and maintain
Any time you have to interrupt your thought process for mentally processing another thing, that's stopping progress. I bet every dev who reads it goes "why is that comment even there", their thought process is interrupted.
It's a small detail, but details matter. Care about your work, be intentional with your craft. Don't leave clutter that doesn't need to be there
Code efficiency is not the only important part of writing code
12
u/pmarkland Sep 05 '21
If u didn't comment that, I would've thought showAlert() is going to alert me about an upcoming show. So good job!!!
6
u/StochasticTinkr Sep 05 '21
Honestly, I feel like this style of commenting is school's fault. They teachers often want this type of comment so they can be sure that the students understand what they wrote, but it is definitely NOT helpful in non-academic settings.
It's one of the first things I try to unteach newbies in the field.
69
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 05 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
4
u/TopDivide Sep 05 '21
Happens to me way too often. Usually I write the logic as a sequence of comments and then fill the gaps with code. I don't always delete the comments...
3
u/Few_Importance_7615 Sep 05 '21
Comments are a lot like signs & labels... They should be clear, concise, and cover the messy details...
That's a tad excessive though... As an aside, I've never understood why some coders seem to have this anti-comment mentality. All it seems to do is cause them and their successors more problems...
196
u/[deleted] Sep 05 '21
Good thing that comment is there so we can know what that function does
2
u/netsutetsu Sep 05 '21
What is "the alert"?
111
u/Knuffya Sep 05 '21
Let me fix this:
9
u/BarryFruitman Sep 05 '21
Fixed it:
4
u/Wafflelisk Sep 05 '21
I have a serious undercommenting problem so stuff like this makes me feel slightly better
1
u/BarryFruitman Sep 05 '21
That's not Swift, it's obviously Javascript. Or Kotlin. Or Ruby. Or Python. Or C#.....
3
u/Dziry Sep 05 '21
sometimes, I write comments first to highlight what code I'm going to write, and then do the actual code, when I do that I end up with such comments, because the comment existed before the code
4
u/Silverwind_Nargacuga Sep 05 '21
It’s better than the alternative
2
u/Oxxixuit Sep 05 '21
Can someone please explain me what this function do it's not enough explicit
/s
2
u/AL1L Sep 05 '21
Shall we alert someone?
4
u/[deleted] Sep 05 '21
It's better to show what the functions returns for example in the comment than redundantly repeating the function name
1
u/Grubzer Sep 05 '21
Does it show alerts?
1
u/heckingcomputernerd Sep 05 '21
Hmm,the floor here is made out of floor
0
u/[deleted] Sep 05 '21
nothing wrong with that really, it might be a bit redundant but i'd consider it a good habit to make a comment for most things
-13
u/mesoptier Sep 05 '21
Sometimes a comment like this makes sense. It can be useful for visually separating the line from another block of code above.
0
u/TheCakeWasNoLie Sep 05 '21
;
0
u/[deleted] Sep 05 '21
[deleted] — view deleted comment
0
u/[deleted] Sep 05 '21
[deleted] — view deleted comment