Program Layout
-
- User
- Posts: 51
- Joined: Mon Jun 01, 2009 3:56 am
Program Layout
Does anyone have a program layout. Like where do you place the Constants, Declare statements & or procedures.Do all the Declare statements go before the procedures. I wrote a program which shows a BMP file and another having a Menu. When I ran them only the BMP was displayed. If I remarked out the BMP program then the menu would work. Why did I have to remark out 1 of them to get the other to work?
You'll find it easier to get help to solve your problem if you post the portion of your code that you are having problems with.
Generally PB can handle things laid out all over the place (I'm guilty!!), but its best generally to declare things up front.
From the PB help file:
http://www.purebasic.fr/english/viewtopic.php?t=37059
Generally PB can handle things laid out all over the place (I'm guilty!!), but its best generally to declare things up front.
From the PB help file:
Probably a good idea to download this beginners guide from the link underneath to begin with.Syntax
Declare[.<type>] name(<variable1[.<type>]> [, <variable2[.<type>]>, ...])
Description
Sometimes a procedure need to call another procedure which isn't declared before its definition. This is annoying because the compiler will complain 'Procedure <name> not found'. Declare can help in this particular case by declaring only the header of the procedure. Nevertheless, the Declare and real Procedure declaration must be identical (including the correct type).
http://www.purebasic.fr/english/viewtopic.php?t=37059
I don't use Declare unless it's absolutely necessary. Placing the procedures in the correct order is usually sufficient.
I think it's common to organize the program something like this:
1. Enumerations and constants
2. Structures
3. Global variable declarations
4. Procedures
5. Main program code (or code to call procedure with program code)
6. DataSections
I think it's common to organize the program something like this:
1. Enumerations and constants
2. Structures
3. Global variable declarations
4. Procedures
5. Main program code (or code to call procedure with program code)
6. DataSections
Trond wrote:I don't use Declare unless it's absolutely necessary. Placing the procedures in the correct order is usually sufficient.

I always have declares for all procs, helps me structure the code like a little contents section. Also, I've noticed (and it was discussed once) that the position of a proc in the source can effect it's performance surprisingly enough so you may want to take advantage of that.
Is there some benefit to playing with proc order for dependancy purpose?
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
> Placing the procedures in the correct order is usually sufficient
Usually is the right word. Sometimes that's just impossible, when procedures
rely on other procedures and one simply can't go before another.
Usually is the right word. Sometimes that's just impossible, when procedures
rely on other procedures and one simply can't go before another.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
aren't you guys part of the pro enable explicit lobby though? 

Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
I know, then I use declares. And sometimes the procedure order becomes very illogical without declares, so then I may use declare as well.PB wrote:> Placing the procedures in the correct order is usually sufficient
Usually is the right word. Sometimes that's just impossible, when procedures
rely on other procedures and one simply can't go before another.
Kale, here is a (bad) example where you have to use declare:
Code: Select all
Declare Odd(Num.i)
Procedure Even(Num.i)
If Num = 0
ProcedureReturn 1
Else
ProcedureReturn Odd(Num-1)
EndIf
EndProcedure
Procedure Odd(Num.i)
If Num = 0
ProcedureReturn 0
Else
ProcedureReturn Even(Num-1)
EndIf
EndProcedure
Debug Even(0)
Debug Even(1)
Debug Even(2)
Debug Even(3)
Debug "--"
Debug Odd(0)
Debug Odd(1)
Debug Odd(2)
Debug Odd(3)
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Program Layout
you wrote TWO programs? why?Hot Pockets wrote:I wrote a program which shows a BMP file and another having a Menu. When I ran them only the BMP was displayed. If I remarked out the BMP program then the menu would work. Why did I have to remark out 1 of them to get the other to work?
perhaps you're misinterpreting the nature of procedural programming?
all I can say so far is

for more analysis, we need more information.
oh... and have a nice day.
-
- User
- Posts: 51
- Joined: Mon Jun 01, 2009 3:56 am
Program Layout
Kaeru:
Why Indeed? I should of said when I combined them into 1 program only 1 ran.
Trend:
Thanks for answering my questionvery well and to the point. May I have a little more advice. Would it work as well if I reversed the order of items 4 and 5. (Just an idea.)
Others:
I downloaded that most excellent book awhile back and have printed all 336 pages into 2 volumes. I will look thru that again to see if there is something like Trend's accurate synopsis. It may take me several days to do it tho!
ALL:
Thank you for your efforts!
Why Indeed? I should of said when I combined them into 1 program only 1 ran.
Trend:
Thanks for answering my questionvery well and to the point. May I have a little more advice. Would it work as well if I reversed the order of items 4 and 5. (Just an idea.)
Others:
I downloaded that most excellent book awhile back and have printed all 336 pages into 2 volumes. I will look thru that again to see if there is something like Trend's accurate synopsis. It may take me several days to do it tho!
ALL:
Thank you for your efforts!
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
did you say this?Hot Pockets wrote:Kaeru:
Why Indeed? I should of said when I combined them into 1 program only 1 ran.
problem is, when you don't say something, the others can't know something.
I could be guessing around and presume, because you said "two programs"
you also wrote two eventloops instead of one...
sounds like "misinterpreting the nature of procedural programming"
whatever it was, it clearly was "ur doin it wrong"....
the others gave you some good overview answering to your general question...
but it wasn't any solution to your problem "bmp shows, menu doesn't show".
why?
surely because you didn't give the least hint what caused the problem.
also mind this:
rrpl wrote:You'll find it easier to get help to solve your problem if you post the portion of your code that you are having problems with.
oh... and have a nice day.