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.

DarkBASIC Discussion / Functions in DB

Author
Message
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 12th Dec 2003 04:04
ok i'll start off by saying this:
in my Comp Sci AP Class we are learning JAVA. and in JAVA we use methods (just the same as functions) for almost everything we want to do.

do you want to do that in DB too? i know you probbibly wouldnt want to make all your objects in a function, but....do you guys know what i mean?

Do i ALWAYS use a function when i can? i guess is what i am trying to sy

Clarks
21
Years of Service
User Offline
Joined: 30th Oct 2003
Location: BALTIMORE,MARYLAND
Posted: 12th Dec 2003 06:00
in my opinion use a function when you can because it gives you flexibility. for example you can use a function to create a level and delete a level.
Brandon Smith
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Urbana, Illinois (USA)
Posted: 12th Dec 2003 07:48
For just orginizing my code in DarkBasic, I'm happy just using
subroutines. I tend to be lazy and like it when every part of my code can access any variable I've created. Your teacher would probably tell you that that's poor programming practice though, and that you should use functions when you can.
Functions and methods also do give you more power, with the ability to have a return type, and especially for implementing recursion....
But I haven't really had to use recursion in DarkBasic, yet.
I think the more we program, the more we will learn about the best ways to use functions, and when and where they are appropriate.

So, hope that helps...some
Brandon

note: I don't claim to know what I'm talking about
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 13th Dec 2003 08:25
Quote: "Your teacher would probably tell you that that's poor programming practice though, and that you should use functions when you can."


Yep, and i'd agree with him.

Functions are essential... Use them everywhere instead of using gosubs etc. If you need variables in the function, pass them to it. If you need to change variables from within the function, make them arrays ( since array's are global ).

You can replace everything with functions... mabey it means re-writing bits of your code, but it does make codeing ALOT easier. especially when debugging.

When you progress into higher languages, such as C++ etc, or even to DBPro, you'll find that functions are easier to make ( because of some missing commands, it's a bit harder in DBC ), and thus, more flexable, and preferable over subs and goto's etc.

If you start to use functions now, in the BASIC language, when you get further you'll be thanking me for telling you to use them, for being able to actually make one without having to ask someone...

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 15th Dec 2003 00:59
functions all the way but sometimes you can squeeze a little more speed out of a raw peice of code so it depends on what is required.
heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 16th Dec 2003 06:59 Edited at: 16th Dec 2003 06:59
However if you need to reuse a section of code, and that code alters the values of many arrays and program variables then it makes more sense to use a subroutine.

The more you see, the more you know.
The more you know, the more you see.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 16th Dec 2003 07:22
Quote: "However if you need to reuse a section of code, and that code alters the values of many arrays and program variables then it makes more sense to use a subroutine."


Actually, no, it makes more sense to use a Function, especially if you are having to change the values of Array's ( since they are global )

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 16th Dec 2003 18:58
functions are faster, are they not?

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 17th Dec 2003 04:55
Faster for development, yes. But faster in processing, I'm pretty sure it's about the same...

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 20th Dec 2003 02:34
In DB Classic sub routines are remarkable faster than functions.
Since there's no "global" directive for variables (just the array hack) nor a "byRef" directive, there are a lot of situations where a sub routine is the better choice.

Me, I'll sit and write this love song as I all too seldom do
build a little fire this midnight. It's good to be back home with you.

Login to post a reply

Server time is: 2025-05-22 04:14:04
Your offset time is: 2025-05-22 04:14:04