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 / Are there established Dark Basic Coding Standards?

Author
Message
borngamer
15
Years of Service
User Offline
Joined: 16th Sep 2009
Location: London, Ontario
Posted: 29th Sep 2009 20:42
Hello everyone.

I've done a little searching and haven't seen anything so I'm going to ask the question. Has the developers of DarkBasic or the community in general established a set of coding standards for DarkBasic?

So for, all of the tutorials I've looked at seem to be inconsistent with variable naming standards, code layout and so on. Indenting and commenting code is promoted (which is great), but what about correct case for variable names, function names and reserved words?

I understand that the language is not case sensitive so the case of different names isn't critical for a good compile, but as my skills grow and I start posting code, I'd like to post code that looks good and follows within the norm.

Sorry if this question seems a bit anal, but as someone with 25 years of programming and documentation experience, I like to know all the standards before I start working on a project.

Thanks,

John
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Sep 2009 22:44
The idea has been proposed but it got blown down in a rage. Suppose DarkBASIC is just an independent programming tool to make games by yourself or in small teams. People are just going to have it that way, lol.

"everyone forgets a semi-colon sometimes." - Phaelax
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 30th Sep 2009 00:55
I for one use standard naming conventions.
That is, variable / function names start with lowercase letters, then for each new word in the name a capital first letter (for example myVariable, myAnnoyingFunction(), etc.).
Constants are all uppercase, and so may certain globals be.

QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 30th Sep 2009 07:53
Trying to determine best practice for dark basic is like trying to nail jello to a tree. Things will get in your way, like the fact that commands are case insensitive. The majority of the community is a younger audience who aren't quite experience enough to write maintainable code. There are no community standards, just personal ones. The language itself is a weird conglomoration of functions that can even get in the way of good coding principles.

So, good luck. Have fun trying to namespace everything. And don't worry about scope. Basic don't need no stinking scope.

borngamer
15
Years of Service
User Offline
Joined: 16th Sep 2009
Location: London, Ontario
Posted: 30th Sep 2009 16:52
Fair enough. All CAPS it is

Seriously though, I had come to the conclusion that standards were non-existent when I started reading the documentation and online tutorials.

I'll have to either develop my own standards or try to apply the standards from other languages.

John
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Sep 2009 19:38
That's the beauty of programming in Darkbasic... no standards.

There are some things that we all do naturally the same but differently at the same time. When I indent I only use one space... almost everybody else use the tab button so their code travels away from the edge a lot more than mine.

I start all arrays, functions, and variables with capital letters and caps for every new word (mine would be MyVariable, MyAnnoyingFunction()). All commands are lowercase in my code but when I talk about them in a message I use all caps so people know when I'm referring to a command.

And above all else there is one command that 90% of us don't use at all... GOTO.

QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 30th Sep 2009 19:38 Edited at: 30th Sep 2009 19:39
I personally use all lowercase. Caps feels like I'm writing a SQL query.

Now that I think about it, there's no naming conventions within the language itself. Like "object position x(obj)" is a function with parens, but "set object position obj, stuff," does not have parens. Some functions have spaces in them, some don't! Reminds me of the "naming conventions" of PHP.


Edit:
Quote: "That's the beauty of programming in Darkbasic... no standards."

This statement makes me uncomfortable

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 1st Oct 2009 00:21
Ok, I admit I don't use goto, but I definitively use gosub. What's you guy's problem with that anyway?

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Oct 2009 07:36 Edited at: 1st Oct 2009 07:40
I've said it before but I don't have a problem with repeating myself.

I've personally stopped using GOTO and even GOSUB but I believe that newbies should use GOTO to just learn about the command. Once they learn a better way (GOSUB or functions) they need to stop using GOTO and never use it again. Yes, it was a good command when it was the only thing available in Basic and I have used it myself many times but because we have better methods now... GOTO should be learned and left behind.

That's why when I changed my signature I used Anti-Goto Order because the capital letters spell AGO... meaning in the past... and that's where GOTO should be for all of us non-newbies. The signature is both against GOTO and reminds us that we have all used GOTO in our past.

Colonel_Klink
17
Years of Service
User Offline
Joined: 20th Dec 2006
Location: Within the dark recesses of my mind
Posted: 1st Oct 2009 10:00
Grog Grueslayer, I hear you. But the question still arises 'why not use goto?' I've used Visual Basic most my programming life and it's never given me any bother. A use in VB programming is error trapping is "On Error Goto".
I've used it in DBPro on aoccassions and still not given any grief.

Oh my gosh! He's wearing Full Metal Pyjamas!
--------------------------------------------
borngamer
15
Years of Service
User Offline
Joined: 16th Sep 2009
Location: London, Ontario
Posted: 1st Oct 2009 14:43
Most of us who are old enough to remember the ancient days of basic programming can remember sifting through mountains of code with GOTO statements every 5-10 lines. This was in the days when BASIC programs used line numbers.

Line numbers and GOTO statements were especially painful. Imagine having a 500 line program that had 30 GOTO statements in it. If you had to add any code at the beginning of the program all of your GOTO statements would have to be assigned new numbers.

Programmers had tricks back then to help. For one, new sections of code usually started with a much higher number than the previous section (e.g. Initialization started at line 100, data entry at line 500, etc.)

Either way, it was still a mess. If a programmer ran across the line GOTO 250, they needed to actually review that code to see what it did if the GOTO statement wasn't commented by the original programmer.

Later, named tags were added and programmers could write lines such as GOTO ReadDataSection. This was a major improvement but you still had all these GOTO statements which were frustrating to deal with.

Depending on who you talk to, some people think one or two GOTO statements are acceptable. Many (myself included) believe that there are better ways to write your code that you never need a GOTO. Unfortunately, if you are stuck it is sometimes a very easy way out of a problem.

Ok, I think this ends my history lesson for today. And yes, sadly enough, I am old enough to have coded through the different generations of basic. In fact, when I was in college, we learned how to code RPG (another dead programming language) on punch cards.

John
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 1st Oct 2009 19:40
LOL, back in 1993 I worked as a programmer coding in COBOL. We had to ask special permission to use a GOTO, and explain why it was being used and why it was the only way.

There are certain circumstances where a GOTO is very useful. But for the most part they should be avoided.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Oct 2009 20:56
Quote: "Grog Grueslayer, I hear you. But the question still arises 'why not use goto?' I've used Visual Basic most my programming life and it's never given me any bother."


Well the other part of the signature talks about the results of using GOTO in the wrong ways leads to spaghetti code. A tangled mess of hard to follow code that only leads to frustration just looking at it.

Quote: "A use in VB programming is error trapping is "On Error Goto"."


I never programmed in Visual Basic but I have in QuickBasic. It had really nice error trapping too but it had two commands ON ERROR GOTO and ON ERROR GOSUB. If given the option in VB which would you choose?

Quote: " I've used it in DBPro on aoccassions and still not given any grief."


A single GOTO is not going to create spaghetti code but it's like eating chips... you can't just have one. It's better to stop using GOTO totally so you don't even think of it as an option to solve any problems. The bottom line is you're free to use GOTO all you want... until I become Supreme Ruler of the World.

Colonel_Klink
17
Years of Service
User Offline
Joined: 20th Dec 2006
Location: Within the dark recesses of my mind
Posted: 1st Oct 2009 23:08 Edited at: 1st Oct 2009 23:11
Quote: "The bottom line is you're free to use GOTO all you want... until I become Supreme Ruler of the World."

I will keep an eye on you

The 'On error goto' goto in VB is usually contained within the sub routine where the error occurred. e.g.


To be honest this method is very tidy and not spaghetti like at all. However I could see that over use, particularly in DBPro where AFAIK, or have seen so far, there is no error trapping code.

Oh my gosh! He's wearing Full Metal Pyjamas!
--------------------------------------------
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Oct 2009 03:59
GOTO was used alot in qbasic programs, which made it rather difficult to look at good. You were constantly jumping around. I really see no valid reason to use a goto command, gosub (when paired with RETURN) keeps your code way more organized and modular. I think most coding designs should take a modular approach.

Quote: "Sorry if this question seems a bit anal, but as someone with 25 years of programming and documentation experience, I like to know all the standards before I start working on a project."

That tells me you've used more than one language before and you're experienced enough to recognize that each language has its own standards that are important for any coder to adhere to.

I hate when a particular language has a set standard, then someone with 10 years of experience in another language think they should apply language A to language B. Makes it annoying for the rest of us who use language B over language A. (did that make any sense?)

DarkBasic, because it is more of a hobbyist language and largely targeted at beginners with no experience, really doesn't have any standards. Personally, I tend to use Java standards much like Rudolpho described. Globals I'll prefix with an underscore and UDT names start capitalized like I would an object.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 2nd Oct 2009 21:47
@ Colonel_Klink:

Taking over the world shouldn't take too long.

Yeah total error trapping would be nice in Darkbasic but luckily there are plenty of specific error traps that we could make with commands like FILE EXIST(), SPRITE EXIST(), OBJECT EXIST(), and so on. It probably would be a daunting task for Lee to condense all those specific error traps into one command to trap them all.


@ Phaelax:

I admit when I started using QuickBasic (not QBasic) coming from GWBasic I still used GOTO even after I discovered QuickBasic had subroutines. It wasn't until I used Darkbasic for a while that I stopped using GOTO altogether.

The following is my oldest Darkbasic Classic program I could find that was saved... it has goto, and no indenting and several other things I wouldn't do now. You can even see my thought process as I was learning Darkbasic with the remarks. It wasn't long after making that test that I joined the Darkbasic forums and happily learned indenting, functions and the evils of GOTO from just reading messages by people like you (those that have used Darkbasic longer than me).

This was a test for the first game I wanted to make in Darkbasic... Fatso.


Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-24 01:52:18
Your offset time is: 2024-11-24 01:52:18