Declarations

Working on new editor enhancements?
russellbdavis
User
User
Posts: 31
Joined: Wed Dec 02, 2009 4:50 pm
Location: Oklahoma City, OK
Contact:

Declarations

Post by russellbdavis »

I would like to be able to create various source files, but have the DECLARE statement in a single main file. I haven't spent a lot of time in the editor, but it appears the DECLARE for procedures must exist in the file where the procedure exists. Or perhaps use the GLOBAL keyword + DECLARE for a procedure at perhaps the root source file. Just an idea.

I come from a strong VB background (since Jan. 1991), but feel PB is the greatest new tool I have found. I HATE Visual Basic .NET and OOP in Visual Studio. So, I am really eager to get my hands around this product. Kudos to everyone involved in the creation of PB.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: Declarations

Post by Foz »

Check out XIncludeFile and IncludeFile in the help.
russellbdavis
User
User
Posts: 31
Joined: Wed Dec 02, 2009 4:50 pm
Location: Oklahoma City, OK
Contact:

Re: Declarations

Post by russellbdavis »

Thanks will do!
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Declarations

Post by Mistrel »

Freak highlighted the benefit of a two-pass compiler in this post:

http://www.purebasic.fr/english/viewtop ... =3&t=40162

There are also several other posts with various discussions about it and a post somewhere on the "Tricks 'n' Tips" board with a tool that will parse your code and generate declarations automatically.
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Declarations

Post by Kurzer »

Mistrel wrote:...and a post somewhere on the "Tricks 'n' Tips" board with a tool that will parse your code and generate declarations automatically.
Advertising :roll:
Declare-Filter
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Declarations

Post by IdeasVacuum »

it appears the DECLARE for procedures must exist in the file where the procedure exists.
Hello Russell

The good news is that the Declares can be in a single file, providing that file is your "main" file, i.e. the one you have active when the compiler is run. The main file does not have to contain any of the procedures. Put the Declares right at the top of the file, before the IncludeFile entries. - I switch on EnableExplicit to prevent my sloppy code from getting too bad. So, my "Main" file usually consists of the Declares, Global vars, Structures, Font specifiers, Image Plugins, Image catche, Loading of a prompts (Catalog) file and then the Includes, followed by a call to one of the procedures that gets the application ball rolling.

I am a PB newbie and I do not have any real experience with VB either, mostly C/C++ and a bit of C# (not really a fan of .Net). What I can say about PB is that I wish I had found out about it sooner! The tiny size of the exe files it produces will amaze you.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
jamba
Enthusiast
Enthusiast
Posts: 144
Joined: Fri Jan 15, 2010 2:03 pm
Location: Triad, NC
Contact:

Re: Declarations

Post by jamba »

here is mine that I use:
http://www.purebasic.fr/english/viewtop ... 12&t=41339

kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own :P
-Jon

Fedora user
But I work with Win7
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Declarations

Post by Trond »

but it appears the DECLARE for procedures must exist in the file where the procedure exists.
Think of it like this: The PB compiler really compiles just one big file. To automatically copy-and-paste the contents of other files into this bigfile, use XIncludeFile or IncludeFile.

Declares can be in a separate file, but it must be included in the main file before the procedures are used.

IMO there is really no reason for using a lot of declares. If you put your procedures in multiple files and include those, it will have the same effect.
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Declarations

Post by UserOfPure »

Trond wrote:IMO there is really no reason for using a lot of declares.
Depends on your app. Procedures can call other procedures, and sometimes Declares are needed, full stop. You simply can't always have your procedures in the exact order that you want, and Declares come to the rescue in these situations.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Declarations

Post by Trond »

UserOfPure wrote:
Trond wrote:IMO there is really no reason for using a lot of declares.
Depends on your app. Procedures can call other procedures, and sometimes Declares are needed, full stop. You simply can't always have your procedures in the exact order that you want, and Declares come to the rescue in these situations.
I said there wasn't a reason for using a lot of declares. Not that they are never required. I've seen code where all procedures are declared, and I think it's a waste of time.
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Declarations

Post by UserOfPure »

I know. One of my apps needs several declares, about 8. I consider that a lot, but my app won't run without them. I agree that declaring everything is unwarranted most of the time, but I suppose people are just playing it safe, and it doesn't waste anything except a bit of source code.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Declarations

Post by Kaeru Gaman »

I think it's just a matter of what you are used to.
when I started programming I learned to start my program at the top and scroll down to find the subroutines.
when I first programmed in C it turned me upside down, but I learned to deal with it instead of wasting my time with tons of declares.
when I came to PureBasic, it was just a matter of rewarming old habits.
oh... and have a nice day.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Declarations

Post by Kaeru Gaman »

whom you're adressing? :o
oh... and have a nice day.
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Declarations

Post by Kurzer »

jamba wrote:kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own :P
Sorry jamba, I overlooked your post. :oops:
Thats strange, there is no special magic in my plain HTML coded website.

But please look in this thread. In the 3dr post you'll find the direkt download link to the zip archive of Declare-Filter (if you still want to have a look on it).
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
jamba
Enthusiast
Enthusiast
Posts: 144
Joined: Fri Jan 15, 2010 2:03 pm
Location: Triad, NC
Contact:

Re: Declarations

Post by jamba »

kurzer wrote:
jamba wrote:kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own :P
Sorry jamba, I overlooked your post. :oops:
Thats strange, there is no special magic in my plain HTML coded website.

But please look in this thread. In the 3dr post you'll find the direkt download link to the zip archive of Declare-Filter (if you still want to have a look on it).
ok, cool, thanks!
I'll take a look, I can always learn from someone else's code :)
I don't even really use my own declarations tool much anymore (unless I just can't compile or something like that)--but usually it is just one or two procedures that need to be declared.
-Jon

Fedora user
But I work with Win7
Post Reply