18th August 2002 | PROGRAMMING IN THE 21ST CENTURY |
Brian Grainger |
PROGRAMMING IN THE 20TH CENTURY When I bought my first Commodore PET computer in the last century my primary use was to give my brain a new tool to extend its capabilities. A computer could calculate a lot faster than I could and one of my interests, then and now, was number theory. I could use the computer to search for prime numbers or test the validity of conjectures. Indeed, I remember running some trials for a University student in Wales for this very task. In order to do this work I had to program the PET to do my bidding. The PET computer came with a version of Microsoft BASIC and it was this programming language I used at the start. As time went on and I realised its deficiencies I turned to COMAL, the best structured language I found for a beginner. I stuck with COMAL when I moved to the Amiga and even when I moved to a PC. My first PC was a portable(?) Epson that run under DOS and I got a COMAL interpreter and compiler for that. Of course, in 1992 I moved to an IBM PC compatible desktop for all my work, but despite running under Windows, (version 3.1), I still used my already written COMAL programs for my chequebook program. It ran in a DOS Window and I still use it today in a similar manner. One of the sad things is, that as I got to use Windows more and more, I got to program less and less. Programming really was restricted to using the macro languages of first Lotus 1-2-3 and then Microsoft Excel and Word. I could do most things I wanted with Microsoft Office and, with the advent of the Internet, I could usually find programs on there to do those things that Office could not. It was not very satisfying though. I was not being creative. I am sure I am not the only person to feel this way. I have a friend who retired some years ago and bought himself a Commodore 64. He used to program this machine, again with BASIC or COMAL, as a means of keeping his brain active. Over the course of time he eventually bought a PC with Windows. However, despite making pleas for a programming language to use on it he has done no more programming in recent years than I have. TRIALS AND FRUSTRATION I like the concept of the Graphical User Interface, (GUI), and I can see that my chequebook program could be enhanced and made easier to use if I rewrote it to take advantage of a windowing system. I have never done it though. Although COMAL gives the capability of creating windows it has not really been updated as an object oriented programming language and would not be fit for purpose. I have often mused with translating my program into Excel and using Visual Basic for Applications, (VBA). However, when I first started trying to write the most basic of things in VBA, a sort of reaction timer program, I found it difficult to get started. The problem was not that of dealing with event driven programs, rather than step by step based programs, because I had already had some experience of that. The problem was that VBA was difficult to get started. The help file system was, and still is, bl**dy awful. If you know what you want it makes a good reference tool, if you can work out how to get at it, but it is no good for learning. Books did not seem to help much either unless you were intending to devote a significant amount of time to the project. BASIC and COMAL allowed the beginner to write simple things very quickly. Syntax was like English and, in the case of COMAL at least, was very forgiving of user errors. VBA was nothing like this. It was a professional tool. It seemed to me that if you wanted to create a button on the screen with the standard 'Hello World' message you need a command with defines where and what size the button is and the text to be displayed, something like the hypothetical: Button(<topleft>, <width>, <height>, <message>) Now, to be fair to VBA, there exists a nice simple command: Msgbox (<message>, <buttons>) The definition of buttons is a bit esoteric as it uses a numeric value to define the type of buttons to appear. However, the real problem comes in trying to write the rest of the code to make the button show on the screen. It is not easy and the beginner would be confused. It is a long way from the event driven code equivalent of: Message$ = "Hello World" In all the books I read on VBA not one gave an example of how to print "Hello World". I find this curious since it is de rigeur in most Programming books. VBA also comes with its own gobbledegook to understand. We have objects, properties and methods. I sort of likened this to the grammar of a sentence. The object is the equivalent of a noun, a thing. A property is the equivalent of an adjective, a descriptive attribute of the object. Finally method is the equivalent of a verb, i.e. what you do to an object. All well and good until you realise that in VBA for Excel there is a Range Object and a Range property. To me a range is a thing, an object. Very confusing. I have to say this terminology applies to Object Oriented Programming (OOP) in general. It seems to me it is going back to the bad old days when mainframe programmers where high priests of the big iron and used their own language to keep out lesser mortals. With all these irritations I did not look at VBA much longer for programming in Windows. Visual BASIC itself was ruled out for similar reasons and the fact it cost money! Professional software developers seem to make a lot of use of C++. I had a look at this. This suffered from the sort of irritations that Pascal or Algol gave me in the old days. You had to be very precise how you wrote it. Miss a bracket or a semicolon and you were in trouble. Finally, as we get into more recent times I hear Java and Javascript bandied about. They are not related. I must admit I find Javascript better to come to terms with than VBA but it can only be used within browsers that support it. Javascript is not suitable for applications outside of the browser. Java is used here and again I found it very precise in nature. I am not sure how one gets Java for Windows either, especially since the Microsoft spat with Sun, and whether it costs. I was to remain frustrated. That simple language to program GUI applications did not seem to exist. This was how things stood until recently. At work we had a student in his industrial period working at the desk next to mine. His work involved some programming so I asked him what he used to program, when he wanted to create a GUI system. For these sort of things, he said, he used Delphi. This was a programming tool created by Borland and was an alternative to Visual BASIC. The really interesting comment the student made was that to create Windows and other objects he drew them on screen, rather than describe their parameters. Delphi or Visual BASIC would take care of writing the code. I realised what he said was true. I had created forms in Access and this was how it was done. However, once the objects were created you could set the parameters for the object on a context menu for this purpose. Clearly this was a different approach to what I was originally looking for. I questioned myself as to whether I was following the wrong approach. I finally resolved that I wasn't. I likened the method of drawing an object and then letting the program take care of the code to doing sums with a calculator instead of learning basic arithmetic. As a mathematician I have never been happy with that scenario. A calculator is a tool that you use to save time but you must understand the basics first, if only to have some idea when the calculator is giving the wrong answer because you pressed the wrong keys. Similarly, drawing objects without understanding the basics of the programming may well save you time but will be a drawback when you have to adjust or correct programming errors. I know from experience that I can use Front Page Express to avoid learning HTML, but to produce decent web pages I have to understand HTML to tweak the code resulting from Front Page Express. BLOW ME DOWN WITH A FEATHER! One day, as is so often the case, serendipity struck. I had just got round to reading my October 2001 edition of Computer Shopper. This was in June 2002! There was an article on Rapid Application Development, (RAD), Tools and a large proportion of the article was devoted to a language called Tcl and its GUI wrapper, Tk. Incidentally, I would like to mention in passing that Computer Shopper has moved beyond its original target audience of those buying PCs and is now a top notch magazine. Now, apart from the article saying things about Tcl/Tk that I liked, I had come across this name before because another work colleague had books on the language on his desk. I asked my colleague about it and getting favourable responses I took a quick scan of his books. In the overview chapter in one book, after a quick note on how to sum items in Tcl, came the defining section - Hello World with Tk! This was how you coded the classic simple program:
and this was the result: That did not look too difficult. I did not understand the 2nd line of code but the first line made a lot of sense.
Now I appreciate that this button command does not indicate its size or position but, rest assured, the optional attributes exist to define them. By not defining the size or position Tcl/Tk has taken the default of a window just big enough to contain the button, which is just big enough to contain the text and the default borders. In this example -text and -command are just 2 possible attributes defined out of a possible 28. For completeness, I will explain the second line of code does here. When you define the button it is just that, defined. It is not displayed. You can define lots of other objects, or widgets in the terminology of Tk, and then have them all display at once. The 'pack' command is one way of displaying objects and, knowing that, it is now obvious that the 2nd line of code simply displays the object named '.b', the button with 'Hello, world!' on it. I think you can agree with me that this was rather simple to code. I was sold already, but was I to be disappointed as I found out more about Tcl/Tk? Let me describe a little more about the language, some of which has come from this book: Tcl and the Tk Toolkit by John K. Ousterhout. Published by Addison-Wesley (ISBN 0-201-63337-X). This has become the defining book as John Ousterhout actually developed Tcl/Tk.
As you can see from the table Tcl/Tk contains all the things found useful in the simple languages such as BASIC and COMAL. Are there any disadvantages? So far I have noticed a couple. Coming from a C environment, Ousterhout has persisted with the use of braces, {}, to enclose code blocks. Here is an example:
Note the {} signifying the stand and end of both the procedure block and the while loop. While it adds an overhead to the interpreter, the BASIC/COMAL approach of keywords such as endproc and endwhile is much preferred by me, if only because it is more readable and understandable. The second disadvantage arises from the fact that Tcl/Tk is a scripting language. In some respects it appears to have a peculiar syntax, compared to a BASIC/COMAL equivalent. set result [expr $result*$base] is equivalent to the BASIC: result = result * base All the brackets and dollar signs have meaning and cannot be omitted. These disadvantages are serious but, because the easy creation of a GUI is overwhelmingly helpful, I am prepared to put up with them at the moment and see how it goes. I have so far neglected to mention the other killer ability of Tcl/Tk. It exists for Windows, Linux and Mac. Write your code for one and it works on the others. True platform independence at last. Perhaps you can see why I am prepared to drop some of my principles and put up with the disadvantages! WRITING CODE By this time I was eager to write some code so the question arises - how does one do that? At its most basic level you simply type Tcl/Tk commands at your Tcl command line and they execute. The Tcl command line is provided by the application tclsh. This stands for Tcl shell and I will leave it for your amusement to work out how to pronounce it! If you use a windowing system, not necessarily MS Windows, there is a windows shell, called Wish. I tried this to produce the 'Hello World' program. However, when one gets a little more serious, one realises that using Wish alone could be a bit irritating. The process could be described as follows:
What you soon realise is that you want what is called a Integrated Development Environment, IDE. This allows you to code, run and debug from one simple desktop. Time to talk to my work colleague again. He mentioned two that he knew of. The first of these, although quite popular, turned out to be shareware so I did not pursue it further because the second was freeware. The IDE I looked at was called ASED, which I assume stands for 'Andreas Sievers Editor' since it is he who wrote it. As is common in the free software community this tool was written in the language it was to support, Tcl/Tk. Here is a screenshot of ASED after I had loaded and test run the 'Hello World' Program. Remember, the above was created with Tcl/Tk. I think that is a graphic demonstration of how powerful this language can be. WEBLINKS Tcl/Tk, ASED, books, tutorials, help files, etc. are all freely available on the Web. Everything I have downloaded so far has been well-behaved regarding installation under Windows. No peppering of the Windows area with extra system files and only minor, well documented additions to the registry. I guess one should expect this from the free software community, but it is a pleasant change! Here is a list of web links to get all that you need to follow me in experimenting with Tcl/Tk. Where to download Tcl/Tk: http://www.activestate.com/Products/Download/Get.plex?id=ActiveTcl ActiveTcl is a version of the original Tcl from Scriptics (the company run by John K. Ousterhout) in an easily installable form. From the download page you can also download some HTML documentation. The file name of the documentation at the time of writing is: ActiveTcl8_3_4_3-html_tar.gz This is effectively a .tar file, called ActiveTcl8_3_4_3-html.tar, which has been compressed to a .gz file. If you use Winzip to uncompress it will ask for the name of the tar file, (which you give including the .tar extension). Winzip will then ask if it is to extract the files from the tar library. You can do so or use Winzip at a later date to do this. When extracted you will have about 6MB of documentation. This documentation is an HTML copy of the help file associated with ActiveTcl. Where to download ASED: http://www.mms-forum.de/ased/download.htm Where to download the book, Tcl and the Tk Toolkit: http://hegel.ittc.ukans.edu/topics/tcltk/ This link points to 4 postscript files and a text file. The postscript files have a corrupt first line which should read: The book itself is a copy of the first draft of John K. Ousterhout's book. While not the latest edition it is sufficient for the beginner. Of course, you can always buy the latest edition. Where to download the book, Practical Programming in Tcl and Tk: PDF: Postscript: Again, this is a copy of the draft of the first edition. The Postscript version is from the web site of the author and explains clearly the draft nature of the document. You can get sample chapters from the 2nd Edition, (in HTML form), at: You can get sample chapters from the 3rd Edition, (in PDF form), at: Where to find a Tcl Tutorial: http://www.msen.com/~clif/TclTutor.html Web Pages of Tcl/Tk Links: http://hegel.ittc.ukans.edu/topics/tcltk/ UPDATE Since I wrote the above I got side-tracked before uploading to the web. During that time I found an interesting thread to a comparison of Tcl/Tk with other languages: This thread was very interesting for two reasons. First, the founder of the free software movement, Richard Stallman, started religious wars by telling people why they should not use Tcl. Secondly, there is much discussion of the disadvantages of Tcl I mentioned earlier. I have come to realise that a prime driver for why I like Tcl/Tk is the Tk part! Stallman does not raise objections to Tk but makes points against Tcl alone. While I perceive he is somewhat technical in his objections, I would like to avoid the weird syntax and use of brackets of Tcl if I could. Tk can be used with other languages. The thread primarily discusses two other alternatives to Tcl, namely Perl and Python. From the comments made I favour Python. Like Tcl it has cross platform versions, even one for the Amiga, and it has the more usual syntax. Perl seems to be for Unix/Linux based systems only and it is primarily a scripting language. I am not sure if it has been used for applications. It is when I looked at how one calls up Tk in Python that my eyes glazed over. It looks a bit complicated for the beginner. Nevertheless, this must be an area for future investigation. If only I could find those COMAL guys again and encourage them to do a cross platform version, with Tk interface I would be in heaven! Until then I am going to give Tcl/Tk a go and see if I can recover my programming enjoyment. I would be interested in hearing from anyone who has used Tcl/Tk or some alternative simple language. Any comments would be welcome, but if there are any answers to my perceived disadvantages of Tcl/Tk these would be especially useful. At this time I am NOT a fully fledged user so don't expect any answers to 'how to' questions! I want some help from my readers this time! David Proffitt writes, (27/05/2003): My experience is similar, but I have never used, or could get the hang of, BASIC. One's early prejudices seem to carry forward. I picked up a copy of C++ Builder 4 from the cover of PC Plus and have been programming ever since. RAD makes it easy. I think a database ability is also essential. You can see how far I have got from my web site. Ed: In particular, have a look at the history page for the above web site, which explains how David got into programming. |
|
|
|
|
|
|
|
|