tutorials

Spring 2007
course
navigation

Programming

1. The program has been written in Java and Perl. Both have bee written as modules, with sample executable scripts.
The Perl code is in the tar.gz file as Acme::FTree. The sample executable script can be used as: sample.pl sampleInputFile.
The Java code is in the .jar file in the grouping FTree, and the .jar file also contains the sample executable script Sample.java/class. The jar file has been made executable, with the usage: java -jar FTree.jar sampleInputFile.
2.Java is a high level, object-oriented language that exists somewhere between the worlds of compiled and interpreted languages. In order to run Java code, it must be ‘compiled’, but unlike other compiled languages, such as C, it is not rendered into a platform-specific machine language, but instead into Java byte-code, which is then interpreted by the machine at run-time. Although Java byte code can itself be compiled into machine language, I’ve never heard of anyone actually doing so – it would defeat one of Java’s major advantages, its near independence from the platform it is running on. Because the byte-code must be interpreted by a virtual machine, any computer with the virtual machine installed can run any java program. This cross-platform ability makes Java very useful for web applications, where any system could access the program. However, because Java isn’t usually compiled and must be interpreted by a virtual machine, it is not usually efficient in terms of speed. While Java is serial in most basic uses, it does support threads, and it has a great deal of support for asynchronous and parallel operations in client-server internet programs, which adds to its popularity for web usage. I like Java for its strongly typed approach to variables, and I find that its completely object-based nature and rigid structure makes it easier for me to write modular code, and to produce larger, more complex programs.
Perl is another high-level language, one that also compiled to a byte-code before being interpreted (although unlike Java, Perl is compiled right before execution). Perl also has the cross-platform abilities of Java, although Perl interpreters are less ubiquitous than Java interpreters. Perl, though, has the advantage of being open source, both in the language itself, the compilers/interpreters, and most of the available code. Like Java, it is primarily serial, but with support for threaded programs and asynchronous calls. However, where Java is very much object oriented, Perl supports and uses objects, but without making them a focus or a major stylistic consideration unless the programmer tries to make them one. In terms of style, Perl is incredibly flexible. The language is primarily procedural, but supports both functional and object-oriented programming styles. Personally, I think that the implementation of objects in Perl is much less useful and much less developed than in Java, but they certainly are supported and useful. For me, the major strengths of Perl are its immense faculty with strings, particularly with Perl’s regular expression. I also appreciate its low overhead, ease of use, and weak typing when working on small tasks. With Java, even the simplest programs can be a production to create, I find Perl extremely useful as a sort of super scripting language, which I gather is part of its history and inception.
Of all the languages I regularly use, C is probably the most frustrating, and perhaps the most useful. C has been described as the lowest of the high-level languages, and it seems to me to straddle the line between high and low level, giving the programmer great deal more direct control over the exact behavior of the program, and lacking the automation over things like memory usage that most high-level languages seem to have. C is a compiled language, and indeed forms the basis for many other languages, whose compilers (or interpreters) are written in C. The ISO standards for C have been open for quite some time, and the GCC, an open-source C compiler, was the first piece of the GNU Project. C falls very cleanly into the category of procedural languages, and has no native support for true objects. C has very good support for parallelization and inter-process communication, with methods for both threading processes and forking them, depending on the operating system it is running under. While C is very well supported under all major operating systems, programs written in C are not cross-platform. At best, code must be recompiled to run under a different operating system or architecture, and at worst, largely re-written. As an example of this is parallelization, the method for parallelizing code differs between Windows implementations of C, which support threading, and Unix-bases systems, which support forking. Because the C code has very little between it and the operating system, it is much more sensitive to such changes than Java or Perl. The primary advantages of for me of programming in C are the level of control it gives the programmer over resource utilization and actual program functions, and the speed with which well-optimized code can run once compiled. Perhaps as a result of these considerations an others, C and its derivatives are still very popular for writing applications and operating systems.
Of the languages on this list, MIPS assembly code is the truest low-level language. As an assembly code, it is a relabeling of individual processor instructions for the MIPS processor, and so is only one small abstraction away from pure machine code. As a result, MIPS assembly code is very much an imperative language, with every statement either affecting the environment (memory or registers) in some way, or jumping to another section of code. MIPS processors don’t have interlocked pipelines, so every command must be completed in order, and this language is by nature perfectly serial. In general, MIPS assembly code is compiled into machine code and run, although emulator/interpreter programs exist to run MIPS assembly code on non-MIPS architectures. While creating programs in assembly code can be a fun exercise, and MIPS is a RISC (Reduced Instruction Set Computer) architecture and thus easier to work with than, for example, x86 assembly code, it is still much harder to work with than any higher-level language, and is only really useful for writing compilers.
JavaScript is a very high-level object-oriented scripting language designed for client-side scripting and applications using the web. It is interpreted, usually by a browser, and as such is highly cross-platform. This is part of the intention behind its design, as the code is usually provided by a web server to automatically run on the viewer’s computer. The development of asynchronous JavaScript in some newer web applications has become a new paradigm, or at least a fad, in some areas of web development. While I prefer Java’s handling of objects much more than JavaScript’s, it does have its uses in interactive web pages.
PHP is a very high-level interpreted scripting language designed primarily for use with the web. It shares a great deal in common with Perl in terms of both syntax and functionality, and both seem to follow the same paradigm of high readability for the programmer. While PHP has other uses, it seems to be best known for and most used in the construction of web pages, and the interfacing of web pages with other server-side tools, such as databases or inter-site interactions. Because of its development in that direction, PHP has advantages over some other server-side methods of web programming, such as the ability to be interspersed with HTML code on some web servers. Other than that, it has many of the same strengths and weaknesses as Perl, including being open source. For my own usage, I cannot imagine using PHP for anything other than web development.
BASIC is an old high-level language with many variations and decedents. In its various incarnations, it has sometimes been compiled, and sometimes interpreted, although most of the BASIC versions or derivatives I’ve used have been interpreted. It is a simple, procedural, serial language of relatively limited utility. It’s major advantages are its simplicity and easy of use, its ubiquitousness, and the ease of writing interpreters for it. As a result, various incarnations of it are everywhere in small programmable devices, such as graphing calculators. In those variations, such as TI-BASIC (the BASIC derivative running on Texas Instruments graphing calculators, it provides a customized and easy to use scripting language for the user. The programs written for these various incarnations are generally incompatible, but the core elements of each implementation are similar enough that if you know one form of BASIC, you can work with most others without much difficulty. Even though I haven’t used BASIC on a full computer in many years, I find its simplicity and ease of use helpful as a scripting and batching language in the various places I find it, from calculators to environmental controls.

3. A re-do of the Huffman encoder from the Algorithms exam, this time in C (and this time producing actual binary files, instead of just files with text 1s and 0s). The file output.hzip is the result of running this program on huffman.c, its source code.
http://cs.marlboro.edu/ courses/ spring2007/tutorials/ ambrose/ exams/ Programming
last modified Wednesday April 18 2007 6:25 am EDT

attachments [paper clip]

     name last modified size
   $~scratch May 10 2007 3:07 pm 0B [DIR]Acme-FTree-1/ Jun 3 2007 2:49 pm -    Acme-FTree-1.0.tar.gz Apr 17 2007 12:38 pm 7.82kB [TXT]allclasses-frame.html May 10 2007 4:27 pm 1.02kB [TXT]allclasses-noframe.html May 10 2007 4:27 pm 920B [TXT]constant-values.html May 10 2007 4:27 pm 4.64kB [TXT]deprecated-list.html May 10 2007 4:27 pm 4.58kB [DIR]FTree/ Jun 3 2007 2:49 pm -    FTree.jar Apr 18 2007 12:08 am 56.3kB [TXT]help-doc.html May 10 2007 4:27 pm 8.40kB    huffman May 10 2007 3:06 pm 12.4kB [COD]huffman.c May 10 2007 3:06 pm 18.4kB    huffman_out May 10 2007 3:07 pm 11.1kB [TXT]index-all.html May 10 2007 4:27 pm 16.5kB [TXT]index.html May 10 2007 4:27 pm 1.20kB [TXT]jims_session.txt May 10 2007 3:13 pm 148kB    mainClass May 10 2007 4:27 pm 43B [DIR]META-INF/ Jun 3 2007 2:49 pm -    output.hzip Apr 18 2007 2:50 am 11.1kB [TXT]overview-tree.html May 10 2007 4:27 pm 5.19kB    package-list May 10 2007 4:27 pm 6B [DIR]resources/ Sep 4 2011 5:42 am -    Sample.class May 10 2007 4:27 pm 438B [COD]Sample.java May 10 2007 4:27 pm 236B    sampleInputFile May 10 2007 4:27 pm 830B [TXT]stylesheet.css May 10 2007 4:27 pm 1.20kB