You are not logged in.

#1 2010-03-07 03:21:48

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

I...just...can't...type...COMMENTS!!!

I can't do comments, there's just something wrong with me. I don't document anything unless I force myself, and even then it's not a good comment. Why can't I comment well. Are there tutorials that can help with my commenting? Does anyone else have this problem?


Personally, I'd rather be back in Hobbiton.

Offline

#2 2010-03-07 03:24:31

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: I...just...can't...type...COMMENTS!!!

Comments kinda came natural to me, dunno how to help you there. My problem is coming up with reasonable names for functions and variables. I usually just use really bad function/variable names and make up for it with more comments...

Offline

#3 2010-03-07 03:30:29

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: I...just...can't...type...COMMENTS!!!

Well, what are you commenting? If it's simple code, you likely only need comments if it's doing something non-obvious.

Offline

#4 2010-03-07 03:39:02

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Re: I...just...can't...type...COMMENTS!!!

Well when sometimes when I look back at my code I can't figure out what the heck it's doing. I can't even understand my own code! That's how "non-obvious" it is and that's why I need to learn how to comment.


Personally, I'd rather be back in Hobbiton.

Offline

#5 2010-03-07 03:47:22

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: I...just...can't...type...COMMENTS!!!

You'd think being able to understand your code is incentive enough.
I can't offer any specific advice because I'm one of those people it seems to come naturally to, unfortunately.
It helps to not get into 'coding frenzies', where you write massive volumes of code but can't be bothered with the distraction of commenting.
Also, don't code while tired. It doesn't work.

Offline

#6 2010-03-07 03:50:43

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Re: I...just...can't...type...COMMENTS!!!

Ahh, I am indeed affected by coding frenzies, other symptoms include fits of rage when I get errors and an increase in typing speed.


Personally, I'd rather be back in Hobbiton.

Offline

#7 2010-03-07 03:52:21

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: I...just...can't...type...COMMENTS!!!

Okay. Typing fast generally causes errors. Before starting to code, calm yourself down - take a few deep breaths, eat a bun, whatever. Get yourself comfortable.

Also, test often. Very important. If you write something remotely complex, test it.

What language are you using? Techniques tend to vary between.

Last edited by Peasantoid (2010-03-07 03:53:10)

Offline

#8 2010-03-07 04:00:08

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Re: I...just...can't...type...COMMENTS!!!

Mostly python, but sometimes C and when I code C I always forget parentheses and semicolons and that jazz, probably cuz I'm used to the terseness of python, and ironically I tend to write more and better comments in C than in python.


Personally, I'd rather be back in Hobbiton.

Offline

#9 2010-03-07 04:01:23

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: I...just...can't...type...COMMENTS!!!

Anikom15 wrote:

Mostly python, but sometimes C and when I code C I always forget parentheses and semicolons and that jazz, probably cuz I'm used to the terseness of python, and ironically I tend to write more and better comments in C than in python.

Well it's just so easy to write Python. With C, the increased challenge causes even the most careless coder to think 'wow, wtf does that do? better comment it'.

Offline

#10 2010-03-07 07:29:19

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: I...just...can't...type...COMMENTS!!!

/* Commenting isn't that difficult,
    now is it? */


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#11 2010-03-07 07:33:42

bgalakazam
Arch Linux f@h Team Member
From: California, USA
Registered: 2008-09-01
Posts: 76

Re: I...just...can't...type...COMMENTS!!!

I like to comment things a lot, since looking back at them even a day later, they seem weird. For sections of code I really like:

// ========== foobar begin ==========
CODE
CODE
........
CODE
// ========== foobar end ==========

Last edited by bgalakazam (2010-03-07 07:33:56)

Offline

#12 2010-03-07 08:32:25

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: I...just...can't...type...COMMENTS!!!

Anikom15 wrote:

I don't document anything unless I force myself, and even then it's not a good comment.

Most of us need to force themselves to comment a section of code which initially - while hacking it down - seemed quite logical and intuitive. When I started coding I had to establish a habit to do so as well.

Basically you must mentally train yourself to not leave a section of work whithout going back to the beginning and putting a few words about its use, tricks you needed, etc. It need not be a "good comment" (unless you were trying to distribute your code) but it should serve enough as a reminder.

It took a while to become a habit. But now this became thus natural to me that uncommented code just feels wrong - I have to write add few commenting words about it ...


To know or not to know ...
... the questions remain forever.

Offline

#13 2010-03-07 09:42:21

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: I...just...can't...type...COMMENTS!!!

Anikom15 wrote:

Well when sometimes when I look back at my code I can't figure out what the heck it's doing. I can't even understand my own code! That's how "non-obvious" it is and that's why I need to learn how to comment.

Could it be that your code is too scrambled to be easily documented? When you're writing, try pausing every few lines to think about whether what you just wrote is going to be clear later. If the answer is no, restructure it so that it will be. And if you think you'll need an extra hint after that, put in comments. The trick to writing comments is not to be so specific that a tweak to the program will invalidate the comment—the code is supposed to be your specific description. The meanings of variable names or complicated expressions are good candidates for comments (although a complicated expression can often be put into a function and given a name that way, skipping the comment).

Offline

#14 2010-03-07 14:08:22

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: I...just...can't...type...COMMENTS!!!

My commenting style is to comment data structure and subroutine definitions, and only comment the actual code if it involves deep magic.  I go by the rule that if a sub is hard to understand without line-by-line comments, it's too long and should be broken up into smaller pieces, which can then be documented on their own.

Are you using Python's docstrings?  I use POD with Perl but I haven't written any Python in a while.  Doxygen looks like a good doc system for C.

Offline

#15 2010-03-07 16:20:38

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: I...just...can't...type...COMMENTS!!!

No comments is way better than incorrect comments.  If you do get in the habit of commenting properly, be sure to also get in the habit of updating comments if you update code.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#16 2010-03-07 18:08:33

Yannick_LM
Member
Registered: 2008-12-22
Posts: 142

Re: I...just...can't...type...COMMENTS!!!

Easy: start to write comments before code.

If foo is a complicated function with three arguments, start by writing this:

def foo(a, b, c):
    """Does this and that

     a: ...
     b: ...
     c: ...
 
     1./ First do this
   
     2./ Then that

     3./ And then finish.
     """


     # 1/ This


     # 2/ That


     # 3/ Finish

and then fill the blanks wink

This works specially well if you think about something on the evening but don't have something working quick.
You can write the comments now, re-open this code tomorrow and start hacking.

Offline

#17 2010-03-07 19:17:57

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: I...just...can't...type...COMMENTS!!!

Yes, I think writing comments before code is a good idea. If you can't describe properly what the code is supposed to be doing, then it could well be that you don't completely understand the task.

I think that commenting dynamically-typed languages like Python is especially important. With static typing, you can often figure out what a method does by looking at the return type and the argument types. With Python, Ruby etc. a lot of this information is missing, so it's more important to describe what the method is for, what you should be passing in, what it returns and all the rest.

Once you get in the habit of commenting, you will just end up doing it automatically as a normal part of writing the code. It's a great feeling to stumble upon some old code, expect to have a really tough time working with it, but then you discover that you commented it thoroughly and it's very easy to understand smile

Offline

#18 2010-03-07 19:23:12

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: I...just...can't...type...COMMENTS!!!

Honestly the one thing that got me in the habit of writing comments was writing a serious project in assembly.  Assembly is good for that because if you don't comment something complicated, then in two seconds you'll forget what it does, rather than in two days or weeks.

Offline

#19 2010-03-07 20:40:35

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

Re: I...just...can't...type...COMMENTS!!!

Thx, the commenting before writing sounds like a good idea.


Personally, I'd rather be back in Hobbiton.

Offline

#20 2010-03-07 22:18:24

cmtptr
Member
Registered: 2008-09-01
Posts: 135

Re: I...just...can't...type...COMMENTS!!!

tavianator wrote:

Honestly the one thing that got me in the habit of writing comments was writing a serious project in assembly.  Assembly is good for that because if you don't comment something complicated, then in two seconds you'll forget what it does, rather than in two days or weeks.

Kind of true.  While commenting is definitely necessary in assembly, I found that once I work with assembly enough to used to it and then move up to something like C everything appears so readable that I get lazy with the comments.  tongue

Offline

#21 2010-03-08 01:52:32

Kiwi
Member
Registered: 2008-02-24
Posts: 153

Re: I...just...can't...type...COMMENTS!!!

What is a comment?

Offline

#22 2010-03-08 05:03:47

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: I...just...can't...type...COMMENTS!!!

That obviously wasn't one...


.:[My Blog] || [My GitHub]:.

Offline

#23 2010-03-08 08:32:12

Blue Peppers
Member
From: Newbury, UK
Registered: 2009-02-01
Posts: 178

Re: I...just...can't...type...COMMENTS!!!

My problem is that comments from 3am are usualy a gramatical nightmare, or unrelated to the code.


Consistency is not a virtue.

Offline

#24 2010-03-08 09:26:20

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: I...just...can't...type...COMMENTS!!!

Blue Peppers wrote:

My problem is that comments from 3am are usualy a gramatical nightmare, or unrelated to the code.

Lol, I can imagine...

The same code written at different times:

7pm:

for (int i=0; i<n; ++i)

10pm:

// a nice, friendly for-loop
for (int i=0; i<n; ++i)

12pm:

// a nice, friendly for-loop... maybe I should get some coffee?
for (int i=0; i<n; ++i)

2am:

// coffee coffee coffee coffee coffee coffee coffee
for (int i=0; i<n; ++i)

4am:

// maybr i shuldg et some sleepzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
for (int i=0; i<n; ++i)

Offline

#25 2010-03-08 20:01:44

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: I...just...can't...type...COMMENTS!!!

lol lol lol

On the other hand, even at 10 pm this was no useful comment. Everybody can see it's a loop. The comment should list the purpose of such a construct and what the variables ar meant for. Something like:

// Fetches some coffee on each iteration.
// n has to reflect the working hour when calling this
// (the later the higher).
for (int i=0; i<n; ++i)

To know or not to know ...
... the questions remain forever.

Offline

Board footer

Powered by FluxBB