Purpose of PureBasic

Everything else that doesn't fall into one of the other PB categories.
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Purpose of PureBasic

Post by geoff »

A recent thread discusses the relative merits of string types as used in C and Basic. IMO zero terminated strings was a bad choice for Purebasic because it is incompatible with other Basics and less powerful for the user. With conventional Basic strings it is easy to add or remove chr(0) for compatibility with API functions but with zero terminated strings it is difficult to rewrite existing Basic routines. In practice you have to use memory buffers, so writing your own string routines.

I think this is an example of a more general point that warrants a separate thread. That is, what is the purpose of a language like PureBasic?

Many of us use a high level language like Basic because it is more productive than using a low level language like C. In my experience it is several times quicker to write an application in Basic than to write it in C. This is because the language includes simple to use functions that allow us to do powerful things without extensive knowledge of the OS. For example, the 2D drawing functions of Purebasic.

This approach has other benefits. For example, when the OS changes the compiler can be modified to allow existing PB programs to operate as before. Thus one person has to change one program (ie the compiler) and the rest of us need take no action. Nor do we all need extensive current knowledge of the API.

You can include machine code and API calls in your code, and for some people this is an opportunity to learn more about the processor hardware and the OS. But once you do this, your code is less portable across different hardware and OS'es, now and in the future. Professional software is sometimes written and validated to meet strict language standards to ensure this portability and future proofing.

Personally, I am interested in writing useful applications with minimal effort, not in wasting my life assimilating the byzantine complexity of an ever changing Microsoft software interface.

So IMO the language design guideline should be "what is easy for the user?" and not "what does C do?" and not "what's in fashion at Redmond this year?".
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

While I agree with some of your comments, I cannot agree in general. You forget about "choice" and "compromise". PB allows you to concentrate more on the application you are developing and less on the language/compiler, still leaves you with the choice of using PB routines *OR* OS routines *OR* coding in assembler *OR* even coding part of your app in a different language, and all without compromising on speed/ features.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

interesting thread, though i guess that for fred, the prime interest is: make money :-)

but on a serious note: make effective, fast, working code with minimal effort, for people that are not full time programmers and don't think it's fun to dig into the esoteric art of programming c++

on the string thing: no, i don't think it was a bad decision at that time, it looks a lot like c, and in itself there's nothing wrong with it, it's just that all us basic lovers are used to misusing our strings for other things :-)

however, there is nothing wrong with expanding / improving a language :-)

as long as purebasic helps me create properly working code with an acceptable amount of effort, i'll be a happy camper
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
plouf
Enthusiast
Enthusiast
Posts: 282
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Post by plouf »

i don't get it this topic seems to recycle it self after some period of time and the origin of the problem imo is that people comming from other dialects
expect the compiler to read its mind and produce code ,even for simple thinks.
instead of try to indergreate themself in the enviroment that pb is
Christos
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

PureBasic having basic in the name does tend to throw people off. Personally I'm of the opinion that the language should not be made less powerful just to be more in line with other "basic" languages. PB already has structures, pointers, linked lists and much more that you don't see in many other basics.

I love saying this, but the only thing that's basic about PureBasic is the name :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

plouf wrote:... the origin of the problem imo is that people comming from other dialects expect the compiler to read its mind and produce code ,even for simple thinks.instead of try to indergreate themself in the enviroment that pb is
Christos:
Mostly all PB users had starting with other dialects, and is logic that each one of us wants the best features from our previous basic implemented in PB.

I see no evil in the WishList; PB is the best Basic, but still in progress,
and the WishList exists only as a help for Fred's own decisions.
Otherwise, why Fred and/or the PB staff are asking:

Got an idea for enhancing PureBasic?
New command(s) you'd like to see?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Personally I'm of the opinion that the language should not be made less powerful just to be more in line with other "basic" languages. PB already has structures, pointers, linked lists and much more that you don't see in many other basics.
This is exactly why i love and use PB :D
--Kale

Image
plouf
Enthusiast
Enthusiast
Posts: 282
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Post by plouf »

einander wrote: Christos:
Mostly all PB users had starting with other dialects, and is logic that each one of us wants the best features from our previous basic implemented in PB.

I see no evil in the WishList; PB is the best Basic, but still in progress,
and the WishList exists only as a help for Fred's own decisions.
Otherwise, why Fred and/or the PB staff are asking:
my point was not that we must not adopt or add features from other dialects but that it not nececary to throw out the way pb works .
In this case i said it about the null terminated string i don't see a reason to change because "others" have it diffirently ...
Christos
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

plouf wrote:my point was not that we must not adopt or add features from other dialects but that it not nececary to throw out the way pb works .
In this case i said it about the null terminated string i don't see a reason to change because "others" have it diffirently ...
You are right plouf, it is too late to change it now, my point was that the original choice was probably the wrong one. The only option now is maybe to add a second string type.

But my overall point was that a high level language should allow the programmer to do powerful things without knowledge of the OS or resort to writing in other languages or machine code. I agree these facilities should be included in the language, but a good high level language would make their use less frequent.


Let me give an example of high level language routine.
Input a message from the keyboard, encipher it and send it to the serial port:

Code: Select all

Input(message$)
coded_message$=encipher_string(message$); proc not included here
open "out",#1,"com1","9600"
print #1,coded_message$
close#1
Now that's easy to understand isn't it?
It's also hardware and OS independent.

Now try and do that in C or Purebasic.

You can't assign the enciphered text to a string variable because it may include chr(0). So you have to use malloc() and pointers. More complicated and plenty of scope for bugs.

You can't simply access the serial port because C or Purebasic don't include this as part of the language. You have to write a page of API stuff, setting up buffer sizes, priorities, callback messages and so on. Then as soon as a new version of the OS comes out you have to rewrite all this stuff.

I admit that we have to resort to machine code and OS stuff sometimes, we can't expect our language to include everything we would ever want. But look at my example. This is simple stuff which was included in primitive dialects of Basic 25 years ago.

Do we want to create easily understood, portable code in a simple manner or do we want to play with the intricacies of the OS and use primitive machine code constructs just to show how clever we are?
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Zero-terminated forever!

Post by Hi-Toro »

I much prefer things as they are. It would drive me nuts to have to keep adding + Chr (0) every time I called an OS function!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

You can't assign the enciphered text to a string variable because it may include chr(0). So you have to use malloc() and pointers. More complicated and plenty of scope for bugs.
So you can't use encoding or encryption in C!? Ack! :-)

You're absolutely right about your pseudo code not working - but you would never print binary data out like that anyway.. You'd run the data returned from your encrypt/encode function through a hex conversion or something like that..

One of the functions I use to encrypt data in PHP using the mcrypt lib :

Code: Select all

        /*
         * Encrypts data in ECB mode with 3DES cipher.
         * 
         * Returns the encrypted data as a string of HEX digits.
         */
        function
        encrypt_data($xData)
        {
                srand((float) microtime() * 1000000);

                $rModule = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
                $rIV = mcrypt_create_iv(mcrypt_enc_get_iv_size ($rModule), MCRYPT_RAND);
        
                mcrypt_generic_init($rModule, (G_CRYPTOKEY), $rIV);
                $xEncdata = mcrypt_generic($rModule, $xData);
                mcrypt_generic_deinit($rModule);
                mcrypt_module_close($rModule);

                $sHEXtext = bin2hex($xEncdata);
        
                return("_$sHEXtext");
        }
        // encrypt_data()
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

geoff wrote: To be constructive, what I am saying is that I would like to do useful things in a simple manner without recourse to using other languages, API calls or 3rd party DLLs.

Why?

Because the code is easier to write, more portable, less OS dependent and, less hardware dependent.
When I started with PureBasic a few years ago I thought this is exactly the main goal of PureBasic.

But obviously it's not. :cry:

If you code nice stuff, you need always Win-API - that's bad when you want to convert your code to Linux...
Sure you can use CompilerIF and so on.
But for this you have to learn GTK-API...

That is what I call a simple to learn Basic language :wink:
Last edited by fsw on Sun Nov 02, 2003 7:49 pm, edited 1 time in total.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

Karbon wrote:but you would never print binary data out like that anyway..
I'm not printing it out.
This is how you write a binary string to a file in old Basics.

I'm trying to be constructive here.
KISS -- keep it simple, stupid

Simple code written in high level language without recourse to API functions, machine code or 3rd party DLLs has many advantages.

You have a good chance of re-using your code for years to come !! :)


(this message was originally before the one above)
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Geoff, constructive suggestion: why not use PB's memory functions (x-platform?) for this kind of thing? Doing it in strings is IMHO a bid dodgy anyway.
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

API is allowed in PureBasic to not limit the coder. You don't need to use it to do 'nice' things. Of course, WinAPI is 60000 functions, so if you want to do all the nice stuffs available on Windows I need to wrap all the Windows functions, sure it will give power and platerform independant (hum...). The purpose of PureBasic is to allow to build an application which can run on different OS while being still as compact, fast and OS compliant as possible. Of course there is some stuffs lacking, but it all depends of what you are doing.

For example, I often need MD5 encryption routine. Other Basics have building encryption/fingerprint support ? I hope yes, else it would be no use for me.

PureBasic is build to be modular, ie extensible via 3rth part libraries. I saw a nice COM port library developped by marc which is very easy to use, so why not use it..

Every languages have its pro and con, just fit with the one which fits your needs now, not in a few months or year.
Post Reply