Page 60 of 93

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 7:29 am
by Heater
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 7:43 am
by John_Spikowski
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

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 8:57 am
by John_Spikowski
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 9:20 am
by Gavinmc42
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

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 10:44 am
by Paeryn
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!

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 1:09 pm
by bensimmo
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 1:31 pm
by scruss
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 2:28 pm
by ejolson
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?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 5:13 pm
by John_Spikowski
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 5:41 pm
by John_Spikowski
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 5:56 pm
by rpdom
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 5:56 pm
by ejolson
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?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 6:10 pm
by John_Spikowski
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 6:23 pm
by John_Spikowski
@ejolson,

Any luck getting ScriptBasic compiled on your RPi Zero?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 6:46 pm
by ejolson
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 7:20 pm
by John_Spikowski
Python may only be 9 MB to load but start including packages to get it to do anything useful and the truth unfolds.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 7:29 pm
by John_Spikowski
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?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 7:32 pm
by PeterO
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

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 7:46 pm
by Heater
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 8:37 pm
by John_Spikowski
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 9:05 pm
by ejolson
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?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 9:32 pm
by ejolson
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?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 9:38 pm
by John_Spikowski
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?

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 9:49 pm
by John_Spikowski
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.

Re: Why Avoid BASIC on RPi?

Posted: Sun Apr 07, 2019 11:26 pm
by scruss
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.