Why not declaring all the procedure automatically ?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Why not declaring all the procedure automatically ?

Post by Polo »

Hi !
Why do we have to do
declare MyProcedure(...)
to use MYProcedure before we define it ? It would be great to have Purebasic doing this job :) It'll make things easier :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I think it is to make things more clear while reading source code. Besides to tell the compiler how are the functions to be defined in the code.
I never use it. I Define all functions at the beginning of all the code. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

yeah, but imagine you can put the procedure where you want, without having to check if you're using it before or after 8)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

That's why jaPBe has a "create declare files"-function.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Yeah, but as reported before by me, that function doesnt work (or at least not on my system). Im still searching through the japbe source to fix this.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Well, it should be time for Fred to implement that in the compiler, no ? Or to add an option to do it :)
This way we could put all functions at the end of the file, and for example :
Procedure function(do)
a=allocatememory(do+8)
myfollowingfunction(a)
endprocedure

Procedure myfollowingfunction(a)
...
endprocedure
I would love to be able to do that automatically :)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Why not declaring all the procedure automatically ?

Post by PB »

> Why do we have to do
> declare MyProcedure(...)
> to use MYProcedure before we define it ?

You (normally) don't need to declare a procedure at all. Are you mistakenly
thinking that it's always needed? Not so -- you only need to declare when two
or more procedures call each other and there's no way to put them in an order
where the latter ones can see the earlier ones.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

it's simply because

oh

that's a bit too simple :-)

okay, let me rephrase that:

it's simply because fred was lazy

euh...

that's perhaps a little unfair too :-)

it's because purebasic is a ONE PASS compiler, so it doesn't know anything before that has been declared, no vars, no procs, no nothing

if you want to use something you got to define it first, the 'declare' thingy tells purebasic to look ahead and figure out what parameters a function need

i think (personally) that adding an additional pass that does that automatically would make some sense... i mean, even gfabasic did that :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Yeah, i know we declare procedures only when it need to be called before defined, and that's what i would love to get rid off :)
It shouldn't be too hard to do :)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> the 'declare' thingy tells purebasic to look ahead and figure out what
> parameters a function need

Yep. Normally what I do is just throw in my procedures and if I try to compile
and get a message of Whatever() is not a function, an array, or a linked list
I just move the procedure ahead in the code to just before the section that
calls it. As simple as that -- no need to declare it that way. It's only when
two or more procedures make it impossible to shuffle around that you need
to declare one.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> i know we declare procedures only when it need to be called before
> defined, and that's what i would love to get rid off :)

I agree. PureBasic would need to become a two-pass compiler to do that.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

PB wrote:I agree. PureBasic would need to become a two-pass compiler to do that.
That's exactly the point. To enable this feature, the compiler would need
to go through all the sourcecode twice. First to see what procedures are
there, and what parameters they expect, then for the actual code.

Are you ready to double the compiling time just to overcome a little lazyness?

Think of how much better you could use that precious time you are waiting for the compiler to finish :wink:
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Are you ready to double the compiling time just to overcome a little lazyness?

Actually, it's not "double" the compile time because the first pass wouldn't be
compiling anything -- it's just scanning for Procedures and their parameters.
All the commands in between would be ignored. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i wonder if it would seriously slow things down, i somehow doubt that :-)

well, it would then make a good option i guess...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

A big part of the thread got deleted with all the forum stuffs, it seems :)
Anyway, i hope Fred had a look at this, it would be so great :)
Post Reply