Web Design Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignWeb Design Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 4th, 2005, 02:09 PM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,249 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 18 m 20 sec
Reputation Power: 17
commenting my code

say i have quite a few pages, and i need to comment them, what should i do with the code that is same in different pages? comment them all or just one instance of it?

further more should i go overboard and do this:

Code:
/////////////////////////////////////////////////////////////
/                     whatever                                     /
////////////////////////////////////////////////////////////


or
Code:
//if statement to get the results
if ($row) {
.......

Last edited by paulh1983 : April 4th, 2005 at 02:39 PM.

Reply With Quote
  #2  
Old April 4th, 2005, 04:25 PM
edwinbrains's Avatar
edwinbrains edwinbrains is offline
Retired Moderator
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2004
Location: London, UK
Posts: 6,670 edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)edwinbrains User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 85411 Folding Title: Advanced FolderFolding Points: 85411 Folding Title: Advanced FolderFolding Points: 85411 Folding Title: Advanced FolderFolding Points: 85411 Folding Title: Advanced FolderFolding Points: 85411 Folding Title: Advanced Folder
Time spent in forums: 1 Week 6 Days 23 h 39 m 19 sec
Reputation Power: 92
I think it depends on the code you're commenting. If it's just a personal project and you'll be the only one to look at the code in the project, I wouldn't bother commenting code which is the same in multiple pages. Just do the one and ignore the others (perhaps add a "see thisfile.php" instead). However, if it's something more important where other people may be looking at your code perhaps it may be better to comment it more fully, so that anyone else looking at your code knows what's happening, without having to start working through every file.

When it comes to actual commenting, I'd go with your second option, I think the first one is overboard. And I probably wouldn't bother commenting obvious statements like "if ($row) {", since I think anyone looking at that should understand what it means.

But it's quite a personal thing I think, so in the end, do what you feel most happy with.
__________________
- Edwin -

The General Rules Thread | The General FAQ Thread

Reply With Quote
  #3  
Old April 4th, 2005, 05:15 PM
balford82 balford82 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 108 balford82 User rank is Private First Class (20 - 50 Reputation Level)balford82 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 19 h 32 m 42 sec
Reputation Power: 4
I try to use variables and functions that tell me exactly what is going on. For instance, if I have a table with user_ids and names, and I want a function that gets a user name given a user id, then i'll name it "GetUsernameFromID()". Makes my life easier, and keeps me from commenting too much. This goes for form names as well, or any attribute that is worth remembering. In fact, I get myself into such a pattern that even with over 50 functions, I make the correct guess 95% of the time.

On the other hand, if you have code that is complicated and worth commenting, take the time to do it. It will make you feel more familiar with it. The more you think about it, the better chance you'll have of simplifying it.

However, if you notice a complicated chunk of code that is worth commenting in multiple pages, I suggest using includes. Of course (from what I understand), you couldn't do this without a scripting language.

My final note: don't forget that comments that might make sense to you probably don't mean much to other coders. It's tough reading someone elses code. I can't do it - ever. So if you are developing with a group of people, come up with some standards.

Reply With Quote
  #4  
Old April 4th, 2005, 05:40 PM
balford82 balford82 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 108 balford82 User rank is Private First Class (20 - 50 Reputation Level)balford82 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 19 h 32 m 42 sec
Reputation Power: 4
Oh yeah, here's a Slashdot thread I bookmarked a few weeks back: a number of people express their opinions and ideas about commenting. You might check it out: Slashdot Thread

Reply With Quote
  #5  
Old April 4th, 2005, 06:14 PM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,249 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 18 m 20 sec
Reputation Power: 17
thanks ppl, the comments are supposed to be put on my coursework. so it is gonna be a one hell of a job going through and repeating myself page after page :yawns:

Reply With Quote
  #6  
Old April 4th, 2005, 06:19 PM
balford82 balford82 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 108 balford82 User rank is Private First Class (20 - 50 Reputation Level)balford82 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 19 h 32 m 42 sec
Reputation Power: 4
Quote:
Originally Posted by paulh1983
thanks ppl, the comments are supposed to be put on my coursework. so it is gonna be a one hell of a job going through and repeating myself page after page :yawns:


I had a professor that was very strict about comments. It was a pain, cause we'd code everything and add them in at the very last minute. Taught me that you have to follow rules in the real world if you want to keep your job.

Reply With Quote
  #7  
Old April 5th, 2005, 05:08 AM
Porky Porky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: England
Posts: 278 Porky User rank is Sergeant (500 - 2000 Reputation Level)Porky User rank is Sergeant (500 - 2000 Reputation Level)Porky User rank is Sergeant (500 - 2000 Reputation Level)Porky User rank is Sergeant (500 - 2000 Reputation Level)Porky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 11 h 15 m 58 sec
Reputation Power: 15
My 2c...

For my latest project (just a personal thing) I decided to comment my code something like as follows:

' ### Section 1.0 ###

Code etc here

' ### Section 1.1 ###

Code etc here

' ### Section 2.0 ###

Code etc...

It might be slightly overboard but I am trying to get a modular design to my code - its only ever going to run on my computer and I want to make sure that I understand what on earth I was thinking when I come to look back on it in a few weeks/months time. I have a Word document that goes with it that explains the arbitary/confusing parts of the code in a bit more detail. I also use it to log error messages I have recieved/could receive in future, and what the solution turned out to be.

Its overkill yes, but it works for me, and as I say, I think I'll be grateful for it when I come to add code in future, and want to get it in the right place!

Happy coding,

Porky

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignWeb Design Help > commenting my code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT