Page 1 of 2

Why not declaring all the procedure automatically ?

Posted: Fri Feb 04, 2005 7:11 pm
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 :)

Posted: Fri Feb 04, 2005 7:36 pm
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. :)

Posted: Fri Feb 04, 2005 7:49 pm
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)

Posted: Fri Feb 04, 2005 8:10 pm
by GPI
That's why jaPBe has a "create declare files"-function.

Posted: Fri Feb 04, 2005 8:12 pm
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.

Posted: Fri Feb 04, 2005 8:25 pm
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 :)

Re: Why not declaring all the procedure automatically ?

Posted: Fri Feb 04, 2005 11:24 pm
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.

Posted: Fri Feb 04, 2005 11:27 pm
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 :-)

Posted: Fri Feb 04, 2005 11:31 pm
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 :)

Posted: Fri Feb 04, 2005 11:35 pm
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.

Posted: Fri Feb 04, 2005 11:38 pm
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.

Posted: Sat Feb 05, 2005 12:20 am
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:

Posted: Sat Feb 05, 2005 12:28 am
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. ;)

Posted: Fri Feb 11, 2005 7:44 pm
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...

Posted: Fri Feb 11, 2005 8:08 pm
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 :)