Lesson 1 - Intro to the
NetRexx Language Welcome Welcome to Lesson 1 of the NetRexx Course. This lesson is an introduction to the NetRexx language - what it is, where it comes from, what you get with it, how you can use it, and details about its syntax. Hopefully by the end of this lesson, and by performing some of the suggested exercises, you will understand more about NetRexx and it's environment. Scattered throughout the lesson you'll find several 'pop quiz' questions. If you are unsure of the answer, feel free to either email me (mailto:[hidden email]) or the NetRexx Course mailing list (mailto:[hidden email]). What is it? "NetRexx is a programming language derived from both Rexx and Java. It is a dialect of Rexx that retains the portability and efficiency of Java, while being as easy to learn and to use as Rexx." - Mike Cowlishaw, inventor of NetRexx. NetRexx is a computer programming language. It's history comes from Rexx (see http://www2.hursley.ibm.com/rexx), a human oriented programming language, and a far more recent language, Java (see http://java.sun.com). Because of this, NetRexx is really a hybrid language - Rexx moulded to fit desirable features of Java. Having said that, NetRexx is still a programming language, and theoretically it need not be compiled to java executable code, someone could write a NetRexx compiler to produce native Unix binaries for example. The 'reference implementation' of NetRexx (the original implementation provided by Mike Cowlishaw of IBM UK Laboratories, who invented the Rexx programming language), comes with a compiler that takes your NetRexx source code and compiles it into executable Java binaries called byte code. So that means that programs written in NetRexx will run just like java programs. If you've heard of Java applets or servlets, theses are just special sorts of executable java binaries. They, too, can be written using NetRexx. The good side to all of this is that any NetRexx program can be run anywhere Java is installed, making NetRexx programs VERY portable. In fact, almost every recently developed or enhanced operating system has Java available. The NetRexx compiler, the tool that turns your source into executable byte code, is actually written in NetRexx. Mike Cowlishaw said at one point that it took 19 years to get Rexx ported to it's current set of platforms, but converting the NetRexx compiler to NetRexx source (from it's original Rexx source code on OS/2) took 3 weeks and runs on more platforms! (Correct me if I've got it wrong Mike or anyone else). Now that's productivity. To program in NetRexx you don't have to know anything about Java. But to write useful programs with NetRexx, you will. So part of this course will be about explaining how Java works. Don't be worried if you currently know nothing about Java, we'll gradually fix that problem. Pop Quiz: Define NetRexx. What do I get with NetRexx? I'm assuming you've downloaded and installed NetRexx. You need Java installed to anything useful with NetRexx, so here's hoping you've downloaded and installed Java 1.1 or higher as well. When NetRexx installs, it creates a directory (e.g. c:\NetRexx or /usr/NetRexx) to hold it's files. To complete the install, you should have taken the nrtools.zip file from this directory, and unzipped it into your Java installation directory (e.g. \java11 or /jdk1.1.6). This step adds important files to your computer: NetRexxC.zip - the executable code for the NetRexx compiler NetRexxR.zip - the NetRexx run time code netrexxc.cmd, netrexxc.bat, nrc.cmd and nrc.bat - a batch file to make executing the compiler easier hello.nrx - some sample NetRexx code to test the compiler and your installation In the NetRexx installation directory (e.g. c:\NetRexx or /usr/NetRexx), there are many useful files to help you with developing in NetRexx. Starting with the HTML documentation, netrexx.htm, moving along to the many samples that are worthwhile understanding as we continue with the course. All the samples will have a .nrx extension, e.g. Hello.nrx, Buttons.nrx, HelloApplet.nrx. -- Pop Quiz: What's the simplest way of executing the NetRexx compiler for your platform? Writing And Compiling NetRexx Code Ok, lets move on to some more practical matters, like writing code. NetRexx is really an object oriented language, but don't let that scare you, it's also a human oriented language, and that makes it far easier to get your work done than with almost any other language. For example, if you ask a friend the telephone to "Go buy some bread" is that any different to asking them to "Go buy some Bread"? Did you pick the difference? To many computer languages "Bread" and "bread" can be two completely separate things, although us mere humans usually don't think so. Tools To write NetRexx code, you'll need some form of editor to type the code into. On a Microsoft Windows platform, for example, a simple editor is Notepad. A more full featured editor is Word Pad. There are also a few Integrated Development Environments (IDEs) available for NetRexx, devpad (see http://www.mygale.org/~lafaix/devPad/ ) and Visual NetRexx (see http://www.trongus.com/VisualNetRexx/ ) are two. Compiling Once you've chosen your tool for now, you'll need to know how to invoke the compiler. For Windows and OS/2, there are pre configured batch files (netrexxc.bat, netrexxc.cmd, nrc.bat, nrc.cmd) as a fast path for invoking the compiler. On other platforms, you'll need to do it "the hard way" by invoking java with the correct arguments: java COM.ibm.netrexx.process.NetRexxC NameOfYourNetRexxFileHere.Nrx -- Suggested Exercise: Compile and run hello.nrx that the NetRexx installation supplies. Read the code. OO vs 'Scripts' In writing NetRexx applications, you will either choose to ignore OO concepts altogether and write 'scripts' or get completely carried away with OO and use it almost all of the time. Writing a script involves only a subset of the NetRexx syntax, and almost no knowledge of OO concepts. About Objects There is a lot of mystique and confusion around Object Oriented Technology. Mostly, it's because the ideas aren't that well communicated in the first place. You may skip this section if you feel comfortable with OO technology and concepts already. What's an object, and why is OO all the rage? The first real phase of application development that explained things simply was Structural (or Procedural) Application Development. This way of doing development focused on the functionality that the application was to provide, progressively dividing the task into more manageable 'procedures' until finally code could be written. This was called top down development. This had two problems: The functions were completely dependent on the data passed to them by other functions. If the format ('type') of this data changed, there were changes needed everywhere the data was passed. The functions were an integral part of the application they were written for, and on the whole, were not very 'reusable'. So how did OO solve this problem? It changed the focus of development from a functional process to an 'object' process, where an object is a logical collection of functions and the data those functions share. This meant that the data that was shared by the functions could be hidden from other objects (called encapsulation), and hence if changes were needed the impact was far less. Since the functions were now grouped together in some logical way, they usually provided some sort of service or business process, which was more likely to be reusable. Objects have properties (data), and methods (functions) that use those properties. The objects properties are available for as long as the object is available, and can change value over time. An object can be something simple like a button in a GUI: It has some properties associated with it, things like the text of the button, the size of the button, background/foreground colours, font used etc. It also has some functionality associated with it, e.g. it can handle being clicked, and notifies interested parties when it happens. Objects can also be very complex. Consider the NetRexx compiler for example. It knows how to do something extremely complex: read our code and translate it into java code and then compile it. Why use OO Applications developed using OO techniques are different from procedural applications, in that they are really a group of objects co-ordinated to get the job done. Think of a car. The car has some properties: an engine, wheels, doors, a frame etc. It also has some methods: turn on, accelerate, slow down, turn off. To accelerate the car 'object' co-ordinates with the engine 'object', which in turn co-ordinates with the wheel objects. Procedural applications are usually a model a single way of doing things, where OO applications are are a model of the ways things can interact, making OO apps far more flexible from the developers perspective at least. The Class When coding OO applications, the developer writes a definition for all objects of the same type, called a class. A class is a template for the objects to be created, it defines the properties and methods that all objects of that type will have. For example, if we have our car object, we can write a class definition for it, like this: --------------8<----------------------- Cut Here ------- class Car Properties Inheritable anEngine wheels doors frame method turnOn /* put code to turn on the car here */ Say "The car is on!" method accelerate(toSpeed) /* accelerate the car to the speed passed in the parameter 'toSpeed' */ Say "Taking it to warp: "toSpeed /** This method is called when java runs an object from the command prompt */ method main(args=String[]) static car1 = Car() -- our first car car1.anEngine = "Fast" car2 = Car() -- our second car2.anEngine = "Slow" -- do something with the new cars car1.turnOn() car2.accelerate(12) --------------8<----------------------- Cut Here ------- |
Free forum by Nabble | Edit this page |