Last active
August 29, 2015 14:08
-
-
Save paulghaddad/a130f3807db78e5ba0c3 to your computer and use it in GitHub Desktop.
Level Up 2: Knows the cases where comments are really necessary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So, I lied above obviously. Sometimes comments are actually necessary. | |
Name (and defend) some cases where you should add comments to your code. | |
1. Comments that are intended to be compiled into public API documentation; using | |
rDoc, for instance. | |
2. Rescue an exception that causes nothing to happen. A comment | |
is needed to explain why this is necessary, because it is expected | |
that something should happen when the exception is rescued. | |
Although this can be alleviated by creating a method that is called | |
during the rescue. It's name will explain why nothing is supposed to happen. | |
3. Comments are sometimes needed in tests to explain edge cases. | |
4. Before writing code, comments are useful in writing pseudo-code. | |
But once the code is written, these comments should be deleted. | |
5. Handling oddities of other people's libraries, or the Ruby | |
built-in library, that you have to code around. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment