Comments or no comments | Sololearn: Learn to code for FREE!


Comments or no comments

Self explanatory variable names and methods are as good as documenting the code with comments. True or False?

8/3/2017 5:54:47 AM

John Clinton Mwangi

4 Answers

New Answer


5 Best Practices for Commenting Your Code 1) Comments are not subtitles You may have been taught to program by first writing  pseudo-code comments then writing the real code into that wire-frame. This is a perfectly reasonable approach for a novice programmer. 2) Comments are not an art project ORLY? Does this look familiar? +------------------------------------------------------------+ | Module Name: classMonkey | | Module Purpose: emulate a monkey | | Inputs: Bananas | | Outputs: Grunts | | Throws: Poop | +------------------------------------------------------------+ 3) Header Blocks: Nuisance or Menace? They are enablers for badly named objects/methods – Of course, header blocks aren’t the cause for badly named identifiers, but they are an easy excuse to not  put in the work to come up with meaningful names, an often deceptively difficult task. It provides too much slack to just assume the consumer can just read the “inline documentation” to solve the mystery of what the DoTheMonkeyThing method is all about. 4) Comments are not source control The programmers involved in the evolution of this method probably checked this code into a source control system designed to track the change history of every file, but decided to clutter up the code anyway. These same programmers more than likely always leave the Check-In Comments box empty on their commits. Another feature of any tool that has any right to call itself a SCM is the ability to recover old versions of code, including the parts you removed. If you want to be triple super extra sure, create a branch to help you with your trust issues. 5) Comments are a code smell Comments are little signposts in your code explaining it to future archaeologists that desperately need to understand how 21st century man sorted lists of purchase orders. Technique 1: Use meaningful identifiers and constants (even if they are single use) Technique 2: Use strongly typed input and output parameters Credits: Code Complete by Steve McConnell.


Ya empece con print y puts pero como inicio un programa o una hoja o en donde es el inicio



you do yourself a favour when making extensive use of comments. if not for your now-you then definitely for your in-one-year-you