c# ean 13 check digit Java Example of an Ineffective Comment in C#.NET

Encoding EAN13 in C#.NET Java Example of an Ineffective Comment

Java Example of an Ineffective Comment
EAN13 Maker In Visual C#.NET
Using Barcode creation for Visual Studio .NET Control to generate, create EAN-13 image in Visual Studio .NET applications.
www.OnBarcode.com
European Article Number 13 Scanner In Visual C#
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
/* check each character in "inputString" until a dollar sign is found or all characters have been checked */ done = False; maxLen = inputString.length(); i = 0; while ( !done && ( i < maxLen ) ) { if ( inputString[ i ] == '$' ) { done = True; } else { i++; } }
Barcode Creation In Visual C#
Using Barcode generation for .NET framework Control to generate, create bar code image in .NET applications.
www.OnBarcode.com
Decode Bar Code In Visual C#.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
de Complete
Creating EAN13 In .NET
Using Barcode generator for ASP.NET Control to generate, create EAN 13 image in ASP.NET applications.
www.OnBarcode.com
Encoding EAN / UCC - 13 In .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create European Article Number 13 image in .NET framework applications.
www.OnBarcode.com
32. Self-Documenting Code
Painting EAN-13 In Visual Basic .NET
Using Barcode creation for .NET Control to generate, create EAN-13 image in VS .NET applications.
www.OnBarcode.com
1D Barcode Generation In C#.NET
Using Barcode maker for .NET Control to generate, create Linear 1D Barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Page 21
Encode PDF-417 2d Barcode In Visual C#
Using Barcode generator for .NET framework Control to generate, create PDF 417 image in .NET applications.
www.OnBarcode.com
Drawing 2D Barcode In Visual C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create Matrix Barcode image in VS .NET applications.
www.OnBarcode.com
You can figure out that the loop looks for a $ by reading the code, and it s somewhat helpful to have that summarized in the comment. The problem with this comment is that it merely repeats the code and doesn t give you any insight into what the code is supposed to be doing. This comment would be a little better:
Barcode Encoder In C#
Using Barcode creator for .NET framework Control to generate, create bar code image in .NET framework applications.
www.OnBarcode.com
Creating USPS POSTNET Barcode In C#.NET
Using Barcode creator for .NET Control to generate, create USPS POSTNET Barcode image in VS .NET applications.
www.OnBarcode.com
// find '$' in inputString
Encode Data Matrix ECC200 In Java
Using Barcode generator for Java Control to generate, create ECC200 image in Java applications.
www.OnBarcode.com
Barcode Printer In Objective-C
Using Barcode encoder for iPad Control to generate, create barcode image in iPad applications.
www.OnBarcode.com
This comment is better because it indicates that the goal of the loop is to find a $. But it still doesn t give you much insight into why the loop would need to find a $ in other words, into the deeper intent of the loop. Here s a comment that s better still:
Scanning Data Matrix ECC200 In Visual Studio .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Bar Code Scanner In Visual C#.NET
Using Barcode Control SDK for .NET Control to generate, create, read, scan barcode image in Visual Studio .NET applications.
www.OnBarcode.com
// find the command-word terminator ($)
Paint Barcode In None
Using Barcode drawer for Online Control to generate, create barcode image in Online applications.
www.OnBarcode.com
Creating Universal Product Code Version A In None
Using Barcode generation for Software Control to generate, create UPC A image in Software applications.
www.OnBarcode.com
This comment actually contains information that the code listing does not, namely that the $ terminates a command word. In no way could you deduce that merely from reading the code fragment, so the comment is genuinely helpful. Another way of thinking about commenting at the level of intent is to think about what you would name a routine that did the same thing as the code you want to comment. If you re writing paragraphs of code that have one purpose each, it isn t difficult. The comment in the code above is a good example. FindCommandWordTerminator() would be a decent routine name. The other options, Find$InInputString() and CheckEachCharacterInInputStrUntilADollarSignIsFoundOrAllCharactersHave BeenChecked(), are poor names (or invalid) for obvious reasons. Type the description without shortening or abbreviating it, as you might for a routine name. That description is your comment, and it s probably at the level of intent. If the code is a subset of another routine, take the next step and put the code into its own routine. If it performs a well-defined function and you name the routine well, you ll add to the readability and maintainability of your code.
Encode Code 39 Full ASCII In Visual Basic .NET
Using Barcode maker for VS .NET Control to generate, create Code 39 image in Visual Studio .NET applications.
www.OnBarcode.com
Data Matrix ECC200 Decoder In C#
Using Barcode decoder for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
3 KEY POINT
Focus your documentation efforts on the code itself For the record, the code itself is always the first documentation you should check. In the case above, the literal, $, should be replaced with a named constant, and the variables should provide more of a clue about what s going on. If you want to push the edge of the readability envelope, add a variable to contain the result of the search. Doing that clearly distinguishes between the loop index and the result of the loop. Here s the code rewritten with good comments and good style:
Java Example of a Good Comment and Good Code
// find the command-word terminator foundTheTerminator = False;
de Complete
32. Self-Documenting Code
Page 22
maxCommandLength = inputString.length(); testCharPosition = 0; while ( !foundTheTerminator && ( testCharPosition < maxCommandLength ) ) { if ( inputString[ testCharPosition ] == COMMAND_WORD_TERMINATOR ) { foundTheTerminator = True; terminatorPosition = testCharPosition; } else { testCharPosition = testCharPosition + 1; } }
7 Here s the variable that contains the result of the search.
If the code is good enough, it begins to read at close to the level of intent, encroaching on the comment s explanation of the code s intent. At that point, the comment and the code might become somewhat redundant, but that s a problem few programs have. Another good step for this code would be to create a routine called something like FindCommandWordTerminator() and move the code from the sample into that routine. A comment that describes that thought is useful but is more likely than a routine name to become inaccurate as the software evolves.
Focus paragraph comments on the why rather than the how Comments that explain how something is done usually operate at the programming-language level rather than the problem level. It s nearly impossible for a comment that focuses on how an operation is done to explain the intent of the operation, and comments that tell how are often redundant. What does the following comment tell you that the code doesn t
Copyright © OnBarcode.com . All rights reserved.