Blog post !

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1252
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Blog post !

Post by Paul »

BarryG wrote: Nope. Gosub/Return is much faster. Look:

Remember the rule of "never do speed tests with debugger on" :wink:

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
Image Image
marc_256
Enthusiast
Enthusiast
Posts: 744
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Blog post !

Post 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
Last edited by marc_256 on Tue Mar 16, 2021 9:32 am, edited 2 times in total.
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Blog post !

Post 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!
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Blog post !

Post 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.
地球上の平和
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Blog post !

Post 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 :idea:
+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
Last edited by Tenaja on Tue Mar 16, 2021 5:38 pm, edited 2 times in total.
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Blog post !

Post 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.
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Blog post !

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 3995
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Blog post !

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Blog post !

Post by User_Russian »

It is easier to include C/C++ files to PB project than to rewrite all the code to PB.
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 341
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Blog post !

Post by Mindphazer »

Keya wrote:ps. fricken Apple changing their fricken CPU ISA every few years, so annoying for developers!
But so exciting for users !
MacBook Pro 14" M1 Pro - 16 Gb - MacOS 14 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Blog post !

Post 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".
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Blog post !

Post 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
The Stone Age did not end due to a shortage of stones !
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Blog post !

Post by luis »

With the new backed will PB continue to generate a single EXE with no additional dependencies to distribute with it (excluding OGRE) ?
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Blog post !

Post 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
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Blog post !

Post 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
The Stone Age did not end due to a shortage of stones !
Post Reply