Do procedures really have to appear first?

Just starting out? Need help? Post your questions and find answers here.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: Do procedures really have to appear first?

Post by Bitblazer »

jacdelad wrote: Thu Aug 04, 2022 3:25 pmI think it's best to try it out.
And join the discord purebasic chat. See my signature for the link.
webpage - discord chat links -> purebasic GPT4All
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Do procedures really have to appear first?

Post by skywalk »

If just starting out, avoid projects. They are restrictive within the IDE.
Using includes, you can have any files loaded within the IDE and simply hit compile.
Using projects causes different behavior with non-project files.

Keep it simple.
As mentioned, PB is a single pass compiler. Choose your coding technique appropriately.
But always use EnableExplicit.
Modules, or include files using prefixes(my preference) mylib.pbi, mylib_myproc1(), etc.
Includes have no restrictions other than naming conflicts and order of compilation which you control with your Declarations or ordering of individual procedures. In ~100k loc, I have maybe 4 declares, because I manage the location of procedures & variables within the lib files.
It is very simple.
Modules are not. Modules require lots of Declares, MyModule::myProc() and conflicts with Macro's require tricks that are not intuitive.

You have choices. It is up to your workflow.
I prefer to avoid syntax sugar like OOP or project related errors.
I only want to debug code and deploy my exe.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Do procedures really have to appear first?

Post by Oso »

jacdelad wrote: Thu Aug 04, 2022 3:25 pm The project combines your sources and additional files plus additional info and settings into one file.
Try it, create a new project, give it a name. Then add a source file to the project. Now navigate to the project tab and set up all the settings for the project as you like (main source code, threadsafe, version info, which exe to create, icons...).
That's fine, I've created a project and added my .PB and .PBF to it and a configuration file. The project tab is neat, with its ability to add any kinds of files. I notice the way in which you can right-click the upper Project Files box and add files, but you can't do the same with the lower Project Targets box. It's necessary to go into Compiler Options and do it through that.

The Build All Targets option is nice. Most sizable systems don't have just a single executable. We need something like this to make sure everything is recompiled.

One strange thing I notice is that after closing a project, it obviously writes something finally to the .PBP file (it updates the file's timestamp), which consequently means that when I open the project again (either by finding the .PBP file in Windows explorer and double-clicking it OR via Open Project in PB) it complains by showing the below. The file hasn't been modified by me, or by the O/S, but it has been modified on closure by the IDE. It seems wrong to say the file has changed, when it's the IDE that's changed it.

https://imgur.com/a/UOKEA9b
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Do procedures really have to appear first?

Post by Oso »

skywalk wrote: Thu Aug 04, 2022 5:01 pm I prefer to avoid syntax sugar like OOP or project related errors.
I only want to debug code and deploy my exe.
Yes, if you mean Visual Studio's incessant syntax error checking while you're typing and haven't completed making the changes you need, I agree there. There's been times when VS is trying to prevent me from making the very corrections that are needed to satisfy its own syntax checking!
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Do procedures really have to appear first?

Post by Marc56us »

Oso wrote: Thu Aug 04, 2022 6:02 pm One strange thing I notice is that after closing a project, it obviously writes something finally to the .PBP file (it updates the file's timestamp), which consequently means that when I open the project again (either by finding the .PBP file in Windows explorer and double-clicking it OR via Open Project in PB) it complains by showing the below. The file hasn't been modified by me, or by the O/S, but it has been modified on closure by the IDE. It seems wrong to say the file has changed, when it's the IDE that's changed it.

https://imgur.com/a/UOKEA9b
When you close the project, the project manager takes an MD5 fingerprint of all the files in the project. This is an integrity check to know if one of the sources has not been modified by another program (see *.pbp file, MD5 fingerprint line)

The text of the message is not very accurate "while the project was closed" , it should be "after the project was closed"

If you get this message even though you haven't modified any of the project files outside the IDE, check that you haven't got a virus or simply replaced a file with another (version) one after closing

:wink:
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Do procedures really have to appear first?

Post by Oso »

Marc56us wrote: Thu Aug 04, 2022 8:25 pm When you close the project, the project manager takes an MD5 fingerprint of all the files in the project. This is an integrity check to know if one of the sources has not been modified by another program (see *.pbp file, MD5 fingerprint line)
The only file that's changing is the .PBP and consequently its own MD5. None of the other project files change and neither do their individual MD5s. The warning message shows it's the .PBP that has the MD5 mismatch, not the project files, and I can see that the IDE is changing the timestamp in the .PBP file...

<lastopen date="2022-08-04 21:32" user="admin" host="WINDOWS10PRO"/>

and also a flag against each project file ...

lastopen="0"

The change is being made by the IDE, on exit, not thereafter. I appreciate it's probably difficult to make a comparison between the two copies the .PBP below but having the before-and-after version side by side on my screen, I can see that the only variations are the timestamp and the lastopen indicators. Other than that, the files are identical XML.

.PBP before opening the project...

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 6.00 LTS (Windows - x64)">
  <section name="config">
    <options closefiles="1" openmode="1" name="New Project"/>
  </section>
  <section name="data">
    <explorer view="" pattern="0"/>
    <log show="1"/>
    <lastopen date="2022-08-04 19:07" user="admin" host="WINDOWS10PRO"/>
  </section>
  <section name="files">
    <file name="config.txt">
      <config load="0" scan="0" panel="1" warn="1" lastopen="0" panelstate="+"/>
      <fingerprint md5="098f6bcd4621d373cade4e832627b4f6"/>
    </file>
    <file name="console.pb">
      <config load="0" scan="1" panel="1" warn="1" lastopen="0" panelstate="+"/>
      <fingerprint md5="5fc4472644577180c958deb49280267a"/>
    </file>
    <file name="new_test.pb">
      <config load="0" scan="1" panel="1" warn="1" lastopen="0" panelstate="+"/>
      <fingerprint md5="e694124c8295ee3ea2e9c7a4839c24a5"/>
    </file>
    <file name="new_test.pbf">
      <config load="0" scan="1" panel="1" warn="1" lastopen="0" panelstate="+"/>
      <fingerprint md5="b4dc0737af1a674658eca8f008b3eb03"/>
    </file>
    <file name="new_test.pbp">
      <config load="0" scan="0" panel="1" warn="1" lastopen="0" panelstate="+"/>
      <fingerprint md5="df1513e9cb8db1670cf8c63e5dec11a9"/>
    </file>
  </section>
  <section name="targets">
    <target name="Default Target" enabled="1" default="1">
      <inputfile value="new_test.pb"/>
      <outputfile value="new_test.exe"/>
      <compiler version="PureBasic 6.00 LTS (Windows - x64)"/>
      <executable value="new_test.exe"/>
      <options xpskin="1" dpiaware="1" debug="1" optimizer="0"/>
    </target>
    <target name="console" enabled="1" default="0">
      <inputfile value="console.pb"/>
      <outputfile value="console.exe"/>
      <compiler version="PureBasic 6.00 LTS (Windows - x64)"/>
      <executable value="console.exe"/>
      <options optimizer="0"/>
    </target>
  </section>
</project>
.PBP after opening and immediately closing the project...

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 6.00 LTS (Windows - x64)">
  <section name="config">
    <options closefiles="1" openmode="1" name="New Project"/>
  </section>
  <section name="data">
    <explorer view="" pattern="0"/>
    <log show="1"/>
    <lastopen date="2022-08-04 21:32" user="admin" host="WINDOWS10PRO"/>
  </section>
  <section name="files">
    <file name="config.txt">
      <config load="0" scan="0" panel="1" warn="1" lastopen="1" panelstate="+"/>
      <fingerprint md5="098f6bcd4621d373cade4e832627b4f6"/>
    </file>
    <file name="console.pb">
      <config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
      <fingerprint md5="5fc4472644577180c958deb49280267a"/>
    </file>
    <file name="new_test.pb">
      <config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
      <fingerprint md5="e694124c8295ee3ea2e9c7a4839c24a5"/>
    </file>
    <file name="new_test.pbf">
      <config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
      <fingerprint md5="b4dc0737af1a674658eca8f008b3eb03"/>
    </file>
    <file name="new_test.pbp">
      <config load="0" scan="0" panel="1" warn="1" lastopen="0" panelstate="+"/>
      <fingerprint md5="33515d42ebfe3e7d81b672fbcabfbbd3"/>
    </file>
  </section>
  <section name="targets">
    <target name="Default Target" enabled="1" default="1">
      <inputfile value="new_test.pb"/>
      <outputfile value="new_test.exe"/>
      <compiler version="PureBasic 6.00 LTS (Windows - x64)"/>
      <executable value="new_test.exe"/>
      <options xpskin="1" dpiaware="1" debug="1" optimizer="0"/>
    </target>
    <target name="console" enabled="1" default="0">
      <inputfile value="console.pb"/>
      <outputfile value="console.exe"/>
      <compiler version="PureBasic 6.00 LTS (Windows - x64)"/>
      <executable value="console.exe"/>
      <options optimizer="0"/>
    </target>
  </section>
</project>
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Do procedures really have to appear first?

Post by Olli »

I have a strange solve if you do not want to declare neither to worry about procedure :
1/2 : you makes procedures by an other way
2/2 : you call procedures by an other way

This other way consists in typing the procedure heads...

Code: Select all

Procedure.i myProc()
... and recording this source code string in a global mapped table.

Code: Select all

procHead("myProc") = "Procedure.i myProc()"
*proc("myProc") = @myProc()
Procedure.i myProc()
To call the procedures, you use CallFunctionFast().

Code: Select all

CallFunctionFast(*proc("myProc") )
It is slower. It is complex too.

But there are convenients even :
- no worries about procedures order (as wanted)
- the user can watch the design of your program
- you can add a very powerful history
- the user can switch/modify the calls on the fly
- thread use is enabled

2 macros can be used to simplify this concept.
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Do procedures really have to appear first?

Post by blueb »

I agree with pretty much everything that skywalk says...

Modules, etc. can be handy, but an Include file done properly can make your programming so much easier.

Also get to know the PureBasic IDE. It's really very good and can make your life much easier. Fred and Timo did a very good job here. Of course I changed the colors (yellow is not my favorite) {grin}

Get to understand the 'Preferences' dialog to set up the IDE to your liking.

For example I have included the 'Code Templates' in my IDE and have over 2500 lines of code in my Templates.prefs file.

With such things as quick methods to add code into my programs, such as:
- Starter templates
- Inject prefs file code
- add previously built Macros
- WinAPI code
- Special formatting, etc.
- Error fixes for various versions (Ascii fixes, etc.)

All in all, the PureBasic IDE is a real time saver, when combined with this forum.

There are very few sites where you can copy the forum users code, plop it into your IDE and compile the code... all with in 2 seconds! Think about that.. it's amazing.
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Janni
Enthusiast
Enthusiast
Posts: 127
Joined: Mon Feb 21, 2022 5:58 pm
Location: Norway

Re: Do procedures really have to appear first?

Post by Janni »

blueb wrote: Fri Aug 05, 2022 2:02 pm
With such things as quick methods to add code into my programs, such as:
- Starter templates
- Inject prefs file code
- add previously built Macros
- WinAPI code
- Special formatting, etc.
- Error fixes for various versions (Ascii fixes, etc.)
Wasn't aware of these capabilities. Will check them out, thanks :D
Spec: Linux Mint 20.3 Cinnamon, i7-3770K, 16GB RAM, RTX 2070 Super
User avatar
spikey
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Do procedures really have to appear first?

Post by spikey »

Oso wrote: Thu Aug 04, 2022 9:54 pm The only file that's changing is the .PBP and consequently its own MD5.
You have "<options openmode="1"/>". This is "load all sources of the project" in the Project Options dialog. The project file content therefore changes as soon as you open it because the IDE opens all of the files even if they weren't open the last time you closed the project and updates their status accordingly. This gets written back to the project file when you close it. There's nothing abnormal about this.

I'm not sure why you're getting the change notice though - I've been using projects for years and the only time I get this appear is if I've done something unusual outside of the current IDE, manually editing the xml, opening the project in multiple/different version of the IDE, having the xml open in a text editor and opening it in the IDE at the same time...
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Do procedures really have to appear first?

Post by Oso »

spikey wrote: Sat Aug 06, 2022 11:36 amThis gets written back to the project file when you close it. There's nothing abnormal about this.

I'm not sure why you're getting the change notice though
Thanks for the reply Spikey, it's helpful to read what you say. All the replies give us newcomers to PB a leap in knowledge. ;-)

Yes, it's strange that the message is triggered. I'll do some more investigation later and see if I can find what's actually triggering this. The project files were only created so that I could gain a better idea how the concept works, so I may be able to demonstrate which file is responsible, if any, although it's strange that the only change is the timestamp and the MD5 in the .PBP. I'll report back!
User avatar
spikey
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Do procedures really have to appear first?

Post by spikey »

Oso wrote: Thu Aug 04, 2022 9:54 pm The only file that's changing is the .PBP and consequently its own MD5.
Ah - that's what it is - took me a while to figure that out! You've got the project file itself in the project file list. The fingerprint of the project file gets calculated and stored in the project file but this changes the fingerprint of the project file so it doesn't match when it gets reopened and triggers the change notice...

The solution is to remove the PBP file from the list of project files, once you do that and close and reopen the project you should stop getting spurious notices. You don't need the PBP file in the list because it doesn't contain any code completion items.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: Do procedures really have to appear first?

Post by Oso »

spikey wrote: Sat Aug 06, 2022 8:04 pm The solution is to remove the PBP file from the list of project files, once you do that and close and reopen the project you should stop getting spurious notices. You don't need the PBP file in the list because it doesn't contain any code completion items.
Yes, we both found the problem together. Thanks for looking at this though. I noticed that when I created a new project, adding each file one at a time, the warning message didn't return, so then I began to question what I'd done differently.

The reason my first test project included the .PBP file is because of the approach I used. In the Project tab - Add Files to Project, I selected all files and then clicked Open. I didn't notice that it had added its own project file. But looking at the Add File to Project dialogue box, it even includes .PBP files in the drop-down list.

I've noticed that PB sometimes isn't quite as intuitive as it might be, with regard to file suffixes. If we create a new form design and click Save As, it doesn't default to .PBF. What it seems to do, is whenever you create something and save it, it offers all PB file types, irrespective of what has been created, i.e. .PB .PBI .PBF .PBP. I think that's okay for seasoned developers but it can make all the difference the first time we try something out. I realise of course that .PBFs are source code anyway, so perhaps it's difficult for the IDE to recognise that.
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Do procedures really have to appear first?

Post by Tenaja »

irrespective of what has been created...
Irrespective is one of my favorite underutilized words. It's like the grammatical version of fingernails on a chalkboard when someone uses "irregardless".
:D
AZJIO
Addict
Addict
Posts: 1315
Joined: Sun May 14, 2017 1:48 am

Re: Do procedures really have to appear first?

Post by AZJIO »

Templates.prefs.7z
config-PB.7z
If the program is called MyProg, then I make a ForMyProg include file and put the universal isolated functions there.
Post Reply