Programming  
See also my pages for:  
 
JavaScript
Online Tips
Windows

"The computer programmer ... is a creator of universes for which he alone is the lawgiver ... No playwright, no stage director, no emperor, however powerful, has ever exercised such absolute authority to arrange a stage or field of battle and to command such unswervingly dutiful actors or troops."
— Joseph Weizenbaum, Computer Power and Human Reason

Perl VisualAge RPG Java OOP Alternatives Visual Basic Miscellaneous links Newsgroups

  The quote above describes pretty well why I love my profession. I may sound like a real control freak but my left-brain needs an environment where it can exercise its desire for logic and order without causing too many waves, and programming is it. In my job with Safety Insurance in Boston, I create software for use by our independent insurance agents throughout Massachusetts, who now have web access to our AS/400 database for their policies and claims. I have created this software in several formats: Windows (previously OS/2) client/server applications installed on each PC, Java applets that reside on the server and are run from a web browser, web-based (Perl driven) front ends connecting via XML to the AS/400 (RPG driven) back ends through WebSphere MQ message queues, and Perl applications that use SQL to get data from the AS/400 and Sequel servers. In September of 2000, this software, named PowerDesk, was part of a system that earned Safety Insurance First Place in the Beyond Computing Magazine Partnership Awards, honoring Safety for having successfully aligned our information technology operations with our primary missions. Using XML and Perl looks like the way we will continue to do development at Safety, and one of my first enjoyable tasks using the MQ was writing an XML parser for our claim entry application.

I have been programming for a couple of decades in a variety of languages, depending on the job and platform. Professionally, I have mostly used RPG, which I have worked with in various forms since the 1980s, and currently I am developing web-based server applications in Perl. As you can see from my website, for personal use I also do a lot with HTML, JavaScript, Perl, and a bit of Java.


Perl
  Professionally I am a web programmer, and Perl is my primary language. One of my first projects using Perl was to make the listings of current job openings on our company website dynamically load instead of being typed into a static webpage. Previously, the Human Resources (HR) department would email information for new job openings to the web development department, where it would be formatted in HTML, and when the job was filled the page would have to be edited again to remove it. I wrote an application that enables the HR department to enter the job descriptions into a database, and then I modified the Current Openings page of the website to run a script that querys this database and lists the available jobs. If you click on a specific job title on the list it will read the database and display the job description. When the job is filled the database is updated and the job will not longer display on the webpage. Both the web-based maintenance application and the listings pages were done in Perl.

 Perl tips & examples

I thought an easy way to show some Perl how-to info was to display some scripts I have created.
  • Click on the Title to run the application
  • Click on the name.pl to view the source

Create link
(create_link.pl)
At times I have wanted to download a file that is embedded in the HTML of a webpage and I would have to create a little webpage with a link to the file so I could use the Save Target As option on the the right mouse button context menu. This script will allow you to just type in the URL and a web link is created automatically. Since creating it I have found it useful for other things, for instance, at work I wanted my initial Perl script in one application to show a button to go back to the previous webpage if the script is called from a link (using $ENV{'HTTP_REFERER'}), but not if the script was run from a shortcut or typed into the address bar of the browser. I used the Create link script to quickly create a link to call my script for the test.
My iPod songs
(playsongs.pl)

I am always telling people about songs I have on my iPod, so to share some of these songs with others I uploaded them to a folder on my web server and wrote this script to access that folder. This script creates clickable links of the songs and also creates M3Us of them dynamically for streaming. (My songs had to be removed from the server so the iPod songs page has been changed.)

All the songs on my iPod are stored in a folder on my PC, and to show a list of those songs I wrote two scripts:
listsongs.pl ··· builds a file of the songs which I then upload to the server
viewsongs.pl ··· displays that uploaded file as a list of songs (display only, not playable)

Mypics
(showpics.pl)
(show_thumbs.pl)
I got a new little digital camera, and to show some friends the photos I was taking with it I made a script to list them dynamically as links. When I present photographs on a webpage I usually create a thumbnail of the photo to click on to see an enlargement, so I wrote a Perl script (show_thumbs.pl) to create the thumbnails dynamically, specifying a width attribute on the <img> tag for the thumbnail which creates a height with the same aspect ratio as the original image. One consideration when using this technique is that all the image files have to download completely before the page is entirely formatted with the thumbnails, but most people I know have high-speed Internet connections now so that was not a problem. The Mypics webpage runs both of these using Ajax (that is one of the best methods to embed Perl in HTML pages).
Reunion Photos
(skip.pl)
My high school classmate Skip sent me 68 printed photos from a class reunion, which I had offered to scan in and put on my Class Reunion page. There were so many photos that rather than create thumbnails individually like I had done for all the rest of the photos on my Reunion page I decided to clone show_thumbs.pl above to create them, and I am using Ajax to put them on the reunion page.
Perl/Ajax/HTML
One technique I like to use on my website is having a simple HTML template use Ajax to call perl to format the content. This is especially useful when you have a lot of items you wish to list or display and you don't want to tediously create all the HTML to present them. You can put them in a single folder and have perl read and list them. You can even dynamically create thumbnails for photos, which I do on these pages.
Videos

I like to show videos on my website using perl scripts in popup windows (generated in a JavaScript function like showVideo below).
play_flv.pl ··· I wrote this script to play Flash videos (flv files) on my server with this Flash Video Player.
Example usage: <a href="cgi-bin/play_flv.pl?filename=somefile.flv&width=400&height=360&title=Window%20Title">
To see in action click Top 10 Favorites.
show_video.pl ··· I wrote this script to play other video formats, including mpg, wmv, and avi.
Example usage: <a href="cgi-bin/show_video.pl?filename=somefile.mpg&width=400&height=360&title=Window%20Title">
To see in action click Granny air bag.
video_embed.pl ··· Most of the videos on my website are on my server, but sometimes I like to link to videos on a remote site like YouTube, showing them in my own popups. Some browsers don't like linking directly to the videos in JavaScript, so I wrote this script to play the videos using <object> and <embed> tags.
Example usage: <a href="cgi-bin/video_embed.pl?video=http://www.youtube.com/swf/l.swf|video_id=6gmP4nk0EOE&width=400&height=360&title=Window%20Title">
You have to know the path to the video ("http://www.youtube.com/swf/l.swf?video_id=..."), which is often shown in the <embed> instructions on the remote video page.
If the URLs to videos already have CGI characters (which would be confused with my usage), I replace ? with | and & with ` and they will be restored in video_embed.pl.
To see in action click Monty Python.
This JavaScript creates a popup containing the output from the Perl script that is specified in the 'ref' variable defined below.
function showVideo(ref, width, height) { var parms = 'width=' + width + ',height=' + height + ',left=200,top=200,resizable=yes' var target = 'myvideo'; // using the same target name makes all videos use the same window object popupWindow=window.open(ref, target, parms); // make the window dimensions slightly larger than the video var wplus = 10; var hplus = 55; // increase height for IE7 to accomodate location toolbar var ie7 = ((document.all) && (navigator.appVersion.indexOf("MSIE 7.") != -1)); if (ie7) { hplus = 90; } var rwdth = width + wplus; var rhght = height + hplus; popupWindow.resizeTo(rwdth,rhght); popupWindow.focus(); }

This HTML link calls the popup function above with the video to play.
<a href="cgi-bin/play_flv.pl?filename=somefile.flv&width=500&height=375&title=Window%20Title" onClick="showVideo(this.href,520,385);return false;">
print_source.pl This is the script I wrote to display the source code in the above applications here on my website (which I am using here to display its own source). The way it works is that it reads in the source-file and modifies some of the elements—for example, substituting entities for < and > brackets, <br> for newline, and spaces for tab—then displays it in the browser to look just like it does in the editor.

   More...

Top of page


VisualAge RPG
  For several years, beginning in 1995, I used IBM's VisualAge RPG to develop client/server applications. We used to do VARPG presentations and labs with Larry Schweyer and Claus Weiss of IBM at COMMON (perhaps I've even met you there). Since Safety was a beta site for their VARPG development tool we had a special relationship with the Toronto lab, and IBM created a case study webpage about us (and Claus, they misspelled my name).

 VARPG programming tips
  Changing the default action on a project's .ivg file

I liked to put my VARPG projects on a Windows menu, and by selecting the menu option have the GUI designer open the project. By default, if you select a shortcut to a project, or if you double-click on the .ivg file in Explorer it will open up a folder showing you the project's files.

You can change this action with a setting in the Windows registry.

  1. Start Regedit.
  2. Open HKEY_CLASSES_ROOT\ivgfile\shell.
  3. In the right panel, double-click on the entry that says (Default).
      Value data: 'Open,Edit,EditP...'
  4. Switch the order of the items to have Edit first.
      Value data: 'Edit,Open,EditP...'
  Calling a Windows API

When I first used VARPG it was OS/2 based, and since OS/2 didn't have a taskbar like Windows it had a slightly bigger viewable area of the screen. This is not an issue in most situations, but on the 14-inch monitors with 640x480 resolution that were common back then, I found it limiting. I had created one non-scrollable window that was so big and full of graphics and essential information that when I ported the application over to Windows 95, if the user had the Taskbar property set to be Always on top (my personal preference) the bottom of the window would be hidden behind the taskbar. I decided that rather than require every user of this software to turn off this taskbar setting, or make the taskbar Auto hide, I had to create an Always on top menu option for my window so it could overlay the taskbar (saving this setting for future returns to this screen of course). The way to do this is to call a Windows API to make the window first in the Z-order. I posted this tip on the news400.com website (which I believe is long gone).

This code sets the Always-on-top mode of a window.

* Prototype the Win32 API function * The values for the Z-Order parameter (hwndInsertAfter) are: * 1 = Bottom most position in the stack of child windows * -2 = Bottom position of all topmost windows, above all nontopmost windows * 0 = Top position in the stack of child windows. * -1 = Top position of all topmost windows. D SetWinPos PR 1B 0 ExtProc('SetWindowPos') D DLL('USER32') D Linkage(*StdCall) D 10U 0 Value Handle D 10U 0 Value Z-Order D 10I 0 Value x D 10I 0 Value y D 10I 0 Value cx D 10I 0 Value cy D 10I 0 Value flags D hWnd S 10U 0 D flags S 5U 0 Inz(3) D bRC S 1B 0 * Get the window handle. C eval hWnd=%getatr('WIN01':'WIN01':'Handle') * To set the Window to be topmost in the Z-order: C eval bRC=SetWinPos(hWnd:-1:0:0:0:0:flags) * To set the Window to NOT be topmost: C eval bRC=SetWinPos(hWnd:-2:0:0:0:0:flags)

You can also call AS/400 API's, but after developing a nice GUI interface to allow users to maintain their AS/400 passwords I found out the hard way that you can run into authority problems in that area.

  Blinking text

Surprisingly, VARPG doesn't have a Blink attribute for any parts. To achieve a blinking affect you alternate the Visible attribute of a part between ON and OFF, using a timer part and the TICK event. This technique works for any kind of situation where you want to toggle a visual display. I have also used it to alternate images associated with a part to produce animation. To use it, create a timer part on the window with the Visible attribute set to OFF. Experiment with the Interval and Multiplier attributes to achieve the timing you want. Be aware that since VARPG is single-threaded, depending on what else is occurring in your application you may not always get a perfectly timed blinking effect. The timer can be used for other types of animation, for instance, you can alternate images or change the location (left, top, and bottom attributes) of a part on the window canvas.

Uses the TICK event to blink the text.

* Turn on the timer to start generating TICK events. C eval %setatr('WIN01':'TIMER1':'Timermode')=1 * Toggle the visible setting for the text. C timer1 begact tick win01 C 'TEXTPART' getatr 'Visible' vis 1 0 C if (vis = 1) C eval %setatr('WIN01':'TEXTPART':'Visible') = 0 C else C eval %setatr('WIN01':'TEXTPART':'Visible') = 1 C endif C endact

  Create macros for the LPEX editor

The LPEX editor used by VARPG and CODE is easily customizable with Rexx macros. I have added a menu called Custom that has options on it I want to use often, most having hot-key mnemonics.
To use the menu macro, Custom.lxl, add the line 'macro custom.lxl' (include quotes) to the Profile.lx macro (to edit click on Options » Profiles » User preferences) so that it is loaded when you start the editor. The macros must be located somewhere on the LPATH (a registry setting*), which you can view by typing 'query lpath ' in the command dialogue (Actions » Issue edit command). I keep my own macros in 'C:\MyMacros', a different location from IBM's, so that they won't get clobbered by upgrades to VARPG. To add this folder to the LPATH, I typed 'extras on c:\mymacros' in the command dialogue.
   * HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADTS Client Server for AS/400\Environment\CODELPATH4
 
Here are 3 of my macros.
  • Custom.lxl – menu macro
  • WinPos.lx – open editor window in preset size and location, cascade if second window
  • PrevPos.lx – return to previous position in source
Some of the options on my Custom menu call macros that come with VARPG, for instance, the option Match begin-end calls match.lx to identify a logic block. If you haven't discovered this IBM macro, you will be amazed how useful it is. Since the mnemonic Alt-m is set up when my menu is loaded, all I have to do is put the cursor on an IF or DO statement, press Alt-m, and the matching END (or ENDIF, ENDDO) will be located with the entire block highlighted. Conversely I can put the cursor on an END statement to locate the corresponding IF or DO.

Custom.lxl also sets up some other useful RPG actions. If I double-click on a line of code the entire line is highlighted, making cutting & pasting RPG code very easy. Since RPG is a columnized language, pressing Enter to create a new line can cause a problem by breaking up your code if you do this when the cursor is not at the end of a line. I have solved this by creating options to insert a blank line Before (Alt-i) or After (Alt-a) the current line.

And of course, I have also modeled on some SEU actions, Alt-b will go to the bottom of the source and Alt-t will go to the top, and Alt-d will duplicate the current line, making it unnecessary to copy & paste the current line to repeat the code. I have added a toolbar icon for Find next to repeat the most recent Find operation, so you can just click to repeat (like F16 in SEU). Look for it next to the little flashlight icon for Find.

     VARPG related links
VisualAge RPG
     Windows Tips and Techniques
Programming with VisualAge for RPG – the Redbook
The Rexx Language
LPEX User's Guide and Reference

Top of page

Java
 
For years I had a Java page on my website (back when I was a Java programmer) that is no longer linked on my main page. Maybe some day I will just put all the content here.


Object-oriented programming
  What is object-oriented programming? OOP could be described as a collection of objects (called classes) exchanging messages to achieve a common objective. This might seem a little vague without a good metaphor. The following is from the book, Teach yourself Java in 21 days, by Laura Lemay and Charles L. Perkins.

   "You can walk into a computer store and, with a little background and often some help, assemble an entire PC computer system from various components: a motherboard, a CPU chip, a video card, a hard disk, a keyboard, and so on. Ideally, when you finish assembling all the various self-contained units, you have a system in which all the units work together to create a larger system with which you can solve the problems you bought the computer for in the first place.

Internally, each of those components may be vastly complicated and engineered by different companies with different methods of design. But you don't need to know how the component works, what every chip on the board does, or how, when you press the A key, an "A" gets sent to your computer. As the assembler of the overall system, each component you use is a self-contained unit, and all you are interested in is how the units interact with each other. Will this video card fit into the slots of the motherboard and will this monitor work with this video card? Will each particular component speak the right commands to the other components it interacts with so that each part of the computer is understood by every other part? Once you know what the interactions are between the components and can match the interactions, putting together the overall system is easy.

What does this have to do with programming? Everything. Object-oriented programming works in exactly the same way. Using object-oriented programming, your overall program is made up of lots of different self-contained components (objects), each of which has a specific role in the program and all of which can talk to each other in predefined ways."
  

Popular object-oriented programming languages are C++, Smalltalk, Visual Basic, and Java. The concepts which I think most define OOP languages are:
   Encapsulation - including in an object everything it needs, hiding elements that other objects, which communicate with it through public interfaces¹, needn't know about
   Inheritance - creating a new type of object from an existing one, in which the new object (subclass) inherits all the elements from the existing one (superclass)
   Polymorphism - different objects, with their own, unique versions of the same methods, responding to the same message in different ways
This cup of coffee example illustrates these three principles using the interaction between customer, waiter, and kitchen.

¹ "VCRs, watches, cars, and other real-world objects are excellent examples of the kind of objects we wish to emulate, because they successfully hide all the myriad complexities behind really simple interfaces."   -- Sriram Srinivasan, Advanced Perl Programming

 
     OOP links
Object-Oriented Programming Concepts – from The Java Tutorial at Sun
Object-Oriented Programming – from whatis?com
Object-Oriented Programming – from FOLDOC
Object-Oriented Programming Jokes
Object Oriented FAQ
What is Object Oriented Programming?- writer/teacher Elliotte Rusty Harold
Links on OOP – from SUMit, a Dutch company
Object Oriented Concepts – from Sun
The Object-Oriented Page – by Ricardo Devis
Comparing OOP Languages: Java, C++, Object Pascal
Top of page

Alternatives...
  Sometimes it may seem as if it's a Microsoft world where software for IBM-compatible computers is concerned. However, there is alternative software that is quite resilient, and even superior to Windows products. As operating systems go, as I mentioned above, I used to write for OS/2, and I re-booted much less frequently than I do in Windows. My company switched to Windows when IBM moved from OS/2 to Windows 95 as the development environment for VisualAge-RPG. Another operating system, Linux, has a reputation for being very stable, and servers running Linux can operate for months without being re-booted.

I believe strongly in the Open Source concept of programming. At the time I first became interested in learning HTML, there were not that many books on the subject, but I was able to review the code in the browser and see how the various tags performed. You may say that HTML is only an interpreted lanquage, and the source-code must be present in the browser at run-time, but the concept is the same, and I have always been stirred up by those who make postings to web-authoring newsgroups about wanting to hide their JavaScript source-code from others, probably for some selfish, profit-oriented motive. Linux is getting all the press as the current darling of the Open Source movement. However, I still prefer to work in a graphical environment, and even though there are graphical front-ends for Linux, that still smacks of running Windows 3.1 on DOS. Anyway, as I said, I support the concept, and I am proud to be in the brotherhood of programmers that are subscribing to it. I even have a (Copyleft) sticker on the back of my car.

In Java programming I am creating objects that are not fully supported by Microsoft (MS has their own version, which has gotten them into trouble with Sun), but thanks to plug-ins and runtimes by Sun and others these objects can run on a Windows platform. Java is aligned with the Open Source movement and there are some links relating to this on my Java page.

Open Source Initiative (OSI) – an idea whose time has come
Richard Stallman's Personal Page – leader of the free software movement
GNU's Not Unix! – the GNU Project and the Free Software Foundation
Alternative Operating Systems – from Consumer Project on Technology (CPT)
The FreeBSD Project – an advanced free OS from UC Berkeley
Copyleft.netGeek chic!
Slashdot – News for Nerds. Stuff that matters.
The Apache Software Foundation
Perl Mongers – the Perl advocacy people
The Mozilla Organization
     Linux
Red Hat -- Linux, Embedded Linux and Open Source Solutions
IBM Linux Portal
     Linux links
Linux Online
     How to Pronounce "Linux" – audio clip of Linus Torvalds pronouncing the word "Linux"
Linux Journal
Linux Documentation Project
LinuxProgramming.com
Linux Center
Red Hat Linux User's FAQ
LinuxQuestions.org
     OS/2
IBM OS/2 Warp
The OS/2 WWW Homepage – MIT site includes links to many other OS/2 sites
Yahoo! Computers and Internet > Software > Operating Systems > OS/2

Top of page

Visual Basic    VB
  VB was my first experience with GUI programming and a visual-programming IDE.

Microsoft Visual Basic Home
Obi's VB Links
VBRun Drivers
Visual Basic Jobs - Job Listing Service for Visual Basic
VBxtras – other Visual Basic sites on the web
VB Help at DevX
searchVB.com
VBnet – developers resource centre
vbip.com – Visual Basic Internet Programming
VBWire – Visual Basic News & Information Source
Visual Basic Code at VBCode.com

Top of page

Miscellaneous programming and computer links
(see more at Internet & Technology links)
     IBM
iSeries and AS/400: e-servers from IBM, Integrated Application Servers
IBM Corporation
    IBM Search – search IBM's sites
WebSphere MQ (formerly MQSeries)
iSeries NetworkiSeries forums (formerly News400.com)
AS/400 FAQ – uses Faq-O-Matic
MIDGRANGE.COM Mailing List Archive – years of searchable threads
search400.com – the iSeries-specific search engine
    Best iSeries websites
searchDomino.com – the Domino-specific search engine
     Other
MQSeries.net
RocketAware – Programmer's Webliography and Index
Developer.com
Netscape Home Page
Microsoft Homepage

Top of page

Newsgroups
  I used to have all the related usenet groups listed here but they don't seem to function in browsers anymore, so I am just providing links to Google Groups, where they are offered in a web format.
     Windows
comp.os.ms-windows.programmer.*
     Linux
comp.os.linux.*
     Perl
comp.lang.perl.*
     Java
comp.lang.java.*

  There are more programming newsgroups on my pages for JavaScript, Windows, and Online Tips.