473,915 Members | 3,941 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Commenting the source code.


Hi,

I know that this is off topic. but I didn't know
where to post.

Do you comment your source code while coding or after coding.

for example:

you write a procedure and after it is working, you'll comment it.

or

you write a line of code and a comment following.
Thanks Profetas

Nov 14 '05 #1
46 2513
Profetas <xu*****@yahoo. com> scribbled the following:
Hi, I know that this is off topic. but I didn't know
where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is working, you'll comment it. or you write a line of code and a comment following.


I generally add a comment every time I finish a piece of code that does
some non-trivial task. I don't have any rules based on actual LOC
metrics but instead count the things that my code actually does, on a
semantic level. Sometimes I write several pieces of code into a single
source file, and only later comment them all, one by one.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Hasta la Vista, Abie!"
- Bart Simpson
Nov 14 '05 #2

"Profetas" <xu*****@yahoo. com> wrote in message
news:ca******** *************** *******@localho st.talkaboutpro gramming.com...

Hi,

I know that this is off topic. but I didn't know
where to post.

Do you comment your source code while coding or after coding.


Sometimes i'll comment after coding.

Sometimes ill comment whilst coding.

Sometimes i'll comment before coding as a "pseudolanguage " to-do-list or
providing a nice general explaination of the algorithm(s) used, pitfalls and
solutions, quirks, oddities and general notes.

As long as the comments are there...
Nov 14 '05 #3
"Profetas" <xu*****@yahoo. com> wrote in message news:<ca******* *************** ********@localh ost.talkaboutpr ogramming.com>. ..
Hi,

I know that this is off topic. but I didn't know
where to post.

Do you comment your source code while coding or after coding.

for example:

you write a procedure and after it is working, you'll comment it.

or

you write a line of code and a comment following.
Thanks Profetas


When write a function I write comments above lines that I think need
them. Later I write a comment that describes the purpose of the whole
function, but I don't do that until after it's done and mostly
integrated because the purpose normally changes slightly when this
happens.
Nov 14 '05 #4
Thanks for the reply.

My theory is that commenting whilst you are coding,
will break your concentration on what you were programming.

If it is something complex.
Does anybody agree?

Profetas

Nov 14 '05 #5
Profetas wrote:
Thanks for the reply.

My theory is that commenting whilst you are coding,
will break your concentration on what you were programming.

If it is something complex.

Does anybody agree?


Not me. My two main points about comments.

1) If something low level needs a comment you are only solving the
symptom, not the problem. Is this absolute? No. Sometimes you need
obscure code for performance issues, though sometimes second guessing
the optimizer kills it. Keyword: Think.
2) Comment the abstraction a function is meant to represent, document
the pre and post conditions, arguments, range, domain and side
effects. Keywords: Detail without verbosity.
And then you have everything else to consider.

--
Thomas.
Nov 14 '05 #6
On Fri, 22 Oct 2004 06:23:28 -0400, "Profetas" <xu*****@yahoo. com>
wrote:

Hi,

I know that this is off topic. but I didn't know
where to post.

Do you comment your source code while coding or after coding.

for example:

you write a procedure and after it is working, you'll comment it.

or

you write a line of code and a comment following.

Before, during, and after :-)

Sometimes I'll write a comment before a block of code to make sure I
have my thoughts in order and know where I'm going. I write comments
as needed during coding, and after coding, I review to see if there
are any clever things I've done in the heat of the moment that I won't
understand next week.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #7
On Fri, 22 Oct 2004 10:23:28 UTC, "Profetas" <xu*****@yahoo. com>
wrote:

Hi,

I know that this is off topic. but I didn't know
where to post.

Do you comment your source code while coding or after coding.

for example:

you write a procedure and after it is working, you'll comment it.

or

you write a line of code and a comment following.


I follow these rules:
- design the whole program
- break down the design to be more specific
- break down each specific design to be more specific
repeat until each problem is broken into peaces lttle enough
to fill only a screen or a bit more
build modules holding a sub problem (of a sub problem....)
check anything. Recheck it again to be sure to have no mistake in
the design
- design the interfaces
even no coding - only design
recheck that them match any request, change if needed
- document anything well

- start filling modules with documented interfaces and empty function
definitions.
let any trunc return one error result (NULL pointer when it has to
return a pinter in result, anything else that presents an error in
other cases)
insert an debug functiion that says that the function is not
realised yet
This gives you the possibility to start
- build the headers and document them
- build the makefile and document it
test the makefile
- write, document, compile and debug debug fuctions.
You needs debugged debug functions to get your debug sessions more
successfully. Whereas successfull means dedect bugs, checks the
wanted results occure.

Now the project can change in its coding phase
- code, low level fuctions
- comment anything logically
that means write comments relayed to the logical funtionality
but NOT to the coding
- check the comment as if it were code for correctness in logic and
flow
correct errors now!
- when the comments are perfect fill each comment (section)
with the matching code. Use the makefile to to test for errors in
typing.
- write short testcase to debug each function. Neends no great
comments as they
are used only temporary to test the fuctions for korrectness
This ends up with well tested very, very low level fuctions. You
knows
that each function does anything as espected - including failture
handling.
- restart at top of this section but one logical level higher
while testing you can use the lower level functions without testing
them
because the prior cycle has done that careful, so bugs are only in
the new code.

Comments are essential for
- finding design bugs before the first code line gets written
- finding bugs while coding (that is why your comment is on logical,
not
coding level anyway
- finding bugs while debugging. Each programmer gets sometimes a bit
crazy
and writes code other than the design says you should.

True, yes, designing of the whole program and all its lower leveled
functions costs a lot of time. But at least spending one day for the
design and checking it saves you a full week and more on coding and a
month on debugging. So spend any time you needs to get your design
perfect. You saves a multiple time of that in coding.

Debug each little fuction extensive. It is your time you wins. Test
each function separately before you goes to the next one. That is
because you can use it later without doubt of an bug inside it. So you
gets higher level functions more quick ready for use.
--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation

Nov 14 '05 #8
Profetas wrote:
Thanks for the reply.

My theory is that commenting whilst you are coding,
will break your concentration on what you were programming.

If it is something complex.

Does anybody agree?


Not I. If your understanding of what you are doing
is so tenuous that it can't survive the attempt to write
it down, the chances that your understanding is correct
to begin with are poor. Brian Kernighan says "Debugging
is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible,
you are, by definition, not smart enough to debug it.”
I take that as strong advice against writing code at the
limits of your comprehension.

Personally (and this is only a matter of taste), I
like to give each function a block comment describing its
purpose, and I write this comment before writing the code.
I also like to put line-by-line comments on important data
structures and variables, and I tend to write those as I
write the declarations. And that's about it: I'll sometimes
go back after the fact and add comments for anything that's
tricky or unclear or unusual, but since I try to follow
Kernighan's advice such comments are pretty rare.

--
Er*********@sun .com

Nov 14 '05 #9
"Profetas" <xu*****@yahoo. com> wrote in message news:<ca******* *************** ********@localh ost.talkaboutpr ogramming.com>. ..
Hi,

I know that this is off topic. but I didn't know
where to post.

Do you comment your source code while coding or after coding.

for example:

you write a procedure and after it is working, you'll comment it.

or

you write a line of code and a comment following.
Thanks Profetas


Depends on what I'm writing and who I'm working for at the time. Some
companies have fairly strict documentation standards. Many don't.

If I'm creating a new file, there's usually a template that I work
from. I copy the template, modify the header as required, then start
writing code. When I'm creating a new procedure, I first create the
doc header for it (name, inputs, outputs, returns, etc., as dictated
by the standards of whomever I'm working for at the time), then write
the procedure body. Within the procedure body, I'll usually write all
the code without stopping, then go back and comment where necessary.
If I'm fixing a defect, I'll first insert a comment with the defect
tracking number, then add the fix, then go back and add to the comment
if necessary (although usually, details of the fix are documented in
the CM and defect tracking tools, not the source -- you can use the CM
tool to view the actual code changes).
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
1322
by: Marian F. | last post by:
The 12 years old genius function to count english words in a sentence: ' This is my function to count english words in your string ' s is the string with your words to be counted ' Returns an integer as the number of words found Public Function iCW(ByVal s As String) As Integer ' We start declaring the variable to count words Dim c As Integer ' This is the variable used in the for next loop ' to check every char in your string s
8
1871
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments... *************************/
2
1092
by: RYoung | last post by:
Can someone point me to a reference concerning source code commenting with VB 2005, ala C# commenting? I googled and found alot of links to add-ins and commercial products, but I can't find any info on whether documentation generation is supported with VB 2005 using xml comments. Thanks, Ron
100
4798
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to use comments. Thanks in advance! -- http://www.gotw.ca/resources/clcm.htm for info about ]
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11359
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5944
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3370
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.