|
-
Aug 16th, 2000, 08:49 PM
#1
I hate it when I download a sample(from planet-source-code or something) and the code is really badly formatted,
for example, Variables are left un-declared, variables arent names right, and when the code is not indented.
I know they are spending there time to give people code samples, but if my code was formatted badly like that, I would not even submit it until it was cleaned.
it is hard to read, and most of the time its ugly,
I always make my code perfectly formatted, it may not be the best, or the most well commented but it looks nice and is easy to read..
for example.
Code:
For dumbvar = 0 To 10
If dumbvar = 1 Then
MsgBox dumbvar
End If
Next dumbvar
'and
Dim Counting As Long
For Counting = 0 To 10
If Counting = 1 Then
MsgBox Counting
End If
Next
now this is a small demo and it doesnt make that much difference, but when you start getting into really long code, that is when it starts to get very hard to read.
I want to know who else finds this really annoying.
-
Aug 16th, 2000, 08:55 PM
#2
Hyperactive Member
i agree escpecially sience im still learning and it can just make things more complicated than they have to be.
Matt 
-
Aug 16th, 2000, 09:00 PM
#3
Addicted Member
I'm with you on that one denniswrenn, theres nothing i hate more than code that isn't indented properly or code that is indented inconsistently.
i've worked on code where in the same Sub the indent has varied between 1 and 4 characters...
but i'm sure others have even worse "battle tales"
-
Aug 16th, 2000, 09:02 PM
#4
I know I might sound like an "old timer" but when I first started learning, I didnt know of vb-world,
and I had to teach myself the basics of VB, which was hard after only knowing HTML and Javascript,
I think all you newbies who are learning from people like kedaman and megatron, and sam, and me(although i dont answer as much as they have) are really lucky..
<ahem> back to the subject,
I also dont like it when people dont capitalize the variables,
I dont know why, it just looks a lot better when capitalized(not the whole variable, just the key letters, like if I was making a variable that I was using the find the hwnd I would name is MyHwnd or ObjectHwnd)
ok,
thats 'nuff of my complaining for tonight, I wanna here your complaints <points finger like uncle sam on army posters>
-
Aug 16th, 2000, 09:19 PM
#5
Frenzied Member
I'm still battling through the law suit on those Army posters (Apparently I can't sue because of some dumb law that say's you Can't copyright your own name and they're using some obscure technicality about the posters being printe 60 years before I was born)
I hate trying to get through hard to read code but it's something you've gotta do, I use Serges addin that indents the code for you and use the autoreplace to give variables sensible names.
The trouble is if you teach yourself to code It's really hard to know what proper coding should look like, and it's really hard to comment properly until you get into the habit.
Then you get into good habits, try VBScript and you have to go back to leaving next lines unqualified and declaring typless variables (when you just say Dim a and it gives you a variant) (sorry if this is unclear but I was trying to not split infinitives)
It's always going to be a problem and you can't blame the people who do it, my code was terrible when I first started, and it's only through providing code here that I've finally got into the habit of commenting properly.
-
Aug 16th, 2000, 09:32 PM
#6
Addicted Member
Sam,
you speak of Serge's addin - what is this - it sounds good...
also, briefly what is the autoreplace?
thanks,
-
Aug 16th, 2000, 09:45 PM
#7
Frenzied Member
I'll see If I can Dig up Serges Addin For you, basicly it goes through your project and indents your code (puts tabs into If blocks etc) I'll Se If I can dig the files up (Or I might have still the Email it came on)
The autoreplace is when you press Control + h and can replace a prticular word al through your code, so If someone calles a variable a that I want to be called lngNumberOfPlayers I just replace " a " with " lngNumberOfPlayers " and voila, sesible variable names. Then I go through adding comments if neccaserry.
I do still have the original Email BTW so f anyone wants it just post the address up and I'll forward it.
-
Aug 16th, 2000, 10:21 PM
#8
I used to have it but I reformatted and lost the email,
I would like to have his add-in
[email protected]
thanks,
PS:
I use autoreplace if I have a lot of publicly declared API's (like if I forget to switch the option on the api viewer ) in a private module(IE: Form) I just use the autoreplace.
but I usually name my variables properly from the beginning,
it takes a little more typing, but what the hell I am only 65 WMP I need to improve a little 
-
Aug 16th, 2000, 10:27 PM
#9
Addicted Member
Thanks Sam,
[email protected]
thanks again...
-
Aug 16th, 2000, 10:35 PM
#10
Frenzied Member
Dennis, I only use autoreplace and serges addin if I'm dealing with other peoples code, If I'm doing myown code I use good names, tabs and comments from the start.
I'll mail the addin a bit later In case more people want it, I don't wanna have to keep sending it on, I'd rather do it all in one go.
If it wasn't for this sentence I wouldn't have a signature at all.
-
Aug 16th, 2000, 10:55 PM
#11
Dennis, I only use autoreplace and serges addin if I'm dealing with other peoples code, If I'm doing myown code I use good names, tabs and comments from the start.
I never comment, I hate commenting... I dont know why though.
I think what I like most about Visual Basic is its autocapitalize feature,
you have a variable named MyVar
and you type in myvar hit enter and bam! correct capitalization!
-
Aug 16th, 2000, 11:00 PM
#12
Addicted Member
Dennis, yeah, the auto capitalisation is cool, I use it as a way to check that i have spelt the variable correctly, because i always use one capitals in my variable names and then when you type it and press enter if it is still all in lowercase you know that you've made a mistake.
handy really...
-
Aug 16th, 2000, 11:09 PM
#13
Addicted Member
any chance I can have a copy to?
[email protected]
I never really indent my code, its a bad habit I know but just never remember to do it, so this addin could come in handy.
I never really comment my code either as I write it, I should though as if I am giving the code out, I have to go through afterwards and comment it, and usually I have forgotten off the top of my head what a particular line of code does, and have to pick it a part to remember.
as for capitalising, I usually do that for the keywords, unless I am in a rush to get something done.
-
Aug 16th, 2000, 11:11 PM
#14
Dennis, yeah, the auto capitalisation is cool, I use it as a way to check that i have spelt the variable correctly, because i always use one capitals in my variable names and then when you type it and press enter if it is still all in lowercase you know that you've made a mistake.
handy really...
I thought it was only me(using AutoCap. to see if I spelt a var. or function name correctly)
-
Aug 16th, 2000, 11:32 PM
#15
Frenzied Member
The addins are being despatched as I type. (I realised I didn't actually have anything better to do)
I think most people use auto cap as vachecking (which is annoying when you get to C++ because you type your declarations capitalised and then your variables n lower case and it doesn't recognise them)
Other than that you're all evil especially dennis. You're sitting here complaining about other peoples code and not commenting your own (actually crypt isn't complaining and funkyd77 may well comment his code, but dennis is downright hypocritical.)
It's a really good Idea to get into the habit of good coding, It does make your code so much easier to read and debug,
It does take a while to get into the habit of it, but once you do it does help, I've found that I actually code faster when I comment my code because as I'm writing the comments I'm clarifying exactly what I'm doing in my mind so I don't have to stop and thing and I get it right frst time. (some people even write their comments before they write the code and then add the code in later)
Crypt, I'd get into the habit of indenting the code yourself rather than relying on the addin, Indenting is one of the things you get into quite quickly and it makes a huge difference to readability.
This actually sounds like a really preachy post, and I do apologise, but I used to be the most terrible coder in the world and you just don't see how much difference good coding makes until you start doing it.
-
Aug 16th, 2000, 11:40 PM
#16
Addicted Member
(some people even write their comments before they write the code and then add the code in later)
Yep - i do this often - especially when i have to write some code that does some particularly logical stuff <meaning lots of conditions, or the function is based on some algorithm - not implying that everything else is illogical - i suppose just when it takes a fair bit of brain power> and it really works. You can read through the comments and just think - yep, that would do it and then just populate little sections of code to do what you've said it will do.
[Edited by funkyd77 on 08-17-2000 at 12:57 AM]
-
Aug 17th, 2000, 01:54 AM
#17
Lively Member
Yeah I agree. Ppl should take pride in their code. Quite often I have downloaded samples off the web only to find that files are missing (like a form that wasnt in the directory they zipped up). Its annoying. I try to improve my habits consistently. Recently I made myself use hungarian notation for variable naming and its made the world of difference. Doesnt seem right not to do it.
-
Aug 17th, 2000, 02:50 AM
#18
Member
Common Sense, not Conformity!
As we all remember from our high-school comp classes "undocumented code is a good as no code." I would remember this as I am still in high-school But I digress. The point of documenting code is to make it easy to following so that you don't need to look at the code. It does not matter if is in Hungarian or Swiss Banker Notation as long as they make sense.
Few common sense tips/rules:
* declare variables using "as _______" statements but refer to them later with their type-declaration character
(eg. dim MyString as String, MyString$ = "No String")
* put comment on same line if possible
(eg. dim Dead as Boolean ' whether user is dead or not)
* if var name made of several captilize beginning of each
(eg. MyStringIsNice)
* for Booleans there is no point trying to remember what true means and what false means, USE CONSTANTS!
(eg. dim PlayerTurn as Boolean
const RedTurn = False
const BlueTurn = True
PlayerTurn = RedTurn)
* organize var declarations by type and then alphabetically
* name all objects with the usual 3 or 4 letter prefix and of course a descriptive name
* leave spaces between majour blocks of code(eg 2 for loops)
* document NOT AFTER and NOT WHILE writing the code but BEFORE. Write it all in REMs as pseudo-code (again HS). Makes coding much easier
* DON'T OVER DOCUMENT! We do not compile these ourselves, so WE DON"T NEED EVERY LINE CLARIFIED and DON'T CLARIFY THE OBVIOUS
I realize these hints are for real newbies but there might be something there anyone can use...
Visual Basic 6 Professional Edition
Captain Pinko
also:
Turbo Pascal, Turing, QBasic
-
Aug 17th, 2000, 03:02 AM
#19
Hyperactive Member
Use that auto-capitalization to check if the varname is speleld correctly? I type 3 or 4 chars and hit ctrol+space and let VB type the rest...
I usually comment kinda when I'm writing, sometimes before to tell myself what has to happen, sometimes afterwards to tell what's going on. But most of the time kinda at the same time, works very well for me, at least, I understand the codewhen I read it back so I assume it does :-)
I like comments above a line, and preferably use blank lines to seperate pieces of code. Reads easier.
-
Aug 17th, 2000, 05:59 AM
#20
Addicted Member
thanx for the add-in sam I appreciate it .
-
Aug 17th, 2000, 06:38 AM
#21
_______
<?>
Basically, if you want to learn about coding properly all you need do is find one of your first apps and make changes to it. I wrote a mdb app to run a hockey pool and a year or two later went back in to edit the rules and point allotments...I didn't even know what the app was doing in places and I was the one who wrote it....certainly made me aware of commenting and "Pretty Code"
Now I usually write the app and every so often I go in and clean it up. When finished I clean it up thouroughly before I call it a finsihed product.
On this site however, sometimes the code I paste isn't fully documented because times it's not my own writing, it's just stuff passed on and found.
PS.
Don't be too hard on the "Sloppy Coders"...they may not have crossed that bridge yet.
Have a good one,
Wayne
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 17th, 2000, 09:29 AM
#22
Sandra Finch:
dont call me a hypocrit, I never said anything about being pissed at people who dont comment.
Crazy D:
"hit ctrol + space"
thanks, I didnt know about that 
HeSaidJoe
"PS.
Don't be too hard on the "Sloppy Coders"...they may not have crossed that bridge yet. "
I have seen some people who are really good, that have awful looking code,
they look like they could be awesome code writers, but there code looks horrible.
-
Aug 17th, 2000, 11:39 AM
#23
Great points!!!
I've tried to indent and keep what little coding I know clean and readable. Even to the point of over-commenting for myself!
I go in spurts, of when I have time, to devote to learning VB since I have other responsibilities too. But not too long ago, I opened up some source code on another small project... And even with the commenting... I had no idea of what I was doing!!!
Just like picking up a note you write to yourself a few days later... You are not too sure what the heck you were writing to yourself! So I'm being a bit more specific on commenting, rather than making notes I may not understand later.
I read ton's of posts here almost daily... Sometimes I learn something... Other times it gives me something to look up. If I had the time, I'd consider taking some type of class here at the college. Oh well... :-(
You folks are worth far more than a college class, I believe! Thanks!!!
-
Aug 17th, 2000, 11:49 AM
#24
You folks are worth far more than a college class, I believe! Thanks!!!
yeah, and we are worth every penny you didnt pay
-
Aug 17th, 2000, 12:08 PM
#25
Fanatic Member
Originally posted by Samantha Finchbut I was trying to not split infinitives
Hihihihi.
That's the funniest thing I've senn since I looked into the mirror.
And if you don't get it:
First of all: DUH. Where did you go to school? Retard High?
Secondly. A split infinitive is when you put a word between the two parts of the infinitive. And that's what Sam did:
To Not Split
(If you don't know what an infinitive is then you need serious extra-hours tuition)
I feel like having an epileptic fit on the floor with so many uncontained dysprexic movements that my capillaries would burst and I would be left in excruciating pain on the floor.
(My English est improving, innit?)
-
Aug 17th, 2000, 12:14 PM
#26
Frenzied Member
I'm glad that amused you V(ery), It was actually deliberate.
-
Aug 17th, 2000, 05:32 PM
#27
V(ery) ~
Actually some of the most successful business people I know have not even attended college. Some didn't even bother to finish High School!
Each of the individuals I know of either own or operate their own companies. They are independently wealthy and still continue to work.
What is more unique... These individuals never publicly berate others.
I also know of three individuals with "prestigious" MBA's from Ivy League schools who could not make it in the business world.
Education is important, but it isn't the end-all some individuals, or corporations, would lead you to believe.
As a rule... What goes on in the business world, including Sales and Marketing, takes on the average of between 3-5 years to reach your text books.
And the Professor teaching business and economics, if they were good, would be in the workplace utilizing their knowledge. Since they cannot... they choose to impart it through an educational system. Which doesn't impress me in the least to begin with.
I would rather read, listen and learn VB techniques from Sam, Megatron, denniswrenn and the rest... Rather than to be instructed by some booksmart person who couldn't make his/her own way in the real world.
Those that can, do. those that cannot, either teach or manage.
-
Aug 17th, 2000, 06:07 PM
#28
Ctrl+Space is cool.
Didn't know about it... :P
By the way, I like even putting blank lines between parts of code that are already separated from other parts. E.g:
Code:
Dim hObject As Long
'Some code...
If hObject = Me.hWnd Then
Debug.Print "Blah blah blah..."
Debug.Print "Yadda yadda..." & hOject
MsgBox "Handle is: " & hObject
If hObject > 1000 Then Exit Sub
End If
'Some code...
But that's just an example. :P
This way it's much, much easier to read it.
-
Aug 17th, 2000, 06:15 PM
#29
I do that too
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|