borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Disable Window Key)Next Topic (Embed flash in VB form?) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Remarks?
Poster Message
Shock
Level: VB Lord


Registered: 30-03-2003
Posts: 150

icon Remarks?

Back in my Qbasic (and Basic) days. i never used remarks. it was a bitch to go through every line of code and write down what it did just so ill never forget. I usually dont. I make my programs so obviously constructed that anyone can understand what im doing.

but the question is, should i comment on every single line i code? whats the use of it, noone else is coding with me?

but every single professional programmer tells me remarks are worth twice their weight in gold. im not sure exactly why _extensive_ (read: extensive) commenting is neccesary, or even usefull. so whats this all about?
PS: I only put in remarks when i code something very ingenious.

[Edited by Shock on 22-04-2003 at 12:26 AM GMT]

22-04-2003 at 12:25 AM
View Profile Send Email to User Show All Posts | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Remarks?

Why are comments important?

Good Question.

Besides the obvious "all IT staff must fully comment code"...IMO comments are necessary to show your reason for direction - how/why you did something the way you did or rather how/why you're going to do something a certain way. I don't have to tell you that there's always more than 1 way to satisfy an objective programmatically. Any deviation from the norm ("ingenious" programming methods), and oftentimes a standard routine, should be documented so others can tell what/why/how...not to mention so you yourself can tell. Maybe it's all my burnt brain cells , but I can't remember half the code I wrote 6 mos. ago.   

____________________________
Eggheads unite! You have nothing to lose but your yolks.

22-04-2003 at 02:26 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: Remarks?

Try debugging an application that's around 1000 pages of code (or a few hundred thousand lines of code) that has under 100 comments.

Comments being like:
' Step 1
' Step 2
' Loop through data

Not every line needs to be commented, many things would only really need commenting at the top (ex: the purpose of the routine), or within a loop with multiple if elseif statements. Basically for what the condition is if true/false whatever, just so it's completely clear.

A lot of commenting depends on how simple a program is, or how it's designed. Enums, Types, global variables are very good places that comments are needed (just so it's clear to people debugging it in the future, or you months/years later).

There are many situations that would call for comments, others will certainly post, but here are a few examples (note: this doesn't actually do anything, and might be missing a () or 2, but just for an example).


Private Function CalculateDistance() as Double
    Do
        DoEvents
        Distance=(((Distance+Sqr(Distance^2E34))/CoordsXYZ) MOD 2)) *24.585673+Distance/(1/3) + 24*365*c
    Loop Until Distance >= c^c
    CalculateDistance=Distance
End Function

' What does the above do? How long would it take to remember exactly why it's done?

Public Const c = 300000000 ' Speed of light - rounded, actual 299,792,458 m/s


Most code that I write makes sense without too many comments, granted I have large variable/routine names. Others while it makes since to me, it only does since I know what's intended - and only to others if they know what it's supposed to do.





____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

22-04-2003 at 02:32 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: Remarks?

if i may add...

i agree that leaving comments is a tedious task, especially if you want to comment properly.

BUT, heavy commenting is not good practice, it is discipline.

like others might say as well... sometimes even the simplest code can be forgotten in time.

when i code programs for other people, i leave heavy comments, especially when they might have a different way of coding from me.

when i code for myself, i leave just as much heavy commenting too.

one reason why employee type programmers have to leave heavy commenting on their part is so that when their programs have to be updated, or if they leave work unfinished, or if they are working in a team, then it is very important that you do not leave your work only understandable to you. responsibility perhaps is the word?

everything i have said is just my opinion. no offense to anyone, okay?  

____________________________
Been busy trying to take a second degree <--it's not working out...

23-04-2003 at 06:01 PM
View Profile Send Email to User Show All Posts | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: Remarks?

Just give my opinion. Unless the code is going to be over 200 lines do NOT comment it until you have done it all and you are sure that you aren't going to just scrap the project and start again. This is to ensure you don't wastle loooads of time doing it.

That is assuming that you aren't part of a team and this isn't work you are being employed to do. If you are being employed or are part of a team then you NEED to comment at the start of every set of variable declarations, loops etc.

And if you have a LOUSY memory like i do, as i struggle to remember what i did a few seconds ago, just comment it all, comment about the blank lines if you have to, comment, comment, comment.

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

24-04-2003 at 08:04 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: Remarks?

This will sound strange to some of you, but I actually comment programs as I code even if it's a few line thing. Of course, not detailed stuff, just general comments. Meaning that when doing a loop, I'll instinctively comment what it does before writing the loop.

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

24-04-2003 at 09:20 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: Remarks?

You gotta remember JL, that you have loads more programming experience than certainly me and probably many others. I only have like 1-2 years of programming experience. And different people have different methods of doing everything.

BTW. how long have you been programming?

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

24-04-2003 at 09:40 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Shock
Level: VB Lord


Registered: 30-03-2003
Posts: 150
icon Re: Remarks?

it may sound weird but ive been programming ever since i was 7. I started on my grandfather's PCjr., which the default startup was something like BASIC version j.

I guess all these years of instinctive programming (like I program like people write books...I just know what to do) made it unneccesary for me to remark everything. Its like when learning to do something, you just make a mental note "this does this" and i remember.

What really gets me tangled up is VaRiAbLeS. they give me a headache, like how I wrote it. In my youth all i did was make RPGs, since they could be mostly text and pretty much all of the coding you do is readily apparent. You can imagine having a million varialbes that all look the same like HP, H.P., Hitpts. and Hpoints (if your wondering HP is current hp holder for battles and the like, H.P. is the constant hp when not in battle, Hitpts. would be hit points AFTER applying bonuses from items and such, and Hpoints would be a seldom used variable lets say if i used an item that would last a time). As you can see the confusion becomes very obvious. so variables, as much as i hate to comment on 500 variables, IMO its the only really important remarks. Most other coding can be understood by reading it, variables cannot.

But thats just me. When i write essays and the sort I just sit down and type a thousand words. when I code i usually just type and type, without a plan or the such. I used to use remarks for planning, such as

fight:
do
if time = true then DOTURN
loop
doturn:
'input turn code here
goto fight

but even later on i found it very unneccesary, by using subroutine names such as HUMANPLAYERTURN, or by using extended varialbes such as BASEHITPOINTS or the sort.

but everyone has their own personality, and i repsect people who can super-organise everything they do and make very few mistakes. I guess it depends if your programming professionaly or as a hobby.

25-04-2003 at 02:56 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: Remarks?

I've been programming since about 1982 or 1983 I believe... After so much time, you kind of forget. But it was during the 8088 processors as the top of the line stage, a little while before the "fast" 286's came out.



____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

25-04-2003 at 03:51 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Shock
Level: VB Lord


Registered: 30-03-2003
Posts: 150
icon Re: Remarks?

the PCjr is equipped with a 086 processor (or the equivalent of one). one learns patience

25-04-2003 at 04:01 AM
View Profile Send Email to User Show All Posts | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: Remarks?

wel, same with JL... i do comment as i go along my coding...

i'd rather not go back just to comment, especially when i'm on a roll.... my problem is, that when i'm on a roll, i actually go programming for about 3-4 straight... and i mean non stop... so, i comment all the time... especially when it comes to declaring variables... i have to mention why it's dimmed as single, or double... especially when i code for other people...
that has been the number three question asked since i programmed for other students.



____________________________
Been busy trying to take a second degree <--it's not working out...

25-04-2003 at 08:08 AM
View Profile Send Email to User Show All Posts | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Remarks?

hhhmmm...pcJr...had one of those...but my first was a  Commodore 64 of my very own (I even had the hot new peripheral, the 3 1/2 floppy drive....ooooooohhhhhhh - still got it all too). Back then the only remarks I wrote were subroutine headings, even though I was doin stuff like machine language and a lot of Pokes/Peeks that really could've used comments. Now, I think my commenting is habit, after having teachers/managers/clients that require it...

[Edited by ~Bean~ on 25-04-2003 at 08:42 AM GMT]

____________________________
Eggheads unite! You have nothing to lose but your yolks.

25-04-2003 at 01:41 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1658
icon Re: Remarks?

My first computer had a 5-1/4in (360k I believe) bay that the entire OS fit on (MS-DOS2.x [thinking 2.11]), it had an optional low density 3.5in floppy (720k) as an expensive upgrade.

One of my first programs was a little murder mystery, exploration of a area using one-two word commands to navigate. It was a few thousand line program... with no comments - anywhere. Not surprisingly, I had to re-write it when I got qbasic (I had no clue what anything was supposed to do, only used a-z for variables too). Also got it down to under 500 lines - with comments.



____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

25-04-2003 at 06:36 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: Remarks?

The first computer i got was when my parents bought it in about 1990 when i was about 2. It was an amiga with a whole 512k of RAM! AmigaBASIC, a totally useless language unless you wanted to make strange sounds out of its almost monophonic sound system or make games with lovely 2D graphics. The only reason we upgraded to a PC was because the TV adapter went bust.

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

25-04-2003 at 06:56 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Remarks?

LMAO!! TV Adapter...LOL...now you're bringing back memories...I actually got the Commodore for Christmas one year - just the Keyboard/CPU (they were all 1 piece)...it had 64K Memory (I only dreamed of having an Amiga). So the Commodore 64 hooked up to TV too, so Dad hooked up the spare/old 35" TV to my new present and I sat at the kitchen table coding. Hah! Which was great cause the first thing I put in was a ball bouncing around the (35") screen - whoopie! But hey, pong was a great game! I didn't get the 5.25 floppy until my birthday in April, what a long four months of losing all my code everytime I power down.
I never did purchase the modem (<1200 baud or something...lol), which was a really big deal back then to be able to get on a bulletin board...

Interestingly enough, the Commodore 64 actually had a suite of office software that was GUI, and it was fairly decent, especially graphics wise, I thknk it was called "Geo-something"...that must've been 1983 or so...

____________________________
Eggheads unite! You have nothing to lose but your yolks.

25-04-2003 at 08:40 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: Remarks?

I reckon the worst thing about them was the keyboard being all-in-one. My return key went after about 1 year so i was left using the enter key every time i wanted a new line which is obviously a pain. My amiga had an inbuilt floppy drive though, thank god! I've gotta say that Robocop was the best game i had for the Amiga, the joystick was awful compared to today though.

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

25-04-2003 at 09:03 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Remarks?

lol...joystick...the C64's joystick was actually quite simple to program - I used my joystick from the Atari 2600 - 8 pin I think.  I had a coupla fav games..."Michael Jordan vs. Dr. J" was awesome and written by EA...another of my favs was a game like JL is talkin about...all text, and you type commands in like "GO Left"..."TAKE Map"...I can't for the life of me remember the name of it but there were a I, II, and III versions...it was kind of like Myst/Riven w/o any graphics...rofl

____________________________
Eggheads unite! You have nothing to lose but your yolks.

25-04-2003 at 09:22 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Shock
Level: VB Lord


Registered: 30-03-2003
Posts: 150
icon Re: Remarks?

I dont know about you guys, but my PCjr. came with exactly 640K of ram...and little else.

no hard drive.

a chicklet keyboard, oddly with a infa-red emmiter so i didnt need a cord (hight of the technology!)

and two (yup, TWO) extra-large medium density, double sided floppy drives.

plus this excruciatingly painful voice synthisiser (?!) attached to the side that could make sounds that almost sounded like words. hey my grandfather DID work for ibm  

but hey those days werent these days when you need a 60GB hard drive and an assortment of softwarehardware to make anything run. back then a kilobite of information was the best game around! not to mention if you held cntrl-something you started the auto-diagnostic routine which was more of a game then anything (keyboard disgnostic: little men running around pushing away the pressed keys, playing pac man to test the mouse...).

But those days were the best. no freezes, no frustration, no anger because no lost information, and no windows to take full advantage of you. Everthing was much simpler back then too...

ok ok *slaps self to disengage overtaking feelings of nostalgia*

25-04-2003 at 09:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: Remarks?

There were SOME crashes with the amiga. Usually when the power supply that was about twice as big as the amiga itself got REALLY hot, but it WAS a very nice flashing red message i got after hours of tapping away!

A lot nicer than the messages we get today. I got one from XP today which said "Your computer has recovered from a serious error", i would've thought that was obvious as my computer had just managed to just terminate its power supply and start up again!

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

25-04-2003 at 09:48 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Remarks?

i love it...what numbnutz coded those MS error messages anyway?

i think it was Bill himself...

____________________________
Eggheads unite! You have nothing to lose but your yolks.

25-04-2003 at 10:19 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: Remarks?

Why did they go and call it eXPerience anyway? Such a piece of Junk, although they have inproved on win ME by miles. Better crash handling, better error message dialog boxes, windows update integration.... I think that kind of sums microsoft up doesn't it? They are still correcting what they should have got right in about 1990 when they bought the first version of winblows out.




NOTICE:
Limitation of liability
I will take no responsibility for my words against Micro$oft Corporation.

[Edited by win_dir on 25-04-2003 at 10:50 PM GMT]

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

25-04-2003 at 10:48 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
SteveG
Level: Sage


Registered: 15-04-2002
Posts: 56
icon Re: Remarks?

Having recently started learning Java the routine of adding remarks becomes second-nature because they form the instructions for using the class via a special sub program.

Also at work I have recently been converting a Q-basic program to VB6, the program being originally written by my former boss who has retired. Whilst he did comment his program they were not helpful and I ended up junking his program and writing the replacement from scratch.

I now always comment programs as I go along especially at the beginning of routines/functions in a module; here is an example -

Sub KvLaminarFlow(Diameter As Integer, KvCalculated As Double)
'***********************************************************
'*  Sub-routine to modify calculated Kv for laminar flow                       *
'*  based on Reynolds number factor FR                                             *
'*  Follows procedure outlined in EN 60534-2-1  Section 8.2                  *
'*  Input:  Valve diameter, Kv calculated for turbulent flow                   *
'*  Output: Kv calculated modified by FR                                             *
'***********************************************************

Whilst it is a pain in the you-know-where comment is an important part of programming in my experience.

26-04-2003 at 07:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Remarks?
Previous Topic (Disable Window Key)Next Topic (Embed flash in VB form?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder