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

Re: Making readable modifyable code.

Mon Nov 28, 2016 4:57 pm

Being in Education myself and having family and relatives as primary teachers.
None use basic, not even a BBC B emulator or speccy or whatever.
It's scratch, python at a push and many other symbolic click and drag setups (mindstorms etc).
It's not actually about the language though, but the process, just as it was back in BBC Basic /Logo land.

This is the first year the 'learn to code' has come through to senior school with the new wave of year 7 (11yr Olds).
I know at the local large one near me they're having to alter their courses as they know too much now.
Oddly I don't actually know for our school, I think we had already altered it.
The maths is not usually a problem for 7yr olds, they're still learning it but know how it works.

Though what it's got to do with the original topic...

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

Re: Making readable modifyable code.

Mon Nov 28, 2016 5:32 pm

Heater wrote:Hmm... Not where I come from. When you are creating software where it matters if it works or not, like avionics controls, or military or satellites, it's a different world:
A good while back, I used to work for the IT department of the maintenance section of "an airline". I won't say who, but let's just say they had some supersonic passenger jets, and they were neither French nor Russian.

Now, the engineers did a seven year apprenticeship before being allowed to put the slightest spanner on an actual in-service airframe, but the software engineers had no such requirement. And yet the software engineers were responsible for the software that told the engineers what to do.

When I arrived, the software that scheduled jobs for major maintenance not only didn't have a test suite, but wasn't in any form of version control. There were multiple divergent copies of the source floating around, none of them could be identified as the "most recent", and the binary code running live, scheduling major maintenance work on several fleets of aircraft ("ours" and those of a number of third parties who contracted their maintenance out), could not be tied to any known collection of source code. The very concept of version control was considered alien, overkill.

And that wasn't even the worst thing I found there.

I could tell stories that would make your toes curl, and probably make you swear off flying.

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

Re: Making readable modifyable code.

Mon Nov 28, 2016 10:33 pm

Heater wrote:I have been wondering about that too:

Are you saying that after over 3 decades of software development the best they can find is to teach kids programming is a rude and crude BASIC from the 1980's?

I'm impressed that it works for 7 year olds. From what I can recall when we were 7 we could hardly do arithmetic.

What are these RCs of which you speak?
There are good mathematics and science books with BASIC code examples from the 80's and early 90’s. The next generation of books replaced the code with instructions on how to use a graphing calculator. A couple decades of textbooks with code examples integrated into other subjects may be difficult to replace and what makes a BASIC virtual machine useful.

Most of these books could easily be updated for Python, but copyrights become an issue and publishers may not want an updated book from the 80's to compete with a current money-making standard. It would be interesting how many of the BASIC code examples in the old books and magazines could be updated to use Scratch. If students do become computer literate, maybe a new generation of books on topics other than computer programming could contain Scratch and Python code examples.

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

Re: Making readable modifyable code.

Tue Nov 29, 2016 6:39 am

That would be more useful when Scratch/Python are properly implemented on Tablet/Smartphone with iOS/Android. It would then be usable in the classroom, rather than heading off to a computer room just to do some sums.
I agree at a higher A-Level or enhanced GCSE, then computer in mathematics and Science (and probably other subjects) should be used a lot more as it would represent what actually happens and equips them for it.
But it cost money and it would need to come from the examing boards.
Otherwise we'll still be left with people who have no idea how to use computer in the real world other than taking pictures and YouTube. Though a few may remember how they programmed one 6yrs prior.

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 11:41 am

An example of readable and modifiable code is a program called GROW written in CHAOS BASIC by Jeff Levinsky around 1979. This version of BASIC is based on the original Micro-Soft MITS BASIC created by Bill Gates and Paul Allen. CHAOS stands for the Clairmont High School Advanced Operating System which ran on an 8-bit Altair 8080 modified using a custom bank-switched memory controller to allow time sharing. This hardware and operating system was developed by educators teaching computer literacy at the high-school level in the 1980's and is notable for having a dynamic directory structure which made each user's home directory appear as their root directory. Putting the home directory as root allows file permissions to be inherited in a natural way that isn't possible for the static directory structures used in modern operating systems like Raspbian. However, that isn't the point of this post.

The GROW program itself seems to be the earliest example of a multi-player user-extensible adventure game intended for teaching purposes. A similar but more sophisticated system called lambdaMOO was developed nearly ten years later at Xerox Parc. Note that MUD1 from Essex University was multi-player but not user extensible nor intended for teaching purposes. Although both GROW and the CHAOS time-sharing system are long forgotten, the motivating need to teach computer literacy is as relevant today as it was back then.

A detailed commentary on the source code for GROW appears in Creative Computing, January 1980, pages 90-97. As the published listing was apparently made using a worn-out ribbon with a damaged typewheel, I have rekeyed the program with slight modifications so it runs under bwBASIC on a Raspberry Pi.

Code: Select all

10 rem                 ***  Extensible Adventure  ***
20 rem                 *    Copyright  (C)  1979    *
30 rem                 *      By Jeff Levinsky      *
40 rem                 *    All Rights Reserved     *
50 rem                 * Written in Chaos II BASIC  *
55 rem
56 rem      Ported to bwBASIC Nov 2016 by Eric Olson
60 rem
1000 rem                                   Main Loop
1010 gosub 2000
1020 gosub 3000
1030 gosub 4000
1040 goto 1020
2000 rem                                  Initialize
2010 rem clear 300,2
2020 p=0
2030 n$="init"
2040 i$=" intro "
2060 gosub 4000
2070 goto 1020
3000 rem                                  Input Line
3010 line input "? ";i$
3020 i$=" "+i$+" "
3030 goto 1030
4000 rem                                Process Line
4010 open "I",1,n$
4020 gosub 5000
4040 if f=1 then 4110
4045 close
4050 open "I",1,"default"
4060 gosub 5000
4080 if f=1 then 4110
4090 gosub 5800
4100 goto 4120
4110 gosub 5400
4120 close
4130 return
5000 rem                                   Find Line
5010 f=0
5020 gosub 6000
5030 if eof(1) then return
5040 gosub 6200
5050 if s$="" then 5020
5060 s$=" "+s$+" "
5070 if instr(i$,s$)=0 then 5040
5080 f=1
5090 return
5400 rem                                  Do Actions
5410 gosub 6000
5420 gosub 6200
5430 if s$="" then return
5440 t$=left$(s$,1)
5450 if t$="P" then print mid$(s$,2):goto 5420
5460 if t$="Q" then print "Quit with ";p;" points":quit
5470 if t$="+" then gosub 6400:p=p+n:goto 5420
5480 if t$="-" then gosub 6400:p=p-n:goto 5420
5490 if t$="G" then gosub 7000:return
5500 if t$="X" then gosub 8000:return
5510 goto 5420
5800 rem                             Random Response
5810 r=int(rnd(0)*3)
5820 if r<1 then print "Huh?"
5821 if r=1 then print "What"
5822 if r>1 then print "I don't understand"
5830 return
6000 rem                                  Skip Block
6010 if eof(1) then s$="":return
6020 line input #1,s$
6030 if s$<>"" then 6010
6040 return
6200 rem                                    Get Line
6210 if eof(1) then s$="" else line input #1,s$
6220 return
6400 rem                                     Convert
6410 n=0
6420 l=2
6430 if l>len(s$) then return
6440 n=n*10+asc(mid$(s$,l,1))-asc("0")
6450 l=l+1
6460 goto 6430
6600 rem                              Input New Data
6610 line input ": ";i$
6620 print #1,i$
6630 if i$<>"" then 6610
6640 return
6800 rem                                   Copy Mode
6810 open "I",2,n$
6820 open "O",1,"temp"
6830 if eof(2) then return
6840 line input #2,i$
6850 print #1,i$
6860 goto 6830
7000 rem                               Goto New Mode
7010 if len(s$)<2 or len(s$)>9 then return
7020 close
7030 n$=mid$(s$,2)
7040 on error gosub 7100
7050 open "I",1,n$
7060 gosub 6200
7070 if s$="" then 7150
7080 print s$
7090 goto 7060
7100 on error gosub 0
7110 close
7120 open "O",1,n$
7130 print "Describe ";n$
7140 gosub 6600
7150 close
7155 open "I",1,n$
7160 return
8000 rem                                 Extend Mode
8010 close
8020 gosub 6800
8030 print "Key words/phrases"
8040 gosub 6600
8050 print "Actions"
8060 gosub 6600
8068 close
8069 kill n$
8070 name "temp" as n$
8080 return
I have also created an archive consisting of the executable script and example data files needed to run the program. Much thanks goes to the author Verda Spell of bwBASIC and to her grandson Ted Campbell for making it widely available on the Internet. If anyone is still interested in a readable and modifiable code challenge, my challenge would be to take the above GROW program and rewrite it using best practices in modern software engineering.
Last edited by ejolson on Thu Dec 01, 2016 11:58 am, edited 1 time in total.

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 11:58 am

ejolson wrote:.

Code: Select all

10 rem                 ***  Extensible Adventure  ***
20 rem                 *    Copyright  (C)  1979    *
30 rem                 *      By Jeff Levinsky      *
40 rem                 *    All Rights Reserved     *
50 rem                 * Written in Chaos II BASIC  *
55 rem
56 rem      Ported to bwBASIC Nov 2016 by Eric Olson
60 rem
1000 rem                                   Main Loop
1010 gosub 2000
1020 gosub 3000
1030 gosub 4000
1040 goto 1020
It fails to be readable on line 1010 onwards..... What is 2000 ? 3000 ? 4000 ?

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

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 12:21 pm

I give it top marks for keeping the lines short and lining the comments up on the right hand side. :)

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 12:42 pm

Heater wrote:I give it top marks for keeping the lines short and lining the comments up on the right hand side. :)
Ouch !
PeterO :D
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 2:15 pm

Heater wrote:I give it top marks for keeping the lines short and lining the comments up on the right hand side. :)
Agreed.
PeterO wrote:
ejolson wrote:.

Code: Select all

10 rem                 ***  Extensible Adventure  ***
20 rem                 *    Copyright  (C)  1979    *
30 rem                 *      By Jeff Levinsky      *
40 rem                 *    All Rights Reserved     *
50 rem                 * Written in Chaos II BASIC  *
55 rem
56 rem      Ported to bwBASIC Nov 2016 by Eric Olson
60 rem
1000 rem                                   Main Loop
1010 gosub 2000
1020 gosub 3000
1030 gosub 4000
1040 goto 1020
It fails to be readable on line 1010 onwards..... What is 2000 ? 3000 ? 4000 ?

PeterO
This shows a difference in how we look at code. I think that is very readable, while a couple more comments about the subroutines would be helpful.
Save power, use fewer cycles total. Assembly Language forever :) .

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 2:39 pm

Code: Select all

1010 gosub 2000
1020 gosub 3000
1030 gosub 4000
It's certainly very readable.

Problem is it's totally meaningless. Each line only says that you are on some line, you are going to go to some unknown line to do some unknown thing and when that thing is done you will continue at the next line and do some more unknown stuff.

Great!

All well and good while you only have a few subroutines in your program and you remember what their line numbers are. Until you renumber all the lines at some point!

I don't know about you but I think that is hard work and my brain would give out after a handful of subroutines.

Arguably it's worse that working in assembler where at least one can name everything. Given that BASIC = "Beginner's All-purpose Symbolic Instruction Code" they certainly failed on the symbolic part. One wonders how earth they ever thought this was a good idea. Except of course BASIC was developed on a very limited machine and they wanted it to be fast and interactive so actually naming things was perhaps too much.

jahboater
Posts: 3054
Joined: Wed Feb 04, 2015 6:38 pm

Re: Making readable modifyable code.

Thu Dec 01, 2016 2:53 pm

I always thought it was "Beginner's All-purpose Simple Instruction Code" but I just looked it up and I think you are right, it is incorrectly named "Symbolic". I have heard it called "Baby's All-purpose Simple Instruction Code" too :?

A long time ago I went for a job where prior to the interview there was a programming test. You could choose any language you liked. Most applicants chose BASIC, but not a single one completed the task, none even came close. It was actually quite simple in Algol 68!

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 2:53 pm

And another thing...

How come we have:

Code: Select all

1010 gosub 2000
And then the subroutine at 2000 has no return but ends with a

Code: Select all

2070 goto 1020
Similarly for the subroutine at 3000.

??

jahboater
Posts: 3054
Joined: Wed Feb 04, 2015 6:38 pm

Re: Making readable modifyable code.

Thu Dec 01, 2016 3:12 pm

Tail call optimization?

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 5:41 pm

I think that's spelled "eventual call stack overflow"

jahboater
Posts: 3054
Joined: Wed Feb 04, 2015 6:38 pm

Re: Making readable modifyable code.

Thu Dec 01, 2016 5:42 pm

tufty wrote:I think that's spelled "eventual call stack overflow"
:lol:

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 5:45 pm

Heater wrote: It's certainly very readable.
Problem is it's totally meaningless.
"You are technically correct, the very very best kind of correct" (Bureaucrat No.1 in Futurama episode "How Hermes Requisitioned His Groove Back")
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
[email protected]
Posts: 1984
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Making readable modifyable code.

Thu Dec 01, 2016 6:04 pm

Ahh BASIC :-)

FWIW, I recently "ported" a classic old game, "Hunt the Wumpus" into RTB. I was pleasantly surprised at how relatively well it was written, although in a classic style with goto/gosub - "structuring" it wasn't that hard.

It's too big to post here, but if you want to look at mine (the original one is preserved in comments), then it's at: http://unicorn.drogon.net/wumpus.rtb

There is a short video of it running with TTY33 speed (and the closest sound I could find after a brief search) https://www.youtube.com/watch?v=x-5lfTqdZUY (sorry - hand-held phone video at screen)

Kids of today... wouldn't believe a word of it!

-Gordon
--
Gordons projects: https://projects.drogon.net/

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 6:32 pm

DavidS wrote:This shows a difference in how we look at code. I think that is very readable, while a couple more comments about the subroutines would be helpful.
There is a detailed commentary in the magazine write up which is available in the references subdirectory. That commentary could have been included in the source but likely wasn't due to memory constraints. I entered the program as it was originally written except for using lower case and fixing one error in the keyword parser at line 5070 to handle synonyms correctly. I also changed the exception handler used to create new files, as bwBASIC didn't implement the resume statement.

The stack leak is an interesting find. Surely such things would be avoided using today's best practices in software engineering. If anyone is interested in rewriting the program as an entry for the proposed readable and modifiable code challenge, I would personally like to see a clean version written in a functional programming language.

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 7:40 pm

Heater wrote:One wonders how earth they ever thought this was a good idea.
Line numbers in BASIC are similar to the sequence numbers appearing in columns 73 through 80 on an IBM punched card. The difference is that the cards need to be fed through a mechanical sorter if they get out of order, while line numbers are sorted automatically by the BASIC interpreter. Thus, one does not have to put a BASIC program through the sorter when the cards get out of order. This also guards against operator error in the machine room when cards are accidentally switched. I've updated the code on the website to fix the stack leak.

User avatar
rpdom
Posts: 12884
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Making readable modifyable code.

Thu Dec 01, 2016 8:15 pm

ejolson wrote:
Heater wrote:One wonders how earth they ever thought this was a good idea.
Line numbers in BASIC are similar to the sequence numbers appearing in columns 73 through 80 on an IBM punched card.
Interesting. I've never used IBM punched cards, but I have used them (and code that needed to be in that particular format). On the ones I used, the line numbers were columns 1 to 6, and 73 to 80 were reserved for comments/version numbers/patch revisions etc.

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 8:22 pm

ejolson,

Wait a minute. The whole idea of BASIC was to get away from stacks of punch cards and batch jobs. The idea was to create an interactive system. Type code into your teletype, or even green screen later on, and run it immediately.

To that end, BASIC was brilliant. You could type LIST, I think it was, and your whole program would be printed out. Then when you want to edit a line you just type the line number followed by the new code you want. Then it RUN to see if it works any better.

BASIC was an IDE. Editor and run time all in one.

Or at least that is how it was in 1974 for me.

On the other hand. We had to prepare a stack of Hollerith cards for our ALGOL programs. Put them in a pigeon hole in the computer center and hope the output of a successful run was delivered by the operator gods the next day.

Those cards had no sequence numbers. You just had to take care not to shuffle them!

Or at least that is how it was for me in 1976.

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 8:24 pm

rpdom,
I've never used IBM punched cards, but I have used them...
Would you like to clarify that?

:)

User avatar
rpdom
Posts: 12884
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Making readable modifyable code.

Thu Dec 01, 2016 8:35 pm

Heater wrote:rpdom,
I've never used IBM punched cards, but I have used them...
Would you like to clarify that?
I think you know what I mean. I have used punched cards, but not on an IBM system.

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

Re: Making readable modifyable code.

Thu Dec 01, 2016 8:59 pm

Ah, right.

Strangely enough I have used such punch cards in various places. Never on an actual IBM machine.

That is why I like to call them Hollerith Cards. After the inventor. Pre IBM days.

Mind you, punch cards were used to program pattern generation into textile machines since Jacquard in 1801 and going back to others in seventeen hundred and twenty whatever.

jahboater
Posts: 3054
Joined: Wed Feb 04, 2015 6:38 pm

Re: Making readable modifyable code.

Thu Dec 01, 2016 9:30 pm

Heater wrote:Strangely enough I have used such punch cards in various places. Never on an actual IBM machine.
Ditto, but I did use an IBM 029 card punch, don't know if that counts.
Heater wrote:That is why I like to call them Hollerith Cards. After the inventor. Pre IBM days.
I remember hollerith constants in Fortran!

Return to “General programming discussion”