Sunday, September 16, 2018

Python - The Emperor's New Clothes

I recently posted a couple of examples of a starfield simulation written in BASIC.  One of these was written in Commodore BASIC for the VIC-20.  The other was written in Liberty BASIC for Windows.

BASIC gets a lot of flack from people with a certain kind of snob factor (yes, you know who you are).  And there is the infamous comment by Edsger Dijkstra, and BASIC has never lived it down.  Nowadays when you see people discussing what is the best first language I probably see Python mentioned most.  In these forum discussions someone always seems to snidely denounce BASIC as that old thing with the GOTO and the unreadable spaghetti code.  They don't seem to have a good reason to recommend Python, except that it isn't BASIC.

People also recommend C and it's derivatives such as C++ which also has GOTO.  So go figure.

Wait, here is something scandalous!  On the Python Software Foundation website, in their design and history FAQ page, they actually answer the question about why there is no GOTO in Python by encouraging people to use exception handling as a hack to simulate something like GOTO!  Ummmm.   See for yourself.  https://docs.python.org/3/faq/design.html#why-is-there-no-goto

Okay, getting back to the starfield simulation example.  If you look at the version of the starfield simulation written in Liberty BASIC, it addresses some of the things that BASIC is frowned on about.
  • GOTO - Uh oh, not really.  There is one GOTO, but in this case I'm not sure a WHILE/WEND forever loop is really better, so...  The Commodore BASIC version has three GOTOs.
  • Structure - The Liberty BASIC version uses control structures properly the way modern languages do.
  • Line numbers - Liberty BASIC programs do not require numbers.  You can give your routines meaningful names instead of numbers.
Okay, let's be frank.  Liberty BASIC was not the first version of BASIC to solve these problems.  There are many BASICs with modern features, and so it isn't fair to criticize BASIC as being a bad language for beginners.  BASIC has been a proper language for teaching good programming practices for a very long time now.

What do you think?  Comments welcome.  :-)


2 comments:

Unknown said...

Funny you mention this. I work for a county public works department and I wrote my first "useful" Liberty Basic program this week. It was nothing very complex. It just read in a file of GPS measurements collected by my survey crew into an 2D array, sorted it (I really appreciate that SORT command), then outputted to another file in a format that could be read by our survey data processing program. It was so much easier than the C programming that I had to suffer through in college (The college I was in only offered C, FORTRAN or Pascal). I was so happy, I posted my Liberty BASIC experience on Facebook and Instagram (#LibertyBasic). A couple of my professional IT friends commented that they would have used Python or Perl for that sort of thing. I told one of them that BASIC my not be fancy, but it gets the job done. Thank you for writing Liberty BASIC, it is just the right fit for me.

Carl Gundel said...

I'm glad you are having a good time with Liberty BASIC. Just yesterday I highlighted an older blog article I wrote where I described how we ran a whole factory using BASIC.

Python may be a decent language, but I don't know why anyone would want to use Perl. Where I come from we call that a write-only language. Come back a little while after you wrote the program and you won't be able to figure out what it does. ;-)