User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: BASIC - more harmful than useful?

Tue Dec 20, 2011 3:23 pm

Quote from tomo on December 20, 2011, 09:45
And, another thought... now an academic one... I remember they taught us that RISCs are generally more friendly to compilers than to hand programmers... meaning it's easier to write a good compiler for a RISC architecture than for a CISC, while, on the other hand, it's easier to hand code in assembler on a CISC, since it usually has more complex and "higher level" instructions ment to make life easier for humans. So, RISCs - generally speaking - aren't really the best platform to be hand programmed in assembler. That's the theory I've been taught. I believe these days microprocessors with their instructon sets are being designed and heading to be more friendly for compilers (i.e. easier to generate good code) and not assembler programmers, as it used to be in the past.

This is my understanding as well. The last CISC architecture is often considered to be the DEC VAX-11/780, with wonderful ASM programmer instructions like polynomial evaluation which requires many RISC instructions to perform. Unfortunately for DEC, it's hard to write a compiler to take advantage of all the wonderful VAX instructions and addressing modes, and brutally difficult to pipeline a machine when instructions vary from 1-60 bytes long.

Some RISCs are a pain to code in ASM. For example, some use delayed branch instructions where one or more unconditional instructions follow the branch to take advantage of pipelining. The compiler knows about them so can make use of the slots, but it makes it hard for humans to follow the code. Nowadays the pipelines have gotten so long that delayed branches are a lot less effective and branch prediction and speculative execution are needed for decent performance. Conditional execution like the ARM "cond" field and Thumb-2 IT instruction are a great way to improve pipelined performance for small conditional expressions.

ARM is an interesting case. While "R" at one time stood for RISC, the ARMv7 instruction set has evolved to be quite complex. For example, you have ARM versus Thumb modes, loads and stores with different offsets depending on whether the data is long, short, or signed versus unsigned byte, and integer divide which may or may not be available on your particular processor. Take a look at the quick reference guides when you're in the mood for a long explore. These issues affect both manual ASM and compilers.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: BASIC - more harmful than useful?

Tue Dec 20, 2011 6:28 pm

Quote from DavidS on December 18, 2011, 23:22
I have not said not to work in HLLs, They make good wen prototyping an app or for when cross CPU support is essential (very rare). Not to mention they are fun.
Oh, I missed this one. Very droll. You are Ben Elton, and I claim my 5 pounds.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 28358
Joined: Sat Jul 30, 2011 7:41 pm

Re: BASIC - more harmful than useful?

Tue Dec 20, 2011 6:39 pm

Quote from tufty on December 20, 2011, 18:28
Quote from DavidS on December 18, 2011, 23:22
I have not said not to work in HLLs, They make good wen prototyping an app or for when cross CPU support is essential (very rare). Not to mention they are fun.
Oh, I missed this one. Very droll. You are Ben Elton, and I claim my 5 pounds.

I missed it too. In effect, this statement means when using Linux on Raspi, you should definitely use a HLL, since the Raspi is Arm and most other Linux systems are x86, and of course, you'll want cross CPU support.

Case rested, well, actually, pretty much asleep.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: BASIC - more harmful than useful?

Tue Dec 20, 2011 8:20 pm

Quote from jamesh on December 20, 2011, 18:39
... since the Raspi is Arm and most other Linux systems are x86...

The problem with ARM and x86 being the current kings of the hills is that it limits opportunities for big-endian versus little-endian debates :-)

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: BASIC - more harmful than useful?

Tue Dec 20, 2011 10:00 pm

Quote from johnbeetem on December 20, 2011, 20:20
The problem with ARM and x86 being the current kings of the hills is that it limits opportunities for big-endian versus little-endian debates :-)

Not at all. ARM swings either way.

And anyway, it leaves more room for vi / emacs.

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 12:29 am

Quote from tufty on December 20, 2011, 22:00
Quote from johnbeetem on December 20, 2011, 20:20
The problem with ARM and x86 being the current kings of the hills is that it limits opportunities for big-endian versus little-endian debates :-)

Not at all. ARM swings either way.


ARM swings all over the place, and depends on implementation. While data access can be either-endian, instruction accesses in ARMv7-A and ARMv7-M are always little-endian, which makes documenting 32-bit Thumb instructions interesting. Many implementations don't provide access to the core configuration bit that sets byte order, leaving it fixed at little-endian. I've only heard of people using ARM as a little-endian machine in practice -- I'd be happy to hear big-endian reports.

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 12:37 am

Quote from tufty on December 20, 2011, 22:00
And anyway, it leaves more room for vi / emacs.

Including how to pronounce "vi". I pronounce it "vee'-uh" (i.e., "via"), after the title character of my favorite horror movie "Viy", a 1967 Russian film based on a story by Gogol. In the film, "Viy" is a hideous, soul-sucking demon.

obarthelemy
Posts: 1410
Joined: Tue Aug 09, 2011 10:53 pm

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 1:17 am

... which inadvertantly led me to that gory, not safe for work video:


I remember as a kid, my dad was bringing back those (French) booklets about factory safety every year. Lots of tits 'n ass to get everyone's attention. Of course, the Germans do it differently. A few years back my brother was working on a locker with an integrated video camera for automated counting of inventory. The camera was screwed to the door, so the otherwise empty locker kept falling if not screwed down. He forgot the T'nA in the operating instructions, and got quite a few accidents...

back on topic...

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 7:09 am

Quote from tufty on December 20, 2011, 05:26
Quote from DavidS on December 19, 2011, 04:20
In its compiled form BBC BASIC V produces better optimized code than current GCC distros (though not for the newer ARMs with there Harvard cache, as it predates this architechure).
Prove it. Easy enough to do.

Simon

I would love to. Two problems I do not have a working ARM/Risc OS machine at the moment, and I no longer have the ABC compiler for BBC BASIC V. If you can find a solution to both, I will gladly prove it (very easy).
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 7:11 am

Yeah no little vs big endians just RISC vs CISC :) .
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

tomo
Posts: 19
Joined: Mon Dec 12, 2011 12:50 pm

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 3:06 pm

Either way, there is still plenty of room left for something vs Ruby vs C vs BASIC vs something. And, of course, let's not forget the Assembler (doesn't matter which and when, really) vs the rest all together.

In the meanwhile, I'm just finishing my last web application, doing all the client-side ajax in assembler while my assembler server-side code is handling those requests. For the speed of light, I'm not using any operating system, either. It's fast as a strike of a lightning and I'm already making a fortune on it... nope, just kidding :-) I do need all that strange stuff like portability in any possible way. But otherwise, I know as hell I wouldn't do it anyway.

obarthelemy
Posts: 1410
Joined: Tue Aug 09, 2011 10:53 pm

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 3:13 pm

ASMJAX ? Bless you !

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BASIC - more harmful than useful?

Wed Dec 21, 2011 4:36 pm

Tomo:
Nice :) .
On the serious side:
The client side should always be HTML (with the HTML 5 spec there is no need for js), on the server side use what ever you want, so long as it runs on the server platform.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: BASIC - more harmful than useful?

Thu Dec 22, 2011 8:49 am

Quote from DavidS on December 21, 2011, 16:36
The client side should always be HTML (with the HTML 5 spec there is no need for js)
:o :o :o :o

Uuuuuuh - whatchoutalkinboutwiilis?

I'd suggest reading the HTML5 documentation (okay, I'll be generous - "reading through the HTML5 documentation again"), and trying to understand the difference between structuring of content (XHTML), rendering of content (CSS) and client-side manipulation of content (javascript or other browser based scripting languages).

I'd go further than the start of your statement, though (I'm a bit of an accessibility nazi) - I would suggest that the client side should, indeed, always be valid xhtml, and should always allow a scripting-free interface. This is actually pretty hard to do in a generic way, especially as "modern" web development toolkits seem to assume that you want to do everything through frickin' AJAX. Scripting layers added over the top should only enhance the experience, not actually be the experience (unless you're doing something like Robotron in javascript, in which case - hey - go for it).

Security-wise, the server side should not defer any validation to the client side - client side validation should only be used to smooth the user experience. And it should never trust *any* data it receives. Especially when there's an evil bastard like me testing it (fuzzing toolkit + ajax interface often == pwnage).

Simon

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BASIC - more harmful than useful?

Thu Dec 22, 2011 1:46 pm

Ok now, CSS+XHTML is good in 99.99% of cases. Scripting is way over used, most things that are scripted on sites should be handled on the server side. The text box that I am typing in is an excellent example, it is scripted, it should just use html to post to the server and the server side do the rest.
Perhaps add a reference for those that do not know the tags.
The fallowing are given with extra spaces:
[ s ] = Strikeout. [ / s ]
[ b ] = Bold. [ / b ]
[ u ] = Underline. [ / u ]
etc.....
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

hilltop
Posts: 25
Joined: Sat Dec 17, 2011 5:00 pm

Re: BASIC - more harmful than useful?

Thu Dec 22, 2011 8:23 pm

At the risk of being a little dull, and trying to drag things back on topic, I'd just like to say that I agree with the title of this thread.

Allow me to explain a little. I learnt BASIC, mostly from trial and error programming. (That is, it was the doing that taught, not the colourful paperback books from the local library or copying listings out of magazines.) And I'd prefer not to have learnt it in the first place. The only other language that uses line numbers which I am aware of is COBOL, and who advocates COBOL these days?

Which begs two questions, why? and what language instead? The why can be explained by this example:

...
1000 DEF FNfibonacci(n%)
1010 IF n% < 2 THEN
1020 =n%
1030 ELSE
1040 =FNfibonacci(n% - 1) + FNfibonacci(n% - 2)
1050 ENDIF
1060 =0

Most people with some understanding of programming reading this thread can probably follow that - it is almost Python. This program can be entered without error messages, and run without any. But it is broken. Not because the final '=0' is dead code, but because the ENDIF is, so what happens is that the stack gets chewed up silently and the memory leak persists until the program terminates (separately from the fact it's recursive and hence uses up stack while recursing).

So the 'correct' version could be:
1000 DEF FNfibonacci(n%)
1005 LOCAL r%
1010 IF n% < 2 THEN
1020 r%=n%
1030 ELSE
1040 r%=FNfibonacci(n% - 1) + FNfibonacci(n% - 2)
1050 ENDIF
1060 =r%

or, alternatively not creating a new variable:
1000 DEF FNfibonacci(n%)
1010 IF n%<2 THEN =n% ELSE =FNfibonacci(n%-1)+FNfibonacci(n%-2)

So it's either 'old style' IF's allononeline (=heiroglyphics) or introduce a dummy variable. Try to explain that to a beginner and I'm sure they would be put off. A language that allows elementary mistakes to be made without warning about them (or having any ability to check) is in my view best avoided.

So which language instead? Probably one of the early 90s ones: Python, Ruby or Lua. Lua would probably suit me best but it's probably just a personal preference thing that is difficult to quantify. In any case if somebody could have compiled me a working Lua binary to use instead of BASIC I have no doubt I would be a better programmer today for it. Just one thing I would say is that it is far better to be proficient in one language than mediocre in four or five. Lua is great in that it can fit inside a normal-intelligence person's head.

The area I wanted to mention is interfacing with the host OS. Bash (which despite the similar name is about as far the opposite end of the programming spectrum as BASIC as you can get, and is NOT a beginners tool - I'm barely competent in it after several years of exposure) gives you the C library functions as easily as you can get. LuaJIT (http://luajit.org) has a rather spiffy FFI (foreign function interface) library which amounts to the same, and more. (Python and Ruby of course have bindings to just about every part of modern Linux, but it's learning and then trusting someone else's code.)

BASIC V under RISC OS has the SYS command. This is not active in the Brandy interpreter when compiled for Linux, but I wonder if someone would be interested in adapting it to become a C FFI, eg.

SYS "printf","Hello, %s %d!","world", 2.0

If that were implemented, plus the stack frame gotchas sorted out, then perhaps it could be useful to some. But really, with Lua et. al. being nearly 20 years old, it's time to forget about the 70s and 80s wrt programming methodologies.

I wish I'd had Scratch.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BASIC - more harmful than useful?

Thu Dec 22, 2011 9:39 pm

Ok, I would also note that a C interpreter is prone to the same errors.

So we need to add some form of stack checking to the Risc OS port of Brandy BASIC and then add both stack checking and some form of system call structure using SYS to the Linux version.

As a quick question:
Does the Linux version of Brandy support assembly for its ARM port???

If not then we also need to enable the assembler on the Linux version.

As your above example shows BBC BASIC is very good at teaching structured programming concepts. Though why does your example show the line numbers? If you open a BBC BASIC file with a most text editors on Risc OS they hide the line numbers, making it an even better tool for teaching structured programming.

EDIT: Typo
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: BASIC - more harmful than useful?

Thu Dec 22, 2011 10:12 pm

I've never had problems with recursive programming in Basic. That's because I've never used a version of Basic that supported recursion :-)

IMO, if you're ready to understand recursion, you're ready to program in a much better language.

pvgb
Posts: 51
Joined: Sat Oct 15, 2011 9:53 pm

Re: BASIC - more harmful than useful?

Thu Dec 22, 2011 10:59 pm

In the beginning was binary. Toggle switches on the front panel. The Manchester "Baby" (http://www.computer50.org/mark......baby.html) used Spitfire radio switches ( Go and see the reconstruction in the Manchester Science Museum if you are ever near there.)

Then somebody invented assembler. Symbols ! Mnemonics ! Easier (!) Quicker ! (To write and debug )

Scientists wanted to write their own programs - Fortran ( Formula Translation ) appears on the scene. Arithmetic expressions in what a mathematician would recognise, control flow mostly in terms of absolute jumps - fixed in Fortran77 as I remember.

Kemeny & Kurtz develop Basic as an easier way to teach people to program.

Cobol - designed so that accountants could read it ? ( Originally for the US Navy stock control system - or so I've been told )

Procession of invention of whole bunch of new languages - at one stage in the 1980s it was reported that the contractors for the DoD were using ~350 different languages. Sometimes I wonder how many languages are in use now, along with incompatible ( and sometimes incomprehensible ! ) libraries, competing frameworks, platform variations and programming styles/idioms. And that is just imperative languages !

Puts the tower of Babel into context.

Programming is actually two problems - the actual problem that you are trying to solve and the problem of turning that solution into working code. Everybody seems to get hung up on the second part, and cites it as the difficult bit.
Perhaps it is because of cognitive overload in trying to solve both parts of the problem in one go ?

I started using Basic - we didn't have access to a CDC6000 to do Pascal. Then I did Algol, Fortran IV and then Pascal.

I do not consider myself to have been harmed by the process. ( I am prepared to concede that I may be so damaged that I cannot recognise the damage )

Would I demand Basic as a first language ? No!
Would I forbid Basic as a first language ? No!

I am however more comfortable with the idea of Python as a first language for people starting out today, especially interactively. ( Just keep away from the more ...convoluted... libraries and interface builders until you have got the hang of things )

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BASIC - more harmful than useful?

Fri Dec 23, 2011 2:00 am

Quote from johnbeetem on December 22, 2011, 22:12
I've never had problems with recursive programming in Basic. That's because I've never used a version of Basic that supported recursion :-)

IMO, if you're ready to understand recursion, you're ready to program in a much better language.


Better this, better that. A programming language is a Programming language.

Many are misled about BASIC due to the forms that did not support named procedures, the slow interpreters of some variants, and the ByteCode compilers of some versions. There are many tools out there, BASIC is an advance language, even though it can be understood by beginners.

FreeBASIC, BBC BASIC, and Brandy BASIC all support Pointers, named procedures, native code compilation, and modular programming. As such modern BASIC should replace the B, maybe UASIC (Universal All Purpose Symbolic Instruction Code), or some such.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: BASIC - more harmful than useful?

Fri Dec 23, 2011 9:07 am

Quote from DavidS on December 23, 2011, 02:00
A programming language is a Programming language.
...but some are better than others at certain tasks. Some are totally useless except as an intellectual exercise (befunge, for example) and some are pointless given the existence of languages which do a better job.

A 2 man pit saw will still slice treetrunks into planks, but an automated machine will make a faster and more accurate job of it.
Quote from DavidS on December 23, 2011, 02:00
FreeBASIC, BBC BASIC, and Brandy BASIC all support Pointers, named procedures, native code compilation, and modular programming.
Well whoop-de-do! Be still my beating heart, the 1970s are still calling.

Direct programmer access to pointers through "high level" languages is a major cause of software security failures.

Named procedures is hardly new (after all, lisp has been doing it since the 1960s), and, although easier on programmers than using line numbers, it's fundamentally equivalent.

Native code compilation, if I understood your earlier post, requires an archaic machine (or emulator thereof), unobtanium software, and still only compiles code for a subset of ARM processors which haven't been in production for at least 10 years. Not to mention that it can't compile all BASIC code. Colour me impressed.

By "modular programming", I assume you mean the ability to split your program into multiple blocks of code on a filesystem, and then reuse those blocks between multiple programs? It might be "new" to BASIC as implemented on home micros in the '80s, which were restricted to tape storage, but pretty much anything that used disk storage has been doing this since - umm - forever.

Give it up, man. It's an awful language.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 28358
Joined: Sat Jul 30, 2011 7:41 pm

Re: BASIC - more harmful than useful?

Fri Dec 23, 2011 2:03 pm

Quote from hilltop on December 22, 2011, 20:23
...
1000 DEF FNfibonacci(n%)
1010 IF n% < 2 THEN
1020 =n%
1030 ELSE
1040 =FNfibonacci(n% - 1) + FNfibonacci(n% - 2)
1050 ENDIF
1060 =0


Can you explain why this chews up the stack please - I don't see why, but then its 25 years since I last did any BASIC.

The only things that comes to mind is that the ENDIF is never executed. Do IF/ENDIF's use up stack space? Are you saying that the compiler/interpreter is too dumb to clean up it's stack on function exit?

James
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

hilltop
Posts: 25
Joined: Sat Dec 17, 2011 5:00 pm

Re: BASIC - more harmful than useful?

Fri Dec 23, 2011 4:45 pm

Quote from jamesh on December 23, 2011, 14:03

Can you explain why this chews up the stack please - I don't see why, but then its 25 years since I last did any BASIC.

The only things that comes to mind is that the ENDIF is never executed. Do IF/ENDIF's use up stack space? Are you saying that the compiler/interpreter is too dumb to clean up it's stack on function exit?


In a word, to answer your last question, Yes, the BASIC V interpreter on RISC OS is too dumb. Other BASIC's may vary. (I have a feeling that ABC, mentioned elsewhere in this thread, will refuse to compile such code, but have no experience with it.)

Basically you shouldn't have function return (or ENDPROC, or GOSUB's RETURN, or even GOTO) branching out of/returning from within control statements IF/ENDIF, FOR/NEXT, CASE/ENDCASE, WHILE/ENDWHILE (and possibly others I've forgotten). You won't get an error, just a silent, invisible memory leak.

hippy
Posts: 9239
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: BASIC - more harmful than useful?

Fri Dec 23, 2011 4:56 pm

Quote from jamesh on December 23, 2011, 14:03
Can you explain why this chews up the stack please - I don't see why, but then its 25 years since I last did any BASIC.

This seems more a compiler / interpreter implementation error to get a memory leak or the stack screwed rather than a systemic Basic language problem.

Whether '=<expr>' is an immediate return and renders subsequent code as "dead code" or not depends on specific implementation definition ( I've implemented both ). Either way; if it's dropping out of a function without reclaiming the stack that's either intended by definition ( unlikely, but then it becomes programmer error ) or an oversight of the compiler writer to realise the consequences in doing that ( compiler design error ).

jraff1
Posts: 11
Joined: Wed Dec 21, 2011 11:58 pm

Re: BASIC - more harmful than useful?

Fri Dec 23, 2011 5:37 pm

After I built and got my CP/M system running (late '70's) I found a Telecommunications programming book (BASIC) and told my son that he HAD to learn it. Mother looked at me as though I had 3 heads but kept quiet. Over the next while he complained about doing this and that, and I just told him to persevere. He did and then the penny dropped and I could NOT get him off the machine. He had a job with Tandy Radio Shack and played daily with programming, DDial, BulletinBoards, etc. He and anoter kid even got into business with some telephone software, then he moved out of the area and we see him infrequently. My daughter did not want any part of the BASIC and flatly refused to learn.
She finally got her degree now works for IBM as a system analyst.

Return to “Staffroom, classroom and projects”