Heater
Posts: 13608
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 7:29 am

ScriptBasic,

Ha! Indeed the fibo(4784969) is frivolous. However some of us learned a lot along the way, about algorithms about languages and so on.

Now we have learned something about ScriptBasic. Not all wasted time then.
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 7:43 am

If you miss the BBC BASIC graphic syntax, ScriptBasic has an extension module for you.

Code: Select all

' BBC BASIC Fern - RPi

IMPORT bbc.bas

BBC::OPEN "ScriptBasic BBC fern - Raspberry Pi"
t1 = BBC::TIME()
BBC::MODE 31
BBC::ORIGIN 200, 100
BBC::OFF
BBC::GCOL 0, 10
x = 0
y = 0
FOR i = 1 TO 80000
  r = BBC::RND(1)
  IF r <= 0.1 THEN
    a = 0
    b = 0
    c = 0
    d = 0.16
    e = 0
    f = 0
  END IF
  IF r > 0.1 AND r <= 0.86 THEN
    a = .85
    b = .04
    c = -.04
    d = .85
    e = 0
    f = 1.6
  END IF
  IF r > 0.86 AND r <= 0.93 THEN
    a = .2
    b = -.26
    c = .23
    d = .22
    e = 0
    f = 1.6
  END IF
  IF r > 0.93 THEN
    a = -.15
    b = .28
    c = .26
    d = .24
    e = 0
    f = .44
  END IF
  newx = a * x + b * y + e
  newy = c * x + d * y + f
  x = newx
  y = newy
  BBC::MOVE 600 + 96 * x, 32 + 96 * y
  BBC::DRAW 600 + 96 * x, 32 + 96 * y
NEXT i
t2 = BBC::TIME()
t3 = (t2-t1)/1000
BBC::VDUSTR "Time: " & FORMAT("%.4f",t3) & " seconds"
BBC::WAITKEY
BBC::CLOSE
Attachments
BBC_BASIC_Fern_RPi.png
BBC_BASIC_Fern_RPi.png (30.54 KiB) Viewed 864 times

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 8:57 am

AIR resolved the issue of having to use sudo for ScriptBasic Perl issue.
There is no script for the included external libs, I did that manually.

BTW, to eliminate the requirement that the esd.pm module be installed (which requires root), edit setup.pl.

After the #!/usr/bin/perl add the following:

Code: Select all

use Cwd qw(cwd);
Then at line 177 change:

Code: Select all

$esdlocation = undef;
to

Code: Select all

$esdlocation = cwd;
This tells the setup.pl file to use the esd.pm that is in the current (sb-dev if using the source from git) folder.

AIR.

User avatar
Gavinmc42
Posts: 3892
Joined: Wed Aug 28, 2013 3:31 am

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 9:20 am

Wow saw that fern and had a flash back to my Microbee days.
First time I wrote a fractal program - in Basic too ;)

"Fractals Everywhere" Micheal Barnsley 1988
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Paeryn
Posts: 2701
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 10:44 am

ScriptBasic wrote:
Sun Apr 07, 2019 3:38 am
Here is the Fibonacci recursive benchmark for Python and ScriptBasic.

Python (Parcially Recursive)

Code: Select all

def recur_fibo(n):
   if n <= 1:
       return n
   else:
       return(recur_fibo(n-1) + recur_fibo(n-2))

nterms = 25

if nterms <= 0:
   print("Plese enter a positive integer")
else:
   for i in range(nterms):
      recur_fibo(i)
   print(recur_fibo(i))


[email protected]:~/sbrpi/examples $ time python fibonacci.py
46368

real 0m0.764s
user 0m0.726s
sys 0m0.030s
[email protected]:~/sbrpi/examples $


ScriptBasic (true recursive function)

Code: Select all

FUNCTION Fibonacci(n)
  IF n <= 2 THEN
    Fibonacci = 1
  ELSE
    Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2)
  END IF
END FUNCTION

PRINT Fibonacci(24),"\n"
[email protected]:~/sbrpi/examples $ time scriba fibonacci.sb
46368

real 0m0.863s
user 0m0.858s
sys 0m0.001s
[email protected]:~/sbrpi/examples $
A bit unfair there, your Python program first calculates each Fibonacci number from 0 to n-1 individually and them finally calculates and prints Fibonacci(n) whilst your ScriptBasic just calculates and prints Fibonacci(n). Also your Basic prints Fibonacci(24) whilst you had Python print Fibonacci(25).
The Python equivalent of your ScriptBasic code would be

Code: Select all

def recur_fibo(n):
   if n <= 1:
       return n
   else:
       return(recur_fibo(n-1) + recur_fibo(n-2))

print(recur_fibo(24))
So Python was calculating a lot more values (most were then being thrown away) and still it managed to be quicker!
She who travels light — forgot something.

User avatar
bensimmo
Posts: 4182
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 1:09 pm

And we should be avoiding Python2 now and moving on to Python3 ;-)

Of course which flavour of Python3 might determine 'speed' and of course the reuse of the cached files on the next go.

User avatar
scruss
Posts: 2546
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 1:31 pm

Re the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

ejolson
Posts: 3682
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 2:28 pm

scruss wrote:
Sun Apr 07, 2019 1:31 pm
Re the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
Where is the timing information? Have you gotten ScriptBasic to run on your Pi yet?

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 5:13 pm

Thanks scruss for the updated Python Fibonacci code.

Bottom line is BASIC is easier to learn than Python and for the most part beginners is our audience.

ScriptBasic is an interpreter not a compiler. Using the pre-processor debugger you can single step through the script, set break points and view the current status of variables.

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 5:41 pm

scruss wrote:
Sun Apr 07, 2019 1:31 pm
Re the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
Richard's BBC BASIC isn't open source and is a BASIC compiler. The BBC graphics extension module is a fork of Brandy's SDL BBC code.

User avatar
rpdom
Posts: 15376
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 5:56 pm

ScriptBasic wrote:
Sun Apr 07, 2019 5:13 pm
Bottom line is BASIC is easier to learn than Python and for the most part beginners is our audience.
Have you got anything to back that up?

I teach kids to code. Some of them use Python. They pick it up fairly quickly. I suspect they would have more trouble picking up (yet another version of) BASIC.

The only thing that takes a little getting used to on Python (especially if you are used to other languages) is that crazy indentation thing.

ejolson
Posts: 3682
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 5:56 pm

ScriptBasic wrote:
Sun Apr 07, 2019 5:41 pm
scruss wrote:
Sun Apr 07, 2019 1:31 pm
Re the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
Richard's BBC BASIC isn't open source and is a BASIC compiler. The BBC graphics extension module is a fork of Brandy's SDL BBC code.
Since about a year Richard's BBC Basic has been open source. The repository is here.

Speaking of BBC Basic, there is also a Fibonacci code written in that dialect of Basic here which has also not been added to the Fibonacci GitHub repository. This version in Visual Basic still seems missing as well. I wonder, did someone forget the password?
Last edited by ejolson on Sun Apr 07, 2019 6:12 pm, edited 2 times in total.

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 6:10 pm

Since about a year Richard's BBC Basic has been open source.
Good to know. I purchased his Windows version a few years ago.

I'm not a fan of having to define variable types. ScriptBasic uses a variant style variable environment.

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 6:23 pm

@ejolson,

Any luck getting ScriptBasic compiled on your RPi Zero?

ejolson
Posts: 3682
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 6:46 pm

rpdom wrote:
Sun Apr 07, 2019 5:56 pm
ScriptBasic wrote:
Sun Apr 07, 2019 5:13 pm
Bottom line is BASIC is easier to learn than Python and for the most part beginners is our audience.
Have you got anything to back that up?

I teach kids to code. Some of them use Python. They pick it up fairly quickly. I suspect they would have more trouble picking up (yet another version of) BASIC.

The only thing that takes a little getting used to on Python (especially if you are used to other languages) is that crazy indentation thing.
This webpage appears to be a well thought out introduction-to-computing class for ages 12 to 13 years old. As part of the course description the teacher
Craig Whitmore wrote:We will begin with basic programming, using an application called Chipmunk Basic.... We will continue on to a more modern visual programming language, Scratch.
Therefore, some people think Basic makes a better introduction than even Scratch.

Some of my students ask if they can use Python when doing their projects. While I always say yes, most difficulties are related to algorithms, indexing, logic and getting the correct answer--not the programming language.

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 7:20 pm

Python may only be 9 MB to load but start including packages to get it to do anything useful and the truth unfolds.

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 7:29 pm

I teach kids to code. Some of them use Python. They pick it up fairly quickly. I suspect they would have more trouble picking up (yet another version of) BASIC.
ScriptBasic can run Dartmouth BASIC code untouched. (except for the DATA statement which I use SPLIT for) I've ported many QuickBasic programs as well. The COM extension module works with VB6. What other BASIC has that kind of syntax flexability?

User avatar
PeterO
Posts: 5067
Joined: Sun Jul 22, 2012 4:14 pm

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 7:32 pm

ScriptBasic wrote:
Sun Apr 07, 2019 7:20 pm
Python may only be 9 MB to load but start including packages to get it to do anything useful and the truth unfolds.
Indeed, there are lots of useful packages that you can use to help you do useful things in Python.... ;)

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 13608
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 7:46 pm

Perhaps we should not devolve into a language war here. That is a non-productive dead end.

All programming languages are terrible. Too slow, too big, too simple, too complex, terrible syntax and semantics, no standards, non-portable, etc, etc. (Delete item where appropriate for whatever language)

Let's focus on whatever good features a programming language may have to offer and where using them might be appropriate.
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 8:37 pm

Heater wrote:
Sun Apr 07, 2019 7:46 pm
Perhaps we should not devolve into a language war here. That is a non-productive dead end.

All programming languages are terrible. Too slow, too big, too simple, too complex, terrible syntax and semantics, no standards, non-portable, etc, etc. (Delete item where appropriate for whatever language)

Let's focus on whatever good features a programming language may have to offer and where using them might be appropriate.
Couldn't agree more.

All I ask is if you try ScriptBasic and didn't like it, please let me know why so I can fix it.

ejolson
Posts: 3682
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 9:05 pm

Heater wrote:
Sun Apr 07, 2019 7:46 pm
All programming languages are terrible. Too slow, too big, too simple, too complex, terrible syntax and semantics, no standards, non-portable, etc, etc. (Delete item where appropriate for whatever language)
I now have ScriptBasic running on a Raspberry Pi Zero W. Here is the result computing the 24th Fibonacci number from the program posted earlier:

Code: Select all

$ time scriba sb.bas
46368

real    0m2.072s
user    0m2.018s
sys 0m0.000s
$ cat sb.bas 
FUNCTION Fibonacci(n)
  IF n <= 2 THEN
    Fibonacci = 1
  ELSE
    Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2)
  END IF
END FUNCTION

PRINT Fibonacci(24),"\n"
If all programming languages are terrible, why avoid Basic?

ejolson
Posts: 3682
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 9:32 pm

ScriptBasic wrote:
Sun Apr 07, 2019 7:29 pm
The COM extension module works with VB6. What other BASIC has that kind of syntax flexability?
How do I run Visual Basic code?

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 9:38 pm

I now have ScriptBasic running on a Raspberry Pi Zero W. Here is the result computing the 24th Fibonacci number from the program posted earlier:
THANK YOU!

Can you send me your bin directory?

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 9:49 pm

ejolson wrote:
Sun Apr 07, 2019 9:32 pm
ScriptBasic wrote:
Sun Apr 07, 2019 7:29 pm
The COM extension module works with VB6. What other BASIC has that kind of syntax flexability?
How do I run Visual Basic code?
The ScriptBasic COM extension module is a CallByName OLE automation interface. The ScriptBasic IDE/Debugger is a VB6 app using the ScriptBasic embedded API and debugging pre-processor. I'm using the ext. module to interface with OCX forms I create in VB6 which calls back to ScriptBasic subs / functions. Check out the AllBasic.info forum for examples.

User avatar
scruss
Posts: 2546
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Why Avoid BASIC on RPi?

Sun Apr 07, 2019 11:26 pm

ejolson wrote:
Sun Apr 07, 2019 2:28 pm
Have you gotten ScriptBasic to run on your Pi yet?
No, the Fern post shows a time of 11.32 seconds.

I don't really have much interest in compiling ScriptBASIC. So much of its setup code is the kind of 1990s horrid Perl spaghetti code that Python programmers still go on about. It's not even using reasonable Perl idioms of the time. It might still work, but it's going to be virtually impossible to test.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Off topic discussion”