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 |
| 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 the first place Partnership Award from Beyond Computing Magazine, honoring Safety for the strategic alliance of technology with its business objectives and for development of internal software. 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 since the early 80s in a variety of languages, depending on the job and platform. For the last several years I have been developing web-based server applications in Perl, and as you can see from my website, I also do a lot with HTML, JavaScript, and a bit of Java. The following quote is from a Perl book but it applies to all languages.
I strongly stress the importance of making your code readable by others. In some languages (HTML and Perl are a couple of examples) you could theoretically write your code in a single line, but this makes it difficult to decipher the logic when your code is being worked with. I use Textpad as my editor and I have my tab key set to 2 columns. I always make my opening and closing tags and logic blocks line up vertically. You can see this in any code examples I provide on my website. Just spending a little extra time to do this when creating code can save a tremendous amount of time for anybody (including yourself) who modifies it later. |
| 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Read a cookie use CGI; my $q = new CGI; my $cookie_value = $q->cookie('cookie_name');
# Write a cookie use CGI; my $q = new CGI; my $cookie = $q->cookie(-name=>'cookie_name', -value=>'cookie_value', -expires=>"+1d"); print header(-cookie=>$cookie);
I wrote one multi-screen Perl application that was going to be linked from an unknown webpage, and I wanted to have an
Exit button on the first screen that would return to the referring webpage. The environment variable 'HTTP_REFERER' holds
the URL of the previous webpage, but if you were returning from a screen within the application it would point to that page.
To make sure this button would always exit the application I saved the original referer value in a cookie to be
retrieved on returns to the first screen.
![]()
Here is how I did this.
use CGI; my $q = new CGI; my $header_printed = ''; # Check for existing cookie containing referer URL my $exit_link = $q->cookie('application_name'); if (!$exit_link) { # If first visit to page create cookie with no expiration date to expire at session end $exit_link = $ENV{'HTTP_REFERER'}; my $cookie = $q->cookie(-name=>'application_name', -value=>$exit_link); print header(-cookie=>$cookie); $header_printed = 'y'; } if (!$header_printed) { print $q->header(); } # (this is an abbreviated version of the print method, without escaped quotes) print "<a href="$exit_link"><img src="images/btn_exit.gif" title="Exit" width="120" height="20" border="0"></a>";
# Load an array with the names of the files my @dir_contents = ''; my $work_dir = "directory-including-relative-path"; opendir(DIR,$work_dir) || die("Cannot open directory $work_dir!\n"); @dir_contents = sort readdir(DIR); closedir(DIR); # Make a list of the name of each file from the array my $files = ''; foreach $filename (@dir_contents) { # Replace certain characters with entities for html display $display_name =~ s/&/&/g; $display_name =~ s/\//⁄/g; # Get the file size my @stats = stat($work_dir.'/'.$file); my $filesize = int($stats[7]/1000).'kb'; # Add the file name and size to the list to be printed $files = "$files$display_name - $filesize<br>"; }
# Set up the user-agent use LWP::UserAgent; my $ua = LWP::UserAgent->new; # Check the link my $link_url = "http://www..."; my $response = $ua->get($link_url); if $response->is_success { # Link is OK ... } else { # Check specific codes on bad link my $rc = substr($server_response,0,3); if ($rc eq '400') { # Bad Request ... } elseif ($rc eq '401') { # Unauthorized ... } elseif ($rc eq '403') { # Forbidden (love the sound of that) ... } elseif ($rc eq '404') { # Not Found ... } }
| 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.
|
|
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.
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.
|
|
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.
Here are 3 of my macros.
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 |
|
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. |
| 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.
Popular object-oriented programming languages are C++, Smalltalk, Visual Basic, and
Java. The concepts which I think most define OOP languages are:
| |||||||||||||||||||||||
| OOP links |
|
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. We have Linux on our servers at work, and my website runs on
a Linus server, so I have to understand the basics of the language (particularly using permissions and being aware of it being
case-sensitive). I still use Windows on my PC at work and I use the TortoiseCVS
version control to integrate the Linux servers to Windows Explorer.
I believe strongly in the Open Source concept of programming. In the early 90s, when 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 put a When I was writing Java applets I was 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.net – Geek chic!![]()
Slashdot – News for Nerds. Stuff that matters.
The Apache Software Foundation
Perl Mongers – the Perl advocacy people
The Mozilla Organization
| Linux |
| OS/2 (I guess this is a little dated now) |
| Visual Basic | VB |
| VB was my first experience with GUI programming and a visual-programming IDE. |
Miscellaneous programming and computer links
(see more at Internet & Technology links)
| IBM |
| Other |
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 |
| Linux |
| Perl |
| Java |
There are more programming newsgroups on my pages for JavaScript, Windows, and Online Tips.