Page 9 of 22
Re: Blog post !
Posted: Tue Mar 16, 2021 5:26 am
by Paul
BarryG wrote:
Nope. Gosub/Return is much faster. Look:
Remember the rule of "never do speed tests with debugger on"
Debugger On: 1113 / 798
Debugger Off: 13 / 20
Code: Select all
Global a
Procedure test()
a+1
EndProcedure
start.q=ElapsedMilliseconds()
For n=1 To 10000000
test()
Next
t1= ElapsedMilliseconds()-start
; -----------------------------------------
a=0
start.q=ElapsedMilliseconds()
For n=1 To 10000000
Gosub test2
Next
t2= ElapsedMilliseconds()-start
MessageRequester("",Str(t1)+Chr(10)+Str(t2))
End
test2:
a+1
Return
Re: Blog post !
Posted: Tue Mar 16, 2021 9:20 am
by marc_256
Hello everyone,
1) I'm programming since 1976 in BASIC and ASM (yes, I'm old) 8, 16, 32, and now these days 64 bits ...
and I still use a lot GOTOs and GOSUBs in my programs.
Why, this is very close to assembly programming logic (JMP / JSR).
If I look to Pauls test here,
Debugger Off: 13 / 20
for 10 000 000 gosubs ?
this is 0.020 sec / 10 000 000
2) About one pass compiler or two pass compiler,
for me personally, I like a very good working compiler, so one or two passes.
My last program is about 1600000 lines and this takes about 6 sec to compile,
and what if it takes 9 sec with a two pass compiler ?
Q) I'm not a C or C++ programmer at all (I tried some time ago),
but my question is, why do we need to switch to C (help) ?
Is there a special reason for ?
For me personally, I'm more interested in 2D/3D upgrades like OGRE
thanks,
greets, marc
Re: Blog post !
Posted: Tue Mar 16, 2021 9:23 am
by Keya
marc_256 wrote:Q) I'm not a C or C++ programmer at all (I tried some time ago),
but my question is, why do we need to switch to C (help) ?
Is there a special reason for ?
see Fred's March 2021 blog post -
https://www.purebasic.fr/blog/?p=480
ps. fricken Apple changing their fricken CPU ISA every few years, so annoying for developers!
Re: Blog post !
Posted: Tue Mar 16, 2021 10:04 am
by Saki
Well,
the first OS written with C was TOS.
This was very much at the expense of speed and the size robbed almost all free memory.
Then it became the standard, the compilers got better and better.
It's still dimensions easier to learn C than assembler, better to handle, better to debug.
Primarily there is no way around it if PB wants to survive in the future, C is the gateway to the world.
Re: Blog post !
Posted: Tue Mar 16, 2021 12:40 pm
by Tenaja
Rinzwind wrote:skywalk wrote:@Fred...
Also a more efficient string type. Length prefixed. So it can contain binary data to. Never use special data to control the same data (0-termination...). There various c libs available that attempt to solve that while still having backward compatibility where needed.
Open minded

+1!
A second, more efficient string library would be appreciated by all who use strings extensively! My requests would be...
Minimum allocated size set at declaration (to avoid numerous reallocations and copying when we know in advance it will gradually grow to a larger size)
Length stored, to avoid repeatedly counting length
Re: Blog post !
Posted: Tue Mar 16, 2021 12:47 pm
by Tenaja
marc_256 wrote:
If I look to Pauls test here,
Debugger Off: 13 / 20
for 10 000 000 gosubs ?
this is 0.020 sec / 10 000 000
Q) I'm not a C or C++ programmer at all (I tried some time ago),
but my question is, why do we need to switch to C (help) ?
Is there a special reason for ?
For me personally, I'm more interested in 2D/3D upgrades like OGRE
thanks,
greets, marc
Marc, in a nutshell, the change would be transparent to us users. However, the flexibility it adds is endless, primarily the benefits of new targets (ARM, for the new Macs, which means new things...hopefully Raspberry Pi etc...) And C lets you choose your favorite compiler. That means you can compile as fast as you want, or make code as fast as you want. Want smallest exe? Use gcc with all optimizations... And it's better than current pb output. Want fast debugging? Use gcc without optimizations... And the added time will likely be negligible...
As for Ogre, since it'll now be compatible with C, you can use whatever C library you want. Updating libraries should be as simple as copying a library over, and you can use any version you want.
Re: Blog post !
Posted: Tue Mar 16, 2021 2:38 pm
by User_Russian
Rinzwind wrote:Exactly why I want the option to extend structures with procedures so we get instance-style programming finally easy for the ones wanting it. Up to now we have to resort to hacks of various complexity and too much boiler plate
To do this, PB needs to be translated to C ++. More precisely, translate to C, but compile with a C ++ compiler. Then inline C ++ will be available, which means classes, templates and many other useful things.
Re: Blog post !
Posted: Tue Mar 16, 2021 3:22 pm
by skywalk
User_Russian wrote:Rinzwind wrote:More precisely, translate to C, but compile with a C ++ compiler. Then inline C ++ will be available, which means classes, templates and many other useful things.
That is a game changer! So many libs are C++ and making wrappers is painful.
Re: Blog post !
Posted: Tue Mar 16, 2021 3:51 pm
by User_Russian
It is easier to include C/C++ files to PB project than to rewrite all the code to PB.
Re: Blog post !
Posted: Tue Mar 16, 2021 4:32 pm
by Mindphazer
Keya wrote:ps. fricken Apple changing their fricken CPU ISA every few years, so annoying for developers!
But so exciting for users !
Re: Blog post !
Posted: Tue Mar 16, 2021 6:48 pm
by IceSoft
User_Russian wrote:It is easier to include C/C++ files to PB project than to rewrite all the code to PB.
Rewrite PB to C

C (not PB) will be compiled to "apps".
Re: Blog post !
Posted: Tue Mar 16, 2021 6:55 pm
by StarBootics
skywalk wrote:User_Russian wrote:Rinzwind wrote:More precisely, translate to C, but compile with a C ++ compiler. Then inline C ++ will be available, which means classes, templates and many other useful things.
That is a game changer! So many libs are C++ and making wrappers is painful.
I didn't read that Fred will make PureBasic an OOP language in the near future. But that will be nice !
Best regards
StarBootics
Re: Blog post !
Posted: Tue Mar 16, 2021 6:57 pm
by luis
With the new backed will PB continue to generate a single EXE with no additional dependencies to distribute with it (excluding OGRE) ?
Re: Blog post !
Posted: Tue Mar 16, 2021 8:36 pm
by Danilo
Rinzwind wrote:Exactly why I want the option to extend structures with procedures so we get instance-style programming finally easy for the ones wanting it. Up to now we have to resort to hacks of various complexity and too much boiler plate code... one simple addition...:
In
Rust you can implement functions/methods for structs. You simply implement methods that work on a data structure and you call it like in other languages: var.method(args)
Example:
-
Method Syntax
-
Rust by Example: Methods
There is no C++ compiler required to implement this, think „C with Objects“... or „PB with Objects“ in this case.
That reminds me of a book:
Extreme C => „This book shows how to implement OO principles in C, and fully covers multi-processing.“
It‘s available for free from packtpub:
Extreme C
Re: Blog post !
Posted: Tue Mar 16, 2021 11:25 pm
by StarBootics
Danilo wrote:There is no C++ compiler required to implement this, think „C with Objects“... or „PB with Objects“ in this case.

Code: Select all
#ifndef EXTREME_C_EXAMPLES_CHAPTER_6_1_H
#define EXTREME_C_EXAMPLES_CHAPTER_6_1_H
// This structure keeps all the attributes
// related to a car object
typedef struct {
char name[32];
double speed;
double fuel;
} car_t;
// These function declarations are
// the behaviors of a car object
void car_construct(car_t*, const char*);
void car_destruct(car_t*);
void car_accelerate(car_t*);
void car_brake(car_t*);
void car_refuel(car_t*, double);
#endif
This reminds me what Guimauve's Dev-Type program was generating back then. It's nothing new in town and to be honest I can't consider this OOP. Simply because you can still have access to the attributes of the so called "object" without using any methods at all. That being said, if you are master of self-discipline why not.
Best regards
StarBootics