I mean, it looks like you were talking through the logic while writing it. Seems superficial and unnecessary at this point, but probably helped you while writing it.
Maybe I'm just deflecting, I definitely do this sometimes. š¤·š»āāļø
My usual methodology is to be liberal with my comments first time around and then a while after I've written the code I'll look back and make it a little tighter
I definitely do this. Especially if itās a really complex function, I will write one comment for each logical step and then write the actual code for it beneath so that I donāt miss anything. Sometimes Iām guilty of committing them without taking another pass at removing them.
It is not. Comments should be avoided where possible. Code should read like a book. Books dont have comments (often).
Let me give an example: instead of commenting a block or line of code. Extract method and name the method to WHAT IT DOES. Then in the case of really strange mathematic things, like ātricksā you could think of adding comments. Normal people dont do tricks like the quake normal trick for example.
Working on a long-running Fortran code base, that breaks abstractions left and right.
Very often I write comments that are several lines long to explain why one line is needed, or all the changes to global state that happen in it, even though the name sounds tame enough.
In college whenever I got stuck on the logic of an assignment I would start to comment the code from top to bottom. Normally saying it in English would help me realize why my logic was wrong.
Even still, there's got to be a deeper meaning than Set animator to 0 worth writing instead
You should check if your array is null and then react appropriately. Rather than assuming it exists and dealing with the fall out via an exception. Exceptions are expensive and shouldn't be part of expected flow. They should be exceptional.
Just as a kind of rule of thumb: Exceptions are unexpected states/events a program, or a small part of a program might run into. If you plan on this event occurring, it's not really an exception anymore. You are basically using the exception as an actual Event, to trigger a fully expected fallback of the program. Exception handling is supposed to be a fallback for when you run in a state you did not intentionally implement.
To put it bluntly, it's an exception to the rules and not a rule itself.
Edit: I hope I got my point across in the last sentence, the first paragraph is rather clumsily put together.
this seems fine tbh. looks like pseudo code you might write out beforehand and you just left it in. sure it's not necessary now but this isn't anything to be embarrassed abou
110
u/tarthim Jan 22 '22
I mean, it looks like you were talking through the logic while writing it. Seems superficial and unnecessary at this point, but probably helped you while writing it.
Maybe I'm just deflecting, I definitely do this sometimes. š¤·š»āāļø
20
u/FallenBlade Jan 22 '22
You should check if your array is null and then react appropriately. Rather than assuming it exists and dealing with the fall out via an exception. Exceptions are expensive and shouldn't be part of expected flow. They should be exceptional.
34
u/[deleted] Jan 22 '22
This hurts me.
34
u/kewlness Jan 22 '22
At least you had comments.
34
u/EquationTAKEN Jan 22 '22
I thought we agreed that a single useless comment doesn't really qualify as "bad code" per se.
21
u/arran_ash Jan 22 '22
Paid by the line xd
17
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 22 '22
Image Transcription: Code
[The image shows a photograph of code on a computer screen, with some lines cut off, as follows:]
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
4
u/[deleted] Jan 22 '22
Yeah, but the rest of comments look awesome.
4
u/AlphonsOwO Jan 22 '22
When you get paid by line:
//Set animator to 0
animator = 0;
3
u/newtons_apprentice Jan 23 '22
fixed
2
u/[deleted] Jan 22 '22
Phew. How would I have known otherwise??
2
u/Dathussssss Jan 22 '22
Oh monogame ! I love this framework !
2
u/MrJZ Jan 22 '22
Better than no commentsā¦
1
u/trevorpogo Jan 23 '22
this seems fine tbh. looks like pseudo code you might write out beforehand and you just left it in. sure it's not necessary now but this isn't anything to be embarrassed abou
1
u/pascalxsome Jan 23 '22
Didn't we all wrote comments like that in the beginning? If even?
Good commenting is something you'll start doing as soon as you're a good enough programmer to get pissed by bad commenting
1
u/propostor Jan 23 '22
Problem here isn't the comments. Actually I think the comments are great.
The problem is the try-catch block in place of an actual null check.
1
u/kristallnachte Jan 27 '22
Everyone has a phase when learning about properly commenting code where they over comment obvious things.
The code should tell you what it does The comment should clarify why it does it.
1
u/BigPryncypalek Jan 30 '22
This is me when our new js teacher asked us to "do an exercise to show what do we know about JavaScript"
1
u/[deleted] Feb 01 '22
you're just like me.