PDA

View Full Version : Coding Style Ideas



kryton9
12-12-2006, 06:29
Guys, I did a test to see if this would work, and glad it does. I am using some ideas from php and dark basic pro. Well in php all the variables have the $
and in DarkBasic Pro a common way to identify float variables is with a #. I think this idea of identifying the type of variable with the variable name and symbol is nice, however the way it is in c, I don't care for as it is in the front of the variable there are so many types.

The idea here is $ would be at the end of string variables, the # at the end of float variables and variables without any symbol are integers.

Also I was thinking for subs it would be

CapFirstLetter and no () it is a subroutine.
CapsFirstLetter() with () means it is a function

capFirstLetter would be an integer variable
capFirstLetter$ a string
capFirstLetter# a float
%capFirstLetter is a constant

What do you guys think? If you have any other ideas would like to read them here.


USES "CONSOLE"
dim float# as double = 123.45
dim s$ as string = "Thin Basic"
dim i as integer = 5

Console_Write( "the float value is " & Str$(float#) & $CRLF)
Console_Write( "the string value is " & s$ & $CRLF)
Console_Write( "the integer value is " & Str$(i) & $CRLF & $CRLF)
Console_Write( "Any Key to Exit" & $CRLF)
Console_WaitKey

Petr Schreiber
13-12-2006, 19:40
Hi kryton,

I don't understand few things.
When subroutine will be word with no (), how you would pass parameters ?
I think it is better to keep them bracketed :)

Regarding $ and #, this is interesting. For example in PowerBASIC, you can use this both ways to create single precision variable:


LOCAL floatie AS SINGLE
' or just
LOCAL floatie!


When I started working in it many years ago, I used the second type a lot. But as the time was passing, I "converted" to the first way. I don't know why...

In current version of thinBASIC, you can use variable syntax you proposed already.
So it is again just matter of personal preferences :)


Bye,
Petr

kryton9
13-12-2006, 21:49
It will be neat to see differnt ideas, I never thought about single precision and longs etc.

About the subs with no (), I always think of subs as no parameters, just code you go to a lot.
When I think Parameters I think in terms of Functions and the function can or doesn't have to return a value.

The main thing is to come up with something that is uniform and help ease the ability to follow the code.
I think it is nice that thinBasic is so flexible in allowing this sort of freedom of choice.