Engrains the terms and allows conversation easier between programmers. Everybody knows what it means to increment a number, so there doesn't need to be any silent confusion.
It may also just be how they were taught. My professors were taught with punch cards and later COBOL. Python is readable to most. Holes in a card is not.
I grit my teeth and understand excessive commenting isn't for real world development. More as a weird way of paying tribute to those that came before. We're lucky we live in a time where many of the great minds of our field have only died recently, or are still alive. More lucky to live in a time where important terms are named in the language we speak. Least I'm not a med student questioning if a latin tutor would help.
dammit. Meant machine code and then with COBOL, in a sort of joke about how much of an improvement that seems to us now. I made the mistake of believing that comments for punchcards were only written onto the cards, and since COBOL has full lines of comments...
I don't know. I'll go recite Litany of Penance to the Machine God, for my transgression.
From the invention of computer programming languages up to the mid-1970s, many if not most computer programmers created, edited and stored their programs line by line on punched cards. The practice was nearly universal with IBM computers in the era.
A punched card is a flexible write-once medium that encodes data, most commonly 80 characters. Groups or "decks" of cards form programs and collections of data.
Except that in the early days they would manually punch the cards using a reference sheet of instructions. Although that would technically be coding in machine code
When I went to college, we used punch cards (mid-70's). They would basically store one line of code and you might have to continue it on the next card. 80 columns per card, I'm thinking and each column would store whatever they used for a byte at the time (octet?). So, basically a card would hold one line of text. I used them to program in Fortran in engineering school. Most cardpunch machines would "type" the text along a ribbon at the top of the card, so you could actually "read the Fortran" without having to decode the holes. I'm pretty sure the holes were just an ASCII representation or something very similar.
At school, you would write your program down in longhand first (they made keypunch forms for that - you could buy tablets of them at the bookstore). Then you'd sit down at a keypunch machine and punch all your cards. The card "deck" was then submitted to a computer operator who would "run your program." Output was always 14" blue-bar tractor-fed paper off a big line printer. I had a typo in a program once that spit out 250 pages of errors (some things never change, eh?). You were charged by the amount of CPU time you used.
Same process for any language. I wrote some Cyber-360 assembly code with the exact same card input and paper output.
DVD-Video standard specs a virtual machine to process stuff like menu navigation and occasionally oddball video codecs, so I guess technically you can program in DVD. Heh.
Allthough technically then you'd be programming in DVD-Video machine code/assembly, so...
Definitely see your point though. Although to be honest what went on punch cards besides assembler or machine code? Admittedly I'm too young to have ever fed one into a computer, but I have used a card punch, and those are a real pain in the backside. If you were really quick you could fill the whole 80 columns in a minute or two. If you were just starting out you could maybe do 1-5 letters per minute, if that. I cannot imagine coding in a language as comically verbose as COBOL on a keypad not unlike a flip phone without predictive text. At least tell me you had a keyboard...
Although to be honest what went on punch cards besides assembler or machine code?
Technically anything. Punch cards really don't care what's stored on them, all they do is tell the reader some string of figits. Many punch cards were use to store inventory measurements for example, or some were used to store employee ID numbers for timetracking, or sometimes they were used for registration systems. There are plenty of non-programming uses for them.
For programming however, COBOL, FORTRAN, and BASIC (at universities) were the primary common languages, aside from various flavors of ASM and machine code, and then some proprietary or obscure ones (JCL and APL come to mind). COBOL was favored for its batch processing abilities; it can be very well optimized to perform small and simple calculations on huge volumes of data, very useful for businesses and banks especially, and one of the reasons the IRS still uses it today (it was also liked because it was designed to be readable (or at least "readable"), so a non-techy business manager could still grok some of it at a glance). FORTRAN was easy to optimize in general, and was favored for scientific uses; running simulations especially. BASIC was popular for teaching people to learn to program, which was quite an expensive endeavor in the 70's.
As to how people typed that, I'd imagine with truly amazing skill. Keyboards were a lot nicer back then, but yeah, errors usually meant retyping the card. For every few programmers, there was usually a supervisor whose job it was was to check the cards from each programmer and verified they were correct, and if not, send them back if there were typos or obvious flaws. Given how expensive computing time was, and how loud and messy the machines could be, there was probably a lot of stress on the operators, which only increases my admiration for them. The biggest savior was probably the technical limitations; even the most advanced mainframes usually only had a few paltry kilobytes or later megabytes of RAM, so the programs you could write by design were very simple. Usually they were just to automate one particular calculation, or sometimes used to tabulate long lists, so the programs usually didn't have to be long and complex (by our standards).
Admittedly I'm too young to have ever fed one into a computer
Me too :) I have a special passion for these machines though, and someday I'd love to get involved in restoring one and pairing it with a teletype or two, maybe as a group project since it's rather infeasible for one person to do it. It's a period of computing history that usually gets very little attention, sadly...
Meanwhile, my policy as a TA: If there are no comments whatsoever, I might dock a point. But otherwise, if it's self-documenting and written clearly enough that I can understand it, that counts as documenting your code.
So much work there. It loads the line from memory at the position of the program register, finds location the variable from the table, loads that into memory. Have the arithmetic unit do a calculation, find where it should go, put it back, increment the program counter. (My terminology is probably a little off. I don't usually delve this deep)
/* //Start of multi line comment //Part of Multi-line Comment
//Empty line //Part of Multi-line Comment
---------------------------- //Top of box //Part of Multi-line Comment
| | //Box //Part of Multi-line Comment
| Written by Windows-sucks | //Box //Part of Multi-line Comment
| | //Box //Part of Multi-line Comment
---------------------------- //Bottom of box //Part of Multi-line Comment
//Empty line //Part of Multi-line Comment
*/ //End of multi line comment //Single Line Comment
//Empty line //Single Line Comment
if //If the following condition is true //Single Line Comment
( //Opening parenthesis //Single Line Comment
1 //One //Single Line Comment
+ //Plus //Single Line Comment
1 //One //Single Line Comment
== //Is equal to //Single Line Comment
2 //Two //Single Line Comment
) //Closing parenthesis //Single Line Comment
{ //Opening curly bracket //Single Line Comment
i //Counter //Single Line Comment
= //Gets set to //Single Line Comment
i //Its current value //Single Line Comment
+ //Plus //Single Line Comment
1 //One //Single Line Comment
} //Closing curly bracket //Single Line Comment
//Empty line //Single Line Comment
I know the whole thing can be rewritten as i++ because 1+1==2 will always be true and i=i+1 is the same as i+=1 which is the same as i++, but this is more verbose.
I think your teachers should pick up a copy of "Clean Code". The author basically says that you should keep your comment to an absolute minimum. Instead you should focus on making the actual code readable. After being in this line of work for 20 years I 100% agree.
I think part of the reason they make you comment so much in school is to make sure that you understand what your doing and aren't just copy and pasting code.
I haven't read Clean Code but I definitely agree that your code should mostly "speak for itself"
I use comments rarely. Mostly for things which the code is not readable enough, or for things where I had a hard bug and where the comments helped me think through it.
Ironically, this encourages code that takes as few lines as possible, at the expense of readability: the sort of bad practice that they wanted to avoid.
We have to run SonarQube for our builds before we can push them to our QA and Production environments and a lack of code comments is considered a hard stop item that will prevent you from moving forward.
Ugh I've been getting into a new workplace's codebase and this has been my problem. There's comments on everything, but it's utterly worthless. Here's this variable being passed in called the cryptor, documentation comment describes it as "the cryptor variable". Ok, thanks a lot for the context >.< at that point I'd rather you just have nothing there
I've started tinkering w/ the BizHawk emulator, in which main is one line, a call to submain. That function is commented: "[...] keep this code from getting jammed into Main() which would create dependencies on types which havent been setup by the resolver yet... or something like that". So I'm looking forward to working on that.
Oh, and I checked through today paying a bit more attention and yeah, not everything is commented. about 80% of it is and it's not standardized, just very similar. Anything about functions or variables is pretty much useless, with inline stuff being marginally more useful.
Yeah, this is what happens when you have policies mandating comments on all public functions/properties. Lack of good comments is a culture problem with your developers, not a policy problem.
The problem is, after 5 years the code will have changed to Dog but no one updated the comment. Imagine your surprise when you call that function and it starts barking and fetching bones.
I'm always asking myself: Is my commit message adding anything of value to that commit? If I just say what files I changed, it's not. If I say why or how, then we're getting there.
"Comments are a failure to express yourself in code" is way better.
The best programmer could run into a situation where they have to do something weird and counterintuitive, e.g. to work around a library bug. In that situation, you are unable to express that in code and then it's 100% ok to comment.
But if you're unable to express yourself in code a lot or even most of the time, you should probably pick up a book and work on that coding skill.
To expand on this, you not only want comments around code that doesn't make sense straight away. You also want comment around code which actually looks wrong or pointless.
Pointless or wrong looking code is often bug fixes for bugs most devs will never randomly encounter. A formatting issue in the old version of IE the CEO's home computer is running, a bug in a 3rd party API that you need to handle with care otherwise your API requests will start failing as soon as everyone goes home for the day etc.
It would be nice to always have automated tests that will fail if someone removes the bug fix but you can save everyone a lot of time but just putting in a comment that explains the bug and why this blob of weird looking code is necessary.
There's times to leave comments, and you need to learn when but as developers we should push to write self documenting code more than worrying about comments.
"Self documenting code" is a worse buzzword than "blockchain". Everyone says "my code is self documenting" but in reality, it isn't.
Sometimes you need constants, often to have something not exceed a fixed length. That length, however, is because of external limitations. So, for example you have
const int MAX_LENGTH = 10;
It would be nice to know why 10 is the max length. It's much easier to simply put the read in a comment, than to "self document" the code by choosing a variable name like
MAX_LENGTH_BECAUSE_OF_DATABASE_LIMITATIONS = 10;
Also, as the car salesman meme would say: *slaps roof of any programming language* This bad boy can fit so many comments in it!
Thank you. People have been loving to ride the "self-documenting" train for far too long.
Yes, clean and clear code is something that we should all strive for at all times, but that does nothing to imply that comments are inherently a bad thing.
Comments provide supplemental information. If the comment doesn't make something more clear (e.g. "Cat" picture above) then the comment is worthless and adds noise. But if the comment provides clarifying information to the reader (e.g. "cat with anger management issues and a bum left eye") then you're going to save someone else a hell of a lot of time when you're gone and they have to make a fix to your crappy code.
The potential for self-documentation is limited and should not be the prime focus. Make your code clear, and use real documentation to do so when it helps.
Honestly the longer variable is preferred. It tells you everything you need to know at a glance without having to look at the declaration. That comment could always be deleted or never updated. Additionally that name could be shortened to DATABASE_MAX_LENGTH.
The Pragmatic Programmer, Tip #44, "Comments in Code" (p249 in the 1st Ed.).
I also enjoy comments that document where the code came from: if you filched the code from a textbook or a Stack Overflow page, providing your sources is good practice.
I like to use comments as short indicators what is happening in a specific part for a better overview. That way I can e.g. add a comment to a loop and fold that loop in my IDE. That way it takes less space when scrolling and I still can see quickly where in the code I am. But maybe there are some better practices. Do you have a link to a guide for clean code commenting and practices how you can code better so you don't even need to comment this?
This is good because if it’s not labeled someone will eventually just stick a dog there and push it into the repo and no one will know why everything broke. If the comment says “Cat” then it will be caught in the pull request because people will notice the sudden mismatch.
Reminds me of that chapter in One Hundred Years of Solitude where the village is stricken with a disease that makes people lose their memories, so before it's too late they go and label up everything, like "this is a cow, it gives milk" etc.
At my workplace I'm currently on a campaign to stop these needless waste of bytes and lines with each code review I do. This includes overly verbose and redundant comments, like "This function you can see here below does x by y." and "This variable is for z". I know what the comment is _about_, colleagues. I only need an explanation _what_ it does!
I'm a big fan of commenting for a block. Things like:
//The next block of code really shouldn't work at all, and frankly
//I have no idea why it does, but the end goal is that we are
//converting a date written in string form into a loadable kernel
//module that allows the OS to understand slightly mis-spelled
//commands if they at least start and end with the correct letter.
//Support for two-letter commands like "rm" has been delayed
//until I figure out why the hell we are doing this.
Googles cat, opens Encyclopaedia Britannica documentation:
Felis catus, domesticated member of the family Felidae, order Carnivora, and the smallest member of that family. Like all felids, domestic cats are characterized by supple low-slung bodies, finely molded heads, long tails that aid in balance, and specialized teeth and claws that adapt them admirably to a life of active hunting.
Instead of comments I document everything using best available inline documentation tooling. So it's XMLDoc in C#, JSDoc in JS and so on and so on. So IDEs provide help on classes, methods and such. If I use actual comment it's hardly ever anything other than TODO, FIXME or HACK. Again: tooling gives mi nice TODO lists from that. Well, it's 2018, don't pretend it doesn't exist.
If you comment like on the picture, you're a struggling CS student, not a programmer. In that case you should get back to square one and learn basics. Learning to code by randomly changing things in examples may work sometimes, but generally it's an anti-pattern. I admit I used to do it sometimes myself. Like I had a big problem with DefalteStream class usage, until I finally read the friendly documentation and I don't need to comment the fragments like "this is an input stream, UNCOMPRESSED" ;) So learn how it works, then it's obvious and you don't comment it anymore. Comments are for things not related with programming itself. They are reserved for things that are not obvious. If you call a function, it's not obvious what data does it take, and what data does it return. Of course, without reading its source code, and we don't have time for that, do we?
697
u/[deleted] Jul 04 '18
When I was a CS major, we were deducted 10 points for each missing comment. Everybody erred towards commenting everything.
198
u/DefNotaZombie Jul 04 '18
That cat is adorable
143
u/deynataggerung Jul 05 '18
Ugh I've been getting into a new workplace's codebase and this has been my problem. There's comments on everything, but it's utterly worthless. Here's this variable being passed in called the cryptor, documentation comment describes it as "the cryptor variable". Ok, thanks a lot for the context >.< at that point I'd rather you just have nothing there
191
u/TenNeon Jul 04 '18
Cat.
47
u/[deleted] Jul 05 '18
"Updating" - Every git commit message ever
46
u/aquarius_rock_climb Jul 04 '18
we wrote code to autogen comments like, add 1 to x
42
u/swoopae Jul 05 '18
Cat cat = new Cat(); // This is a cat.
37
u/_Schroeder Jul 05 '18
//This is a comment to comment my once uncommented code
"Damn, I'm good at my job"
51
u/nayadelray Jul 04 '18
comments are useless if the
catcode is pretty8
u/-xtremi- Jul 05 '18
Well, how else am I supposed to remember that is not a dog?
7
u/apathy-sofa Jul 05 '18
http://secretgeek.net/image/larson-oct-1987.gif
22
u/fakefred0 Jul 05 '18
Oh god! I always thought this creature was a dog! Thanks commenter!
5
u/[deleted] Jul 05 '18
nobody wants to talk about how soft and adorable that cat looks
9
u/[deleted] Jul 05 '18
The label would be even more like a code comment if it said “kitten”.
18
u/Kinglink Jul 05 '18
And that's why I disagree with coding comments.
There's times to leave comments, and you need to learn when but as developers we should push to write self documenting code more than worrying about comments.
6
u/eddietwang Jul 05 '18
"Well I know what the fuck it does, why do I have to write it in English if it's in Java, RIGHT. THERE."
3
u/Albino_Smurf Jul 05 '18
You never know when you're writing it if it's as clear as it seems when you're writing it.
4
u/cyrand Jul 05 '18
This is good because if it’s not labeled someone will eventually just stick a dog there and push it into the repo and no one will know why everything broke. If the comment says “Cat” then it will be caught in the pull request because people will notice the sudden mismatch.
4
u/OishiiYum Jul 05 '18
Commenting is especially important when other people are reading them like working in a team of programmers.
When I worked with groups, it was frustrating to have to translate my group members code on top of having to consolidate mine with theirs.
2
u/[deleted] Jul 05 '18
man cat
2
u/Arancaytar Jul 05 '18
2
u/Dazza93 Jul 05 '18
I mean as long as extends Feline then I'm happy
2
u/Gamma8gear Jul 05 '18
5 years later “Wtf was this cat for... wtf is a cat?”
2
u/trin123 Jul 05 '18
All uppercase
That means: if you remove the cat, you lose the network connection, since the tail acts as cable replacement
2
u/xSaraswati Jul 05 '18
Its look like C++ labels LOL
2
u/xShinryuu Jul 05 '18
Cat cat = CatFactory().getCat();
2
u/JonnyRocks Jul 05 '18
I tell people: I don't want you to tell me what, tell me why.
2
u/[deleted] Jul 05 '18
The other 10% would say "kitten" and be several years out of date.
1
u/ivanjermakov Jul 05 '18
//comment1
u/bubleye12 Jul 05 '18
Unless it's a project, most of my comments are either to do's or a combination of swearing and confusion at working code.
1
u/minkbag Jul 05 '18
You should ask: Why cat?
1
u/Plazmaz1 Jul 05 '18
2% of code
1
u/[deleted] Jul 05 '18
I need that cat in my life. Way too adorable.
1
u/[deleted] Jul 05 '18
Not in my experience. I find comments saying Cat but in actuality it's an Antelope.
1
u/gtfovinny Jul 05 '18
Not to be confused with a rabbit
1
u/ace1309 Jul 05 '18
When you code comments more than actual code
1
u/pinguz Jul 05 '18
Reminds me of that chapter in One Hundred Years of Solitude where the village is stricken with a disease that makes people lose their memories, so before it's too late they go and label up everything, like "this is a cow, it gives milk" etc.
1
u/cratering Jul 05 '18
// arrange
// cat
// assert
1
u/I_AM_GODDAMN_BATMAN Jul 05 '18
I blame whatever the fuck linter we use. There's a dozens of them apparently.
1
u/joakim199 Jul 05 '18
Does all coders love cats?
1
u/CC_Tyrant Jul 05 '18
Or 100% of my GCSE coursework code
1
u/OKB-1 Jul 05 '18
At my workplace I'm currently on a campaign to stop these needless waste of bytes and lines with each code review I do. This includes overly verbose and redundant comments, like "This function you can see here below does x by y." and "This variable is for z". I know what the comment is _about_, colleagues. I only need an explanation _what_ it does!
1
u/dev_kr Jul 05 '18
Rest 10% is for omitting printfs for debugging
1
u/Rubber_Duckies_Dong Jul 05 '18
//TODO Cat? CAT! K I T T Y ! ! !
1
u/voicesinmyhand Jul 05 '18
I'm a big fan of commenting for a block. Things like:
1
u/rhbvkleef Jul 05 '18
Warning: unnecessary use of cat at 12:18. Run "blt -f cat.sh --fix 12" to fix.
1
u/Boh00711 Jul 06 '18
/* -+-+-+-+-+-+-+-+*\
* This is a cat
* Boh00711 20180405
\* -+-+-+-+-+-+-+-+*/
Cat Cat { get; set; } = new Cat();
1
u/NinaBarrage Jul 11 '18
"I don't need to tell you what a cat is, right?"
"Haha, of course not"
Later: "Shit, shit, what the hell is a cat?"
Googles cat, opens Encyclopaedia Britannica documentation:
"Well, shit..."
0
u/[deleted] Jul 05 '18
I don't believe in comments. If it was hard to write it should be hard to read
1
u/SpriteV1 Jul 05 '18
I think we have the same label maker.
1
u/FriesWithThat Jul 05 '18
The comments should tell your colleagues or future self why that is a cat, not how that is a cat.
1
u/[deleted] Jul 05 '18
Instead of comments I document everything using best available inline documentation tooling. So it's XMLDoc in C#, JSDoc in JS and so on and so on. So IDEs provide help on classes, methods and such. If I use actual comment it's hardly ever anything other than TODO, FIXME or HACK. Again: tooling gives mi nice TODO lists from that. Well, it's 2018, don't pretend it doesn't exist.
If you comment like on the picture, you're a struggling CS student, not a programmer. In that case you should get back to square one and learn basics. Learning to code by randomly changing things in examples may work sometimes, but generally it's an anti-pattern. I admit I used to do it sometimes myself. Like I had a big problem with DefalteStream class usage, until I finally read the friendly documentation and I don't need to comment the fragments like "this is an input stream, UNCOMPRESSED" ;) So learn how it works, then it's obvious and you don't comment it anymore. Comments are for things not related with programming itself. They are reserved for things that are not obvious. If you call a function, it's not obvious what data does it take, and what data does it return. Of course, without reading its source code, and we don't have time for that, do we?