Mind-blowing BASIC example from the 1970's:
100 A$="ABCDEF"
110 A$ = REP ("123", 4, 0)
120 PRINT A$
The result is ABC123DEF -- at position 4 (strings start at 1), replace 0 characters with "123". So the REP function looks at the statement it's part of, finds the variable that is being assigned to, and uses that as the starting string (!). It's kind of like a function, only with a weird implied variable that only works in an assignment.You can't just PRINT the result directly, because then how would REP know what the string to change is?
Nowadays "weird" syntax has some solid foundational reason why it's useful or important. This not-really-a-function, though, simply has no justification whatsoever.
(This example is from the BASIC embedded in the Tektronix 4050 terminal).
There are enough variants of BASIC that there's a really nifty handbook with the differences at https://archive.org/details/Basic_Handbook_2nd_Edition_1981_...
The (actually second) BASIC interpreter on the Amiga was made by Microsoft. It was great and horrible at the same time. Great because it had while-loops, labels instead of line numbers, and basic (no pun intended) support for the Amiga GUI, i.e you could open windows and create menus. Horrible because it was super slow and, for some reasons unknown to me, Microsoft had decided to not implement stack frames for subroutines. So, all local variables in subroutines were static and recursions were not allowed.
The weird thing: You still had to write the "STATIC" keyword although all subroutines were static anyway! (I assume the STATIC keyword was optional in the other Microsoft BASIC version and non-static subroutines were supported there)
As DonHopkins notes, this appears substantially identical to the assign-equals operators which are generally thought of as "easy and convenient" rather than "weird". How is the line of code "a *= 7" meaning
"whatever the current value of a is, multiply that by 7 and assign the result to a"
weirder than the line 'a$ = REP("123",4,0)' meaning
"whatever the current value of a$ is, do a string replacement on it and assign the result to a$"?
Yes, it actually did exactly what it sounds like!
Chalk one up for DEC and BASIC. What other programming languages support that feature, huh?
DECSYSTEM 20 BASIC User's Guide: LISTREVERSE command
LISTREVERSE
LISTNHREVERSE
LISTREVERSE and LISTNHREVERSE print the contents of the
user's memory area in order of descending line numbers.
LISTREVERSE precedes the output with a heading,
LISTNHREVERSE eliminates the heading.
LISTREVERSE
EQUIV 10:53 13-NOV-75
40 END
35 PRINT "THE EQUIVALENT CURRENT IS",I, " AMPERES"
25 I=E1/R
10 INPUT R
5 INPUT E1
READY
http://www.bitsavers.org/www.computer.museum.uq.edu.au/pdf/D...Same might go for a terminal with no scrollback...
Come to think of it, this sounds actually rather useful. Had this been available when I was programming on the BBC Micro, I bet I'd have used it.
A$.REP("123", 4, 0)
So the syntax is weird, but the concept isn't totally unusual.Edit: Interesting...the Duinomite folks even noted the "Why Johnny Can't Code" post: https://www.olimex.com/Products/Duino/Duinomite/_resources/E...
I've also been enamoured by PICO-8, a programmable virtual game console - its retro aesthetics and ALL CAPS syntax remind me of BASIC. https://www.lexaloffle.com/pico-8.php
It's late but I'm confused why anyone would spend time doing this, and since it is in the official Google repository, presumably someone at Google was actually doing it on paid time.
https://flagxor.com/article/source-code
I might be coming around to the why of this.
Unlikely. Google (like many companies) assert ownership of everything their employees create, even on their free time. There are plenty of projects under Google organization that have no other affiliation with Google.
Plain, good, old fun?
This isn't that, but withering comments from Dijkstra aside, BASIC is still a great introduction to programming, and this is a fantastic idea; it'll be great to run loads of old type-ins in the browser.
Could have done with a crisper font, though.
I love the idea of a language that has the absolute fewest number of decisions between "I need a little program" and being able to share the program with a friend. The current trend where there's a seemingly bazillion steps before you can write a trivial utility is unfortunate.
However, the microcomputer BASICs had big usability problems. Us modern programmers are so used to block oriented languages that we assume every language just had them. For example, in C you can replace any statement with a list of statements enclosed in { }. In Python where blocks are indented statements, or Pascal where you can make a block of statements with a BEGIN/END.
But many microcomputer BASICs don't have that at all. The IFs often don't have the concept of an ELSE, and often the only thing you can do from an IF is a GOTO.
The end result is a mess of jumps where the programmer is "emulating" real blocks with GOTOs. I've had the recent fun of transcribing programs from a bunch of different early BASIC languages. The complaint that BASIC leads to spaghetti code is real. There are bazillions of GOTOs, and it's a real drain on your mental processing to keep them all straight.
Something like Turbo Basic or QBasic, with a REPL as well would do quite nicely.
On the other hand maybe what is missing is making those little boards with JavaScript or Python more widespread.
I grew up on basic on TRS-80/Apple II/Atari 800 and I have super fond memories of those times. You can even find lots of my BASIC code in old magazines from the 80s. But, I don't really believe those were better than today with kids with Scratch or Unity or other alternatives. Python or JavaScript (runs everywhere) etc... Maybe even PICO-8/Lua etc...
Are there some concrete reason BASIC is actually a good place to start?
It is easy to learn because it was the first language to come with batteries.
In some 8 bit micros it was as powerful as the underlying Assembly, only slower. So it was relatively easy to prototype.
Also the the runtime was the OS.
Nowadays a kid needs to learn how to access the development environment, probably configured by an adult and to do more complicated tasks might need some help getting libraries.
Maybe stuff like boards with MicroPython will help here.
BASIC was how I started programming, 30 years ago.
Is this the first time someone's implemented BASIC in JavaScript? It seems so... obvious in hindsight.
I wonder if this has any potential for kids who want to start to learn programming? Or if there are other better, more modern, places to start these days?
Also... why is this from Google of all places? Seems like more of a personal hobby project.
After this experience I can easily see how someone could still be writing BASIC for a living in 2018, whether for standalone desktop apps or for web CGI, etc.
Business BASIC was ported to mainstream PCs and other micros as the market for dedicated Business BASIC minicomputer systems waned. It still lives on today in the form of two dialects: ProvideX and BBj. And people are still writing/maintaining applications in it.
https://www.hanselman.com/blog/NETAndWebAssemblyIsThisTheFut...
https://blogs.msdn.microsoft.com/webdev/2018/02/06/blazor-ex...
"gwwwbasic" anyone??
I started on BASIC on the TRS-80 Model I in 1980, and it was a great introduction.
That said, newbies are probably better off starting Python (use IDLE for a decent REPL & editor), type `from turtle import *; reset()` to get a graphics window, and learning a nice language from the start.
Outside highly narrow application/context-specific situations, that is.
Is there at least GOTO?
Just as serious. Programming does not always require a solid reason before you can engage in it, quite a bit of it is like playing. If you actually enjoy programming then it is much nicer to do than if everything needs a financial justification.
There is a similar analogy with music, you could make money with it, but you can also simply enjoy it.
BASIC was for many people their introduction to programming, and it has a simplicity which is nearly unmatched today.
By providing a way to run the language inside the ubiquitous web browse, one may hope to spread the usage of BASIC as a learning tool, especially for youngsters.
> It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.
Each of those could be used to write very complete applications including GUIs and such.