Home > Java > Looking back at Basic

Looking back at Basic

A friend of mine has given me an old book “Data structures for personal computers” by Langsam, Augenstein and Tenenbaum. I have russian translation of 1989, original english edition is dated at 1984. This book talks about representation of data structures, such as stacks, queues, linked lists, trees in Basic. My friend isists that this book is a best one describing data structures. I’ve made some googling and found out that authors still keep writing about data structures, but now they use C, C++ and Java as implementation languages.

I will read that whole book because my friend isists. However, I doubt that I’ll find something new there, since I’m already familiar with all those data structures by using Java. I know how their implementation is different, but they can provide same interface. The only thing implementation affects is a speed of different operations, so developers can choose implementation based on most-frequently used operations. But I’ll read all this book until the end. For me reading about basics again and again is not boring, it helps to understand basics better. Mainly my attention is not to ideas and data structures, but to syntax.

Book was written in time then 8-bit home computers were at top of popularity, so lots of people used Basic. Authors are collage teachers, so they’ve choosen Basic so they could use that book in their education. I’ve also used Basic in 80s, so that book is not a problem for me. This book is very interesting for me because last time I’ve wrote something in Basic was 13 years ago. I see large differences between my current programming style, the style I’ve used 13 years ago and style used by authors.

Since I’m mostly progamming in Java, my current style of programming is similar with style used by Sun and Apache (and different from IBM). But if I will do something in Basic, I’ll do that in style I’ve used 13 years ago, because I believe that my style is best for that language. I think that style used by authors is not practical and just used by them in educational purposes.

Authors do it wrong from very beginning. Their approach to software development is to start from requirements and planning, and spend a lot of time on it. For me, this approach is theoretical. I always start prototyping quickly. They justify their way by pointing to difficulties with troubleshooting and possible program redesign. But Basic was never used in projects so large that their redesign will be too difficult. And troubleshooting with Basic always were simple task.

Next, authors try to apply procedural programming style to Basic, which is absolutelly unsuitable for that. They propose to declare some variables as “input parameters”, and other variables as “output parameters”. So each invokation of sub-routine will include explicit setting of input parameters and explicit getting of output parameters. Authors use “swap” as example of their approach, and 3 operator-operation becomes 12 line (including comments) “procedure”. Horrible.

Nowdays that approach is called “functional style”: function takes some inputs and produces some output, avoiding any side-effects. But Basic doesn’t have syntax for invoking sub-routine with arguments and return some value. So, sub-routines in Basic were used to produce side-effects. Why bother creating general-purpose sorting sub-routine, if invoking it will make programmer to work hard specifying all arguments ? Much easier whould be to create sub-routine to sort particular array, and just invoke it, without specifying anything at point of invocation ? Another annoyance with sub-routines is that they are not different from GOTO, so they make program’s structure more complex. Because of that “swap” whould always be inlined. Because of that, Basic never had libraries of sub-routines.

I’m not trying to argue that Basic is perfect language. It’s syntax is very limited, and it was not usable for large projects. Now we have much better languages. But author’s attempt to use programming style of Pascal/C with Basic is not good at all. Programming in Basic should be done in style which is better adopted to syntax of Basic.

Another big mistake that authors make is in chapter then they discuss “typical Basic errors”. First, they show variable re-use, next they show calculating average value. First error is pure “translation” error: when problem was translated into Basic, same variable was used twice. Such problem is also possible in any language, but some programming techniques help avoiding them, however such techinques are not available for Basic. Second error is pure algorithmical one, and doesn’t relate to programming language at all. Mixing those problems together is not good.

I want to say thank you to Basic, it was great language at time, and helped lots of people to learn programming. Demands of software development made other language more popular, but I will always remember good old Basic.

There are great variety of programming styles. General approaches with “separation of concerns” are good, and some languages tried to make their syntax to help implement such approach. But styles should not be used blindly. Better to use style which is more suitable for each language. I believe that each programming language invents own “style”, most suitable for that language.

The book itself is not a great source of knowledge for me. But it’s a great food for thoughts.

Categories: Java
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: