Best practics for programming crossplatform applications?

Just starting out? Need help? Post your questions and find answers here.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Best practics for programming crossplatform applications?

Post by Korolev Michael »

How do you organize your code in case of developing crossplatform applications?
Creating separate modules?
Or declaring procedures depending of current compiler?
Or something else?
Former user of pirated PB.
Now registered user :].
infratec
Always Here
Always Here
Posts: 7663
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Best practics for programming crossplatform applications

Post by infratec »

Hi,

it only needs some CompilerIf which I directly use inside the code itself.
I have only one piece of code which completely load different inlcudefiles:
For accessing the serialport with unusual baud rateswhich is only possible with many different
API calls.

And in general:
If you use threads... never use SetGadget... or StatusBarText()
Use PostEvent to do all viewing stuff in the main program.
Else you run into different kinds of trouble.

Bernd
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Best practics for programming crossplatform applications

Post by Lunasole »

I think it is enough just to use compilerif, but not for any small part to avoid extra code trashing.
I.e. if there are for example OS-depended code inside of procedure, it is reasonable to make a copy of whole procedure and use conditional compilation with it, instead of using it inside procedure (especially several times).
The modules me personally still didn't liked enough, as for me they looking useless unless they are "class modules" ^^ Although without modules other problems with Include/XincludeFile raising, but currently it doesn't take much time to resolve such conflicts.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Best practics for programming crossplatform applications

Post by Keya »

do you guys just use the one PBF file for each Dialog or do you have slightly-tweaked copies of each Dialog for each OS?

i ask because i find that forms designed in one OS often have controls at least slightly out of place or slightly too small/big when viewed in another OS, so it seems each control needs its own specific tweaking on each OS, but that would mean doing everything three times, and i cant use CompilerIf's because the Form Designer would overwrite them if i ever modified the form. Catch22²!
User avatar
TI-994A
Addict
Addict
Posts: 2752
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best practics for programming crossplatform applications

Post by TI-994A »

Keya wrote:...it seems each control needs its own specific tweaking on each OS, but that would mean doing everything three times, and i cant use CompilerIf's because the Form Designer would overwrite them if i ever modified the form.
Just one form file would suffice; simply tweak them in the code modules. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Best practics for programming crossplatform applications

Post by Keya »

yes but making the manual recalculations for each control's x/y/width/height or constantly retweaking/executing/inspecting/retweaking/executing/inspecting until it looks right is very laborious/time consuming compared to using the Form Designer where you correct the look of a control in just a few clicks and confirm visual correctness immediately
User avatar
TI-994A
Addict
Addict
Posts: 2752
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best practics for programming crossplatform applications

Post by TI-994A »

Keya wrote:yes but making the manual recalculations for each control's x/y/width/height or constantly retweaking/executing/inspecting/retweaking/executing/inspecting until it looks right is very laborious/time consuming compared to using the Form Designer where you correct the look of a control in just a few clicks and confirm visual correctness immediately
So, use the form designer to get the desired layout metrics, then simply use the generated values. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Best practics for programming crossplatform applications

Post by Marc56us »

You can use the Form Designer And manual code without problems.
Make Form with the VD with size for your OS and resize for others
Put Resize() code immediatly after OpenWindow().

Code: Select all

XIncludeFile "....pbf"

Zoom_Linux = ...
Zoom_Mac = ...

OpenWindow_0()
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
    ResizeWindow(#Window_0, #PB_Ignore, #PB_Ignore, x * Zoom_Linux, y * Zoom_Linux 
    ResizeGadget(#
    ...
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
    ResizeWindow(#Window_0
    ...
CompilerEndIf


Repeat
    ...
Forever
:wink:
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Best practics for programming crossplatform applications

Post by Fred »

For easy cross-plateform GUI, I would use the Dialog lib instead of using the form designer, as it will recalculate everything right depending of the OS default font.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Best practics for programming crossplatform applications

Post by Keya »

But to generate that XML you still have to manually type in all the x/y/width/height etc for every control, using your imagination to visualize? time consuming and laborious... or is there an XML Form Designer (or converter)? also i see if you use XML you need to include MIT license/copyright info with your app, not major but perhaps not always desirable
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Best practics for programming crossplatform applications

Post by Fred »

No, you don't have to use x,y,width,height, you just define the layout. It's easier once you get used to it and takes care of all OS little variations. The IDE only use dialogs for its window, which allows to have perfect render on all OS.
Post Reply