October 06, 2022, 10:40:30 AM


IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

1. Introduction

Started by LarryMc, October 13, 2014, 04:59:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


From the IWBasic User's Guide:
Projects are the heart of multi module programming and combine all of the source files and resource information into a centralized project module. Using projects you can create very complex programs by separating your source code over multiple files and libraries. Subroutines and variables in source files can be either local or shared globally between files for ease of data reuse.

That paragraph covers a lot of ground.  Let's expand upon that.

But first we need to discuss two terms that each have multiple meanings and can cause quite a bit of confusion.

IWBasic allows two different methods of creating an application or project.
In this statement project refers to the overall effort that defines what the user is trying to accomplish.

If we are discussing the methods the user may use to create the application the two terms are  Single File and Project.
In this context Single File describes the method of creating the application or project.

When we say that Single File projects are single file,  it means that Single File applications are compiled from a single file.

We can also say that a Project can be single file. This means that our Project contains a single file and the application is compiled from that.

Therefore, the following are true statements:
A Single File application can contain only one single file(source file).
A Project application can contain as few as one single file(source file) but most often contains multiple source files.

Anyone who has used IWBasic for any amount of time knows how to create a Single File application.  Therefore that method is not in the scope of this tutorial.


Why choose the Project method over the Single File method for creating an application?

Our good friend Graham recently made some comments about using Projects that a lot of people have stated in the past:
"I've never used a 'project' in all the years I've been programming."

"In the little example you give, I'd write the 'main' code, and tuck the subroutine at the end of it. Then it all is visible, editable, and compiles in one go. ."

"It may be that if you get a huge program, the compile time becomes noticeable - but even with my largest ever program, I've never noticed it."

Graham's comments are right-on for the majority of hobby programmers and I can't say they are wrong.

But there are a few of us hobby programmers that Projects make a lot more sense.

For example the IWBasic2.5 beta contains 30,000 lines of code with 657 subroutines.
By spreading that out into 50+ source files and grouping subroutines by functionality along with descriptive naming of the source files it makes it real easy to know where to look to make modifications/corrections without doing a lot of scrolling through irrelevant code or a combobox with 600+entries. In my other library offerings the same applies but on a slightly smaller scale.

Although I don't always do it, by using the OnMessage, OnMenu, and OnControl commands you can clean out message handler routines and put all the desired code in subroutines that can be grouped in separate source files.  Doing so eliminates searching through huge message handlers. It reduces the message handler down to the @idcreate  or @idinitdialog messages only

Once I get all the source code in a given source file exactly like I want it I never have to look at the code again(no scrolling over it to get to other code)

When you write a program with 30,000 lines compile time is significant.  It takes over a minute to recompile the program.
With Projects, once you compile the entire project the first time you only need to recompile the source file you change and then relink the project which takes less than 10 seconds.  The only exceptions are when you change a global variable(add/delete) or an include file.

A major plus of Projects is that you can add other files as resources(images, dialogs, html files,etc).  This allows you to distribute your exe files without having to also distribute all of those extra files in the same folder or a subfolder.

Another plus with Projects (as I've stated elsewhere) comes when you are building lib files which I've done a lot of.
1st I create a project with 2 source files. The $main file looks like a User's application that calls the lib functions.  The other is the source file(s) for the lib.
With this arrangement I can do all my testing without having to create a new lib file each time I make a change and copying the lib file to the IWBDev\libs folder.
When I'm ready to create the lib for release I create another project containing just the lib source files and compile it as a static lib.  It really speeds up the process.

This concludes  1. Introduction.
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library