%3CLINGO-SUB%20id%3D%22lingo-sub-1535675%22%20slang%3D%22en-US%22%3EThe%20Importance%20of%20Comments%20in%20Data%20Projects%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1535675%22%20slang%3D%22en-US%22%3E%3CP%3EProject%20management%2C%20scientific%20experimentation%20and%20software%20engineering%20all%20have%20at%20least%20one%20component%20in%20comment%3A%20documentation.%20Without%20the%20basic%20concept%20of%20transferring%20the%20knowledge%20of%20a%20given%20operation%20from%20the%20author%20to%20the%20reader%2C%20projects%20of%20any%20nature%20are%20doomed%20to%20become%20a%20maintenance%20issue%2C%20with%20potentially%20devastating%20results.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20Data%20Projects%2C%20we%20have%20an%20interesting%20issue%20with%20this%20documentation.%20Whilst%20the%20project%20plans%2C%20software%20specifications%20and%20so%20on%20are%20well-defined%20and%20mostly%20consistent%20in%20nature%20and%20delivery%20method%20(such%20as%20a%20Microsoft%20Word%20document)%2C%20comments%20within%20the%20code%20for%20a%20given%20component%20are%20not.%20Different%20languages%2C%20platforms%20and%20other%20constructs%20make%20consistency%20more%20challenging.%20This%20can%20become%20a%20huge%20issue%20when%20the%20calling%20or%20receiving%20component%20needs%20to%20rely%20on%20the%20operation%20of%20the%20other%20component.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20state%20the%20obvious%3A%20At%20the%20very%20least%2C%20you%20should%20comment%20your%20code%20with%20complete%2C%20informative%20information.%20It's%20up%20to%20you%20to%20understand%20how%20your%20language%20or%20compiler%20uses%20comments%2C%20and%20you%20will%20also%20have%20to%20learn%20how%20other%20popular%20languages%20use%20comments%20since%20you%20may%20need%20to%20read%20source%20code%20from%20your%20team.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20I%20learned%20to%20program%20(on%20a%20Mainframe%2C%20several%20hundred%20years%20ago)%20I%20was%20taught%20to%20write%20comments%20detailing%20the%20flow%20of%20the%20program%20%3CEM%3Efirst%3C%2FEM%3E%2C%20and%20then%20go%20lay%20in%20my%20code%20underneath%20the%20comments%20I%20wrote.%20%22Comment-First%22%20coding.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDepending%20on%20the%20language%2Finterpreter%2C%20there%20are%20(usually)%20two%20types%20of%20comments%3A%20%3CEM%3ELine%3C%2FEM%3E%20and%20%3CEM%3EBlock%3C%2FEM%3E.%20A%20%3CEM%3ELine%3C%2FEM%3E%20comment%20is%20indicated%20by%20some%20set%20of%20symbols%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Flanguage-elements%2Fcomment-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esuch%20as%20--%20in%20T-SQL%3C%2FA%3E)%2C%20and%20is%20terminated%20with%20the%20end%20of%20the%20line.%20A%20%3CEM%3EBlock%3C%2FEM%3E%20comment%20uses%20different%20symbols%20to%20%22start%22%20and%20%22stop%22%20comment%20text%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Flanguage-elements%2Fslash-star-comment-transact-sql%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esuch%20as%20%2F*%20and%20*%2F%20in%20T-SQL%3C%2FA%3E)%2C%20and%20can%20span%20multiple%20lines.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20general%2C%20always%20prefer%20Block%20comments%20to%20Line%20comments.%20The%20reason%20is%20that%20lines%20of%20text%20often%20have%20different%20ASCII%20characters%20to%20signal%20the%20%22EOL%22%20or%20End%20of%20Line%20for%20a%20given%20software%2Fhardware%20environment%20-%20Linux%20and%20Windows%20terminators%20for%20instance.%20Take%2C%20for%20example%2C%20this%20unfortunate%20comment%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E--%20Whatever%20you%20do%2C%20do%20not%20run%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E--%20TRUNCATE%20TABLE%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E--%20On%20this%20code!%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E(Yes%2C%20I've%20something%20just%20like%20this)%20If%20the%20%3CSTRONG%3E--%3C%2FSTRONG%3E%20at%20the%20start%20of%20the%20line%20is%20removed%20for%20the%20middle%20component%20by%20some%20accident%2C%20you%20can%20see%20that%20would%20have%20a%20tragic%20result.%20I%20recommend%20the%20comment%20be%20changed%20to%20this%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20Whatever%20you%20do%2C%20do%20not%20run%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3ETRUNCATE%20TABLE%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%26nbsp%3BOn%20this%20code!%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E*%2F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOr%20even%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20Whatever%20you%20do%2C%20do%20not%20run%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3ETRUNCATE%20TABLE%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3E%26nbsp%3BOn%20this%20code!%20*%2F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20way%20you'll%20get%20a%20syntax%20error%20alerting%20you%20to%20an%20issue%20if%20you%20leave%20out%20the%20start%20or%20end%20comment%20symbols.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20an%20aside%2C%20each%20language%20may%20handle%20these%20comments%20differently%2C%20so%20make%20sure%20you%20understand%20how%20they%20work%2C%20or%20are%20even%20stored.%20For%20instance%2C%20in%20some%20SQL%20dialects%2C%20starting%20a%20Stored%20Procedure%20with%20a%20comment%20may%20not%20save%20the%20comment%20in%20the%20Stored%20Procedure%20definition%20(although%20if%20you%20keep%20the%20source%20code%20it's%20there%20of%20course).%20For%20instance%2C%20this%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20Let's%20Create%20a%20Procedure%20to%20deal%20with%20that%20return%20data%3A%20*%2F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3ECREATE%20PROC%20%40ReturnMe%20AS%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E....%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMight%20be%20different%20when%20you%20call%20to%20view%20the%20text%20of%20the%20Stored%20Procedure%20than%20this%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3ECREATE%20PROC%20%40ReturnMe%20AS%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20Let's%20Create%20a%20Procedure%20to%20deal%20with%20that%20return%20data%3A%20*%2F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E....%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20what%20is%20a%20%22Good%22%20Comment%3F%20Well%2C%20since%20I%20am%20%22old-school%22%2C%20my%20comments%20at%20the%20start%20of%20the%20code%20looks%20like%20this%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20%3C%2FSTRONG%3E%3CMYOBJECTORFILENAME%3E%3C%2FMYOBJECTORFILENAME%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3EPurpose%3A%20%3C%2FSTRONG%3E%3CPURPOSEOF%20code%3D%22%22%3E%3C%2FPURPOSEOF%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3EAuthor%3A%20%3C%2FSTRONG%3E%3CAUTHORNAME%3E%3C%2FAUTHORNAME%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3EDate%20Created%3A%20%3C%2FSTRONG%3E%3CDATECODEORIGINALLYCREATED%3E%3C%2FDATECODEORIGINALLYCREATED%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3EEdits%3A%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CDATEEDITEDANDREASON%3E%3C%2FDATEEDITEDANDREASON%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CDATEEDITEDANDREASON%3E%3C%2FDATEEDITEDANDREASON%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E*%2F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20%3C%2FSTRONG%3E%3CCODE%20segmentcomment%3D%22%22%3E%3CSTRONG%3E%26nbsp%3B%20*%2F%3C%2FSTRONG%3E%3C%2FCODE%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3E%2F*%20EOF%20%3C%2FSTRONG%3E%3CMYOBJECTORFILENAME%3E%3CSTRONG%3E*%2F%3C%2FSTRONG%3E%3C%2FMYOBJECTORFILENAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20fact%2C%20for%20Transact-SQL%20code%2C%20%3CA%20href%3D%22https%3A%2F%2Fblog.greglow.com%2F2019%2F02%2F07%2Fshortcut-change-default-text-in-new-query-window-in-ssms%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EI%20use%20this%20handy%20tip%20from%20my%20friend%20Dr.%20Greg%20Low%3C%2FA%3E%20to%20make%20text%20that%20a%20default%20Query%20Window%20in%20SQL%20Server%20Management%20Studio.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOther%20tools%20have%20similar%20constructs%2C%20or%20you%20can%20just%20paste%20that%20in%20OneNote%20to%20use.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIs%20all%20this%20a%20bit%20much%3F%20Yes.%20Until%20you%20need%20it.%20Also%2C%20coding%20my%20comments%20makes%20me%20think%20more%20about%20what%20I%20am%20doing%2C%20and%20slows%20me%20down%20a%20bit%20to%20put%20higher%20quality%20into%20my%20work.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20is%20an%20interesting%20new%20development%20in%20Data%20Projects%3A%20Notebooks.%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fnotebooks.azure.com%2FBuckWoodyNoteBooks%2Fprojects%2FAzureNotebooks%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EI%20use%20Jupyter%20Notebooks%20quite%20a%20bit%20in%20Data%20Science%20work%3C%2FA%3E.%20Jupyter%20Notebooks%20have%20%22Cells%22%20that%20allow%20you%20to%20enter%20either%20Code%20or%20Text.%20The%20text%20is%20usually%20longer%2C%20can%20be%20formatted%2C%20have%20links%20and%20graphics%2C%20and%20can%20be%20quite%20descriptive.%20In%20a%20way%2C%20it's%20like%20a%20hyper%20set%20of%20comments.%20So%20are%20comments%20still%20needed%20in%20the%20Code%20cells%3F%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELike%20most%20Data%20Project%20questions%2C%20the%20answer%20is%20%22it%20depends%22.%20If%20the%20Notebook%20itself%20is%20a%20code%20artifact%2C%20the%20Code%20Cells%20do%20not%20need%20to%20be%20further%20annotated%20-%20that's%20the%20point%20of%20the%20text.%20If%2C%20however%2C%20the%20code%20in%20a%20Cell%20can%20be%20%22extracted%22%20for%20use%20in%20some%20other%20way%2C%20or%20the%20Text%20Cell%20is%20used%20to%20explain%20the%20purpose%20but%20not%20the%20code%20flow%2C%20then%20yes%2C%20comments%20are%20still%20needed.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20stick%20to%20the%20basics%20in%20your%20software%20engineering%20and%20Data%20Science%20work%2C%20and%20ensure%20you%20comment%20your%20code.%20As%20I%20was%20taught%20early%20on%2C%20%22Pretend%20that%20the%20person%20that%20will%20maintain%20your%20code%20is%20a%20very%20easily%20triggered%20person%2C%20and%20knows%20where%20you%20live.%22%20That's%20good%20advice.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1535675%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Buck%20(1).jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F206835i0DB92AFF3A83DDA3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Buck%20(1).jpg%22%20alt%3D%22Buck%20(1).jpg%22%20%2F%3E%3C%2FSPAN%3EMany%20of%20the%20issues%20in%20a%20Data%20Project%20come%20from%20%22Hygiene%22%20-%20the%20fundamental%20technical%2C%20software%20engineering%2C%20and%20scientific%20processes%20that%20form%20the%20fundamentals%20of%20the%20project%2C%20regardless%20of%20scale.%20In%20this%20short%20article%2C%20Buck%20Woody%20pontificates%20on%20the%20importance%20of%20comments.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1535675%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EData%20Science%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EData%20Solution%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHow%20I%20Work%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EProcess%20and%20Procedure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Project management, scientific experimentation and software engineering all have at least one component in comment: documentation. Without the basic concept of transferring the knowledge of a given operation from the author to the reader, projects of any nature are doomed to become a maintenance issue, with potentially devastating results. 

 

In Data Projects, we have an interesting issue with this documentation. Whilst the project plans, software specifications and so on are well-defined and mostly consistent in nature and delivery method (such as a Microsoft Word document), comments within the code for a given component are not. Different languages, platforms and other constructs make consistency more challenging. This can become a huge issue when the calling or receiving component needs to rely on the operation of the other component. 

 

To state the obvious: At the very least, you should comment your code with complete, informative information. It's up to you to understand how your language or compiler uses comments, and you will also have to learn how other popular languages use comments since you may need to read source code from your team.

 

When I learned to program (on a Mainframe, several hundred years ago) I was taught to write comments detailing the flow of the program first, and then go lay in my code underneath the comments I wrote. "Comment-First" coding. 

 

Depending on the language/interpreter, there are (usually) two types of comments: Line and Block. A Line comment is indicated by some set of symbols (such as -- in T-SQL), and is terminated with the end of the line. A Block comment uses different symbols to "start" and "stop" comment text (such as /* and */ in T-SQL), and can span multiple lines. 

 

In general, always prefer Block comments to Line comments. The reason is that lines of text often have different ASCII characters to signal the "EOL" or End of Line for a given software/hardware environment - Linux and Windows terminators for instance. Take, for example, this unfortunate comment: 

 

-- Whatever you do, do not run 

-- TRUNCATE TABLE 

-- On this code!

 

(Yes, I've something just like this) If the -- at the start of the line is removed for the middle component by some accident, you can see that would have a tragic result. I recommend the comment be changed to this: 

 

/* Whatever you do, do not run TRUNCATE TABLE 

 On this code!

*/

 

Or even

 

/* Whatever you do, do not run TRUNCATE TABLE  On this code! */

 

That way you'll get a syntax error alerting you to an issue if you leave out the start or end comment symbols. 

 

As an aside, each language may handle these comments differently, so make sure you understand how they work, or are even stored. For instance, in some SQL dialects, starting a Stored Procedure with a comment may not save the comment in the Stored Procedure definition (although if you keep the source code it's there of course). For instance, this: 

 

/* Let's Create a Procedure to deal with that return data: */

CREATE PROC @ReturnMe AS

....

 

Might be different when you call to view the text of the Stored Procedure than this: 

 

CREATE PROC @ReturnMe AS

/* Let's Create a Procedure to deal with that return data: */

....

 

So what is a "Good" Comment? Well, since I am "old-school", my comments at the start of the code looks like this: 

 

/* <MyObjectOrFileName>

Purpose: <PurposeOf Code>

Author: <AuthorName>

Date Created: <DateCodeOriginallyCreated>

Edits: 

<DateEditedAndReason>

<DateEditedAndReason>

*/

 

/* <Code SegmentComment>  */

 

/* EOF <MyObjectOrFileName>*/

 

In fact, for Transact-SQL code, I use this handy tip from my friend Dr. Greg Low to make text that a default Query Window in SQL Server Management Studio.

 

Other tools have similar constructs, or you can just paste that in OneNote to use.

 

Is all this a bit much? Yes. Until you need it. Also, coding my comments makes me think more about what I am doing, and slows me down a bit to put higher quality into my work.

 

There is an interesting new development in Data Projects: Notebooks. I use Jupyter Notebooks quite a bit in Data Science work. Jupyter Notebooks have "Cells" that allow you to enter either Code or Text. The text is usually longer, can be formatted, have links and graphics, and can be quite descriptive. In a way, it's like a hyper set of comments. So are comments still needed in the Code cells? 

 

Like most Data Project questions, the answer is "it depends". If the Notebook itself is a code artifact, the Code Cells do not need to be further annotated - that's the point of the text. If, however, the code in a Cell can be "extracted" for use in some other way, or the Text Cell is used to explain the purpose but not the code flow, then yes, comments are still needed. 

 

So stick to the basics in your software engineering and Data Science work, and ensure you comment your code. As I was taught early on, "Pretend that the person that will maintain your code is a very easily triggered person, and knows where you live." That's good advice.