Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-22-2006, 11:39 AM
Sionofdarkness Sionofdarkness is offline
Programming Expert
 
Join Date: Jul 2006
Posts: 385
Rep Power: 10
Sionofdarkness is on a distinguished road
Default Why are comments important?

Since comments don't do anything for the code, what's the purpose of them? I know all languages have them, and sometimes when I view the source code of things I see them, but they don't really say anything useful. I think worrying about them is a waste of time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-22-2006, 05:26 PM
dirkfirst dirkfirst is offline
Programming Professional
 
Join Date: May 2006
Posts: 338
Rep Power: 11
dirkfirst is on a distinguished road
Default

Comments are very important because if you look at your code a month after you create it you'll have no idea what you were doing and why you did it. With comments you don't have this problem. Also, comments are good if you are sharing work with another programmer.
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-23-2006, 09:17 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,047
Last Blog:
NaNoWriMo Summary
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

If the code is self-explanatory, there is no need for comments. Comments are useful for when you are doing something where either the algorithm or the technique is unclear. They are also useful in documenting specifications for functions or classes that someone else will be using. A common thing in programming is to have one person write a library for someone else, and only distribute the headers and compiled library. The person using the library can't see how things work, so must rely on the headers and comments to know what is legal and what isn't for that library.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-25-2006, 08:09 AM
smith smith is offline
Programmer
 
Join Date: Jun 2006
Posts: 108
Rep Power: 9
smith is on a distinguished road
Default

Quote:
Originally Posted by WingedPanther
If the code is self-explanatory, there is no need for comments. Comments are useful for when you are doing something where either the algorithm or the technique is unclear. They are also useful in documenting specifications for functions or classes that someone else will be using. A common thing in programming is to have one person write a library for someone else, and only distribute the headers and compiled library. The person using the library can't see how things work, so must rely on the headers and comments to know what is legal and what isn't for that library.

With that being said, the person using the library couldn't use it unless there were comments. A good programmer always uses comments.
__________________
Code:
for (int i;;) {
   cout << "Smith";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-25-2006, 12:02 PM
Sionofdarkness Sionofdarkness is offline
Programming Expert
 
Join Date: Jul 2006
Posts: 385
Rep Power: 10
Sionofdarkness is on a distinguished road
Default

Alright, I understand. I'm sure it is especially important if you aren't the only person working on the code, because comments could also be used to tell your partner what to do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-25-2006, 05:32 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,047
Last Blog:
NaNoWriMo Summary
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

It's also useful when you pick up code after working on other things for 6 months. There's nothing like looking at code that you KNOW made perfect sense when you wrote it and scratching your head.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-26-2006, 01:13 AM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Rep Power: 10
brackett is on a distinguished road
Default

Just a reminder: Comments aren't only for explaining the code (the how) but also for explaining why the code does what it does (the why).

If you're code isn't ridiculously complicated, it can be read and understood what it's doing...but without a comment, there's no way to know *why* it's doing it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-26-2006, 07:23 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 109
Rep Power: 8
icepack is on a distinguished road
Send a message via AIM to icepack
Default

This is more of a topic for programming theory rather than language specific like Java.


food for thought.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-26-2006, 08:32 PM
ShortCircuit ShortCircuit is offline
Learning Programmer
 
Join Date: Jun 2006
Posts: 34
Rep Power: 9
ShortCircuit is on a distinguished road
Default

icepack is right. Comments are important in ALL coding, whether its HTML, Java, C++ etc - you should comment in everything you do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-27-2006, 05:12 PM
Crane's Avatar   
Crane Crane is offline
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Rep Power: 13
Crane is on a distinguished road
Default

Well, I don't think they are very important in HTML as it is a very easy language to just look and see what is going on.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java:Reference - Proper Comments John Java Tutorials 5 02-04-2007 09:53 PM
Comments? dirkfirst JavaScript and CSS 3 01-19-2007 09:29 AM


All times are GMT -5. The time now is 02:08 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads