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.

Geek Culture / A function declaration in a BASIC language

Author
Message
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 25th Sep 2007 07:58
Hello all, please let me know the way you think a function/procedure/method should be declared in a BASIC language. Here is an obvious one:

Function/EndFunction


Typed


Any other ideas/votes?


Cheers,

-naota

DBP, $80. DBP's plugins, $320. Watching DBP Crash, Priceless.
NG Website Aex.Uni forums
Dazzag
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Cyprus
Posted: 25th Sep 2007 09:13


Cheers

I am 99% probably lying in bed right now... so don't blame me for crappy typing
Current fave quote : "She was like a candle in the wind.... unreliable...."
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Sep 2007 11:14
I like typed, but I dont like the whole "something as something" thing. Also, I think it's better to have a "return" command rather than putting it after "endfunction", because that looks like the variable is outside the actual function.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Zombie 20
17
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 25th Sep 2007 11:56
I like Dazz's, it would have a nice flow to it.

Jonny_S
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 25th Sep 2007 12:19 Edited at: 25th Sep 2007 12:24
dazzags is defintly the way most BASIC languages seem to do it, although I think alot use return to exit the loop i.e.


Your signature has been erased by a mod
Dazzag
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Cyprus
Posted: 25th Sep 2007 15:14
Ah, I don't know about most. I've used a few, and it can be pretty random really. The one I put in was from VB6. Main reason I like it is because of the optional parameters. Nothing worse than a function with an optional parameter and you *have* to put a 0 in it to use default settings. Sucks bigstyle. With that style you can then say b=fct1(a,c,d) or b=fct1(a,c) if the "d" param was optional. Much better. You can also say something like 'optional param2$="DEFAULT"'. Which is nice for defaulting stuff. That example would mean that param2 is optional (note everything afterwards has to be too) and is a string, and defaults to "DEFAULT" if not passed in.

Cheers

I am 99% probably lying in bed right now... so don't blame me for crappy typing
Current fave quote : "She was like a candle in the wind.... unreliable...."
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Sep 2007 15:53
I go with Dazzag's points - maybe allowing 'returning' instead of 'as'. The returning of those values I also agree with, as well as the nicety of having default values.

I don't think it's a good idea to use the 'return' keyword to return a value - return already has a purpose, to return from a gosub. That's only a problem if you support gosub though.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 25th Sep 2007 16:58 Edited at: 25th Sep 2007 17:03
in vb.net

Public Function TheFunctionName(args as ValidTypes)As ValidType
'CODE
'using the RETURN ValueHere keyword anywhere in the func code immediately exits the function at that point, returning the value provided.
'at some point you need to set TheFunctionName equal to some value so if End Function is hit the value gets returned
End Function


functions can be overloaded, overidden, or override
functions can have optional args
function args are ByVal by default, ByRef if specified explicitly

My DBP plugins page is now hosted [href]here[/href]
Jonny_S
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 25th Sep 2007 19:26 Edited at: 25th Sep 2007 19:28
Yes, I like the way CR said, and yes I supposed your right dazzag when I think about it the implementation can vary with different BASIC dialects. For example I had thought vb6 and vb.net used identical syntax for function declarations, but it seems I remember less VB6 than I realised.

Your signature has been erased by a mod
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 26th Sep 2007 04:33
The problem with setting "TheFunctionName" to some value for returning a value is that functions are just pointers to an area of memory which would be executed. And hence, setting TheFunctionName to some value would result in changing the pointer to the function, which could have your program crash due to a memory fault. By the very design of the language, and with OOP in mind, pointers are necessary for the functions.

I noticed the "End Function" part too, I'm sorry but by the design of the language no spaces are allowed in function names. I spoke with Zotoaster about his thoughts on spaces in functions, and he agrees that they shouldn't have spaces, for example:



Would cause an error in dark basic (If you have one of Cattle Rustler's plugins, I believe it was one of cattle rustler's programs).


I appreciate the input, and so far only a few people like the typed names, but for a BASIC is apparently not viable. I can see the point in this, and would make the language look a bit more like C/C++. I'm still looking for views on the matter though.


Cheers,

-naota

DBP, $80. DBP's plugins, $320. Watching DBP Crash, Priceless.
NG Website Aex.Uni forums
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 26th Sep 2007 14:38
I was just pointing out how functions are done in vb.net, beyond that I wish you luck.

My DBP plugins page is now hosted [href]here[/href]
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 27th Sep 2007 00:11
I thank you for that CattleRustler, your comments are much appreciated.

DBP, $80. DBP's plugins, $320. Watching DBP Crash, Priceless.
NG Website Aex.Uni forums

Login to post a reply

Server time is: 2024-11-19 07:13:18
Your offset time is: 2024-11-19 07:13:18