Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Is there anything out there for coding practices, or conventions?

Author
Message
tiresius
21
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 29th Mar 2004 23:36
Hello all.

I've had DBPro for a while, coding on and off. I'm going to be starting a good size project now, still working it out mostly on paper and doing tech demos to make sure DBPro can do what I want (all 2D so it shouldn't be a problem!).

Anyways, I saw some code from Lee Bamber, I forget where, but it looked really nice. My coding style is readable but what I saw of Lee's impressed me greatly. Is there any documents out there for DBPro users that say "Here's how you should name your variables" or "Here's how to avoid GOSUBS" and stuff.

A couple things I noticed from the code was that his functions started in lowercase and subsequent words were upper, like initImages() or readInput(). Another thing was the use of _ to continue lines (didn't know we could do that ) and the third was that some gosub calls started with _ in the name, like "gosub _getFile". Not sure why?

Actually I remembered where I saw the code, it was in a screenshot for the BlueIDE. It must have been a demo program that comes with DBPro or something?

So is there something written out there specific for how we should code in DBPro to make code readable and look nice? Maybe how to use separate modules and stuff too? Thanks for any info.
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 30th Mar 2004 00:11 Edited at: 30th Mar 2004 00:12
Quote: "So is there something written out there specific for how we should code in DBPro to make code readable and look nice? Maybe how to use separate modules and stuff too? Thanks for any info. "

not that i know of... what i do...

1-comment frequently
2-use capitals to define separate words in variables (E.G. NumOfPlains...)
3- use _ to define separate words in functions (Go functions!) and subs (E.G. Make_Matrix)

ooh ooh i got this great idea master yoda we could make a game! and the game's story line would be...
"Your wife is death. How? NO idea. But it is murder. REVENGE!!!!!!!!!"
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 30th Mar 2004 01:50
use hungarian notation and strongly typed variable definitions

intMyNumber as Integer
strMyText as String
dwoMyScore as Dword
fltMyData as Float

you get the idea



Home of the VB.NET Class Builder Utility - Demo available now!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 31st Mar 2004 17:05
Go with what you are comfortable with. Unless you're working in a team, you can set your own standards, so long as you stick to them. Hungarian notation is an excellent starting point, my code uses things like...

sVar for strings
iVar for Integers
fVar for real numbers
bVar for booleans (actually integers in DB Pro, but it tells me I'm using it as a boolean)
ariVar() for an integer array

fGetSomething() for functions

...and I don't do Subs.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 31st Mar 2004 17:44
I prefer 3-letter H-Notation only because coming from vb using single letter can cause a problem in certain instances. Consider:

sMyVar as String
sMyVar as Single

but that's just me



Home of the VB.NET Class Builder Utility - Demo available now!
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 31st Mar 2004 18:43 Edited at: 31st Mar 2004 18:44
There isn't any db specific documentation I know of. Once you have written a few small games you will work out what works for you. It's mostly personal preference anyway. For instance it's going to be a cold day in hell before I start using hungarian notation but CattleRustler BatVink get on fine using it.
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 31st Mar 2004 18:54
Yeah, it is really a style thing. Comments don't cost a dime. So, remember to use them early and often. They'll save your sanity down the road and when you want to show your code to others (either to help someone or to get help with a problem.)

Some tips that might help. Try not to hard code object and image IDs. Use a variable or constant and it will be self documenting and easier to maintain in case you need to change your resource loading code.

Use user defined types, if they are available.

One, they organize your data better.

Two, when used in an array, you define the type and array once rather than having to manage multiple arrays or 'uncommented' multi-dimensional arrays.

Three, types have some built-in syntax checking to make things easier and more bug free.

Four, types can be easily expanded without have to add a bunch of code to other parts of your project. If you change a type, the syntax checking in bullet three will allow DBP to pin point every line of code that needs to be fixed/updated.

Good luck.
--
TAZ

Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 1st Apr 2004 00:55
The advantage of the capitals for new words (e.g. mySuperCoolFunction) is mainly that it is quicker to type (although I also find the underscores aesthetically displeasing).
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 1st Apr 2004 02:55
oh yeah, INDENT!!



Home of the VB.NET Class Builder Utility - Demo available now!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Apr 2004 21:51
Indenting is very important. I hate reading code thats all at the same margin. Commenting is important. Descriptive variable names are a good idea. Not just for others, but for your own sake. Naming conventions basically means the same thing. thisIsMyFunction(), Start with a lowercase letter for the first word, then capitalize the first letter of each word thereafter. CONSTANTS should be all capitals.

"eureka" - Archimedes
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Apr 2004 14:20
Don't use multiple commands on a single line. The only place that doing it has a point is in the 20 line forum. Anywhere else gives you a maintenance problem.

Capitalisation is a personal preference. Some like all words to start with a capital, some only do this from the second word, some use underscores instead ... it really doesn't matter as long as you pick one and stick with it.

Meaningful names is important. With them the majority of comments are simply not needed ... and I'll refrain from commenting on what adding random characters to the front of variable names does for that (hungarian anyone ) as that is a personal pet hate.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2024-09-22 04:29:57
Your offset time is: 2024-09-22 04:29:57