5 Things this PHP programmer learned from System-i/as400 programmers
December 9th, 2007 by Aaron
Working in a shop that has approximately 15 times more System-I as/400 iSeries (whatever you want to call it) programmers, I’ve been immersed into their culture, standards and mindset.
As you can imagine, as a fresh new programmer for emerging web technologies, there was some struggle between me and the analysts for this older language. However, as I stepped back and actually looked at their directions, suggestions and practice, I found 5 things that I actually should integrate into my methodology.
1. Make necessary text settings dynamic using databases
Generally, these programmers have progressed through their career under highly strict and audit-able programming and promoting to production environments. Because of that, they tend to leave a lot of the actual text in their applications separate from their programming logic. This allows them to get their application out in production, and then just change the data in the databases (or files as they call them. Also in our environment, changing data is a lot easier than changing programming).
PHP programmers should be used to this as well when creating multi language applications. I learned that this could be useful in situations where I only have one language - especially when working with business users who aren’t fully set on their wording until after the application hits production. (Just recently, I changed 3 help texts for an application at work - and it took me about 3 minutes of database manipulation - rather than an hour of checking out code, modifying it, repromoting it, etc.)
2. Add additional logic situation by creating database driven action rules
For whatever reason, you might find yourself wanting to introduce different language for different partners (in our case states). Previously, we had created state switch statements in shared code to determine what to do for any particular state. However, this means that I had to keep the code up to date in areas where it wasn’t explicitly shared with code that referenced specific states. If we added a new state ever, we’d have to go and modify everyone’s code again.
The system-i programmers had been creating rules for these type of situation. Basically a rule is a numeric record with a state or environment specifier and then a yes/no value. Then, they would intelligently program their logic around these rules. The environment or state where the rule was being retrieved from had the proper value for that state. For example, if I were getting rule 114 from WI.t_rules it might be 1. Rule 114 from IA.t_rules would have a 0. This also adds flexibility for environments who made a decision to do it one way, but now want to do it another way.
3. Separate your logic into smaller objects and keep your display separate
System-I programmers can make display files which is basically a type of interface to show data. Also, they are moving to more and more of a modularized system - which is something I’ve always wanted to do (using MVC pattern). They are introducing more service programs who’s only duty is to take a parameter and do a quick specific calculation and return them. This was a cool reiteration of a programming concept that I already knew. Their service programs are very similar to web services - which is encouraging me to keep thinking of making more and more service oriented architecture.
4. Validate your data
Although this is an obvious thing - and this is something I shouldn’t have had to re-learn, you do end up getting lazy when you’re programming for your own projects all the time. When you send stuff to the System-i, say like a date field, and it is incorrect format, it will cause their program to hang (that is to say, halt and hold crash information in memory for someone to analyze). Because of this, my connection is blocking - and my page freezes too (this could be solved with a proper time-out - but we’re not covering that here.) When a program hangs, a page is generated to the system-i programmer on call. You can imagine that they’re really irritated if its in the middle of the night.
At any rate, PHP has let me become a little bit lazy. If I send an invalid date format to a function, it’ll just error - but most often continue to run. This was a good experience for me to have - I’m far more diligent about error checking my data before it even leaves my script.
5. Not everyone is a programmer / I take stack programmers for granted
This one is kind of a double point. Its amazing to me that their are two types of workers on the system-i side: the system analysts and the programmers. SA’s are responsible for quoting, designing and generally architecting the project requests that come through. The programmers take those specifications and make them reality. This is a little bit different for me as I’ve always just been in charge from start to finish. I still pretty much am right now in this organization - I do get assisted by the SA’s when the project is very cross platform, however.
The other thing that caused me some surprise is that the programmers and analysts don’t know the intricate details about their stack - that is the whole environment and programming box their using. They have an administrator who is a lot more familiar with the environment. This is kind of different for a LAMP programmer - I originally looked down on them for that - but then I realized it was positive for two reasons: It had security and it tried to separate duty and responsibility to allow more specialization.
These two things - after I realized they even existed - helped me communicate with my peers in the system-i programming side a lot better, effecient and more accurate.
So, although I like to give some of the more fun system-i programmers a hard time about programming on an old archaic language and that they can’t handle us young hotshots, there is a lot to gather from these experienced programmers.
APD post processing wrapper
November 17th, 2007 by Aaron
A while ago, I discovered the ‘joys’ of APD… and then moreso, the ‘joys’ of not being able to make heads or tails out of the output script. After digging deeper, I saw that the original directory already had some PHP scripts to parse the output. I ran those and wasn’t very impressed. Even more important, my boss wouldn’t be impressed. I needed to be able to make something that could be useful to integrate into a table (I finally used dojo to create a table…)
At any rate, I thought I might save anyone some time by posting the code here:
Continue reading APD post processing wrapper
MySpace bulletins to RSS
September 27th, 2007 by Aaron
So I’m sick of myspace… or so I say to myself. So now I log in about half the time as I did before… and this is because I’ve made the following script. It logs in and grabs each bulletin from your top bulletins. Then, it creates an RSS feed from them.
Lets check it out:
Continue reading MySpace bulletins to RSS
Create Google Advanced Search String
September 25th, 2007 by Aaron
I found an interesting article about the parameters of the advanced search URL for google. Just for fun, I tested out their concepts and they were all true. I figured maybe there was a reason to do this as a PHP class (I think I was just bored…).
You can find the code here:
Continue reading Create Google Advanced Search String
Create an RSS feed of comments from myspace
September 8th, 2007 by Aaron
Lately, I’ve been trying to find ways to reduce the amount of time I spend on stupid sites like myspace (nevermind the fact that the time it took to reduce this amount took me enough time to visit myspace 1x a day for another month - heh). At any rate, I’ve been using Google Reader alot more (I’m up to 180 or so feeds) and I thought: Why don’t I make an RSS feed o my comments - then I don’t have to go back to the site when someone sends me a comment. (Mind you, myspace does send you an e-mail when you receive a comment, but doesn’t include the content. JEMDiary does, however ;)) I searched the internet and found a few sites that are doing that for a service, and one guy who was giving away a regular expression. So, I took his idea and wrote my own php script for cron. Check it out here:
Continue reading Create an RSS feed of comments from myspace
Pass PHP session to a new script using fsockopen
September 6th, 2007 by Aaron
I was working on a script that opened up a new connection to the same server with fsockopen to process a php script. It passed the variables needed through GET and then gathered the output. Finally, it displayed the output on the screen under the current context.
I ran into an issue where now I needed to set a session variable in my calling script, but make the same session information available to the called script (the called script starts its own session too).
This is how I did it:
Continue reading Pass PHP session to a new script using fsockopen
ODBC for UDB and PHP - How I increased performance by 400%
August 2nd, 2007 by Aaron
In our current setup at (”the triangle”), we have to use odbc connections to access our db2-udb database - and I don’t like it. But we have to stick with it - and thats the way life is. The main reason I don’t like it is the immense overhead and time it takes to execute queries. Well, I did some research and found out some interesting things. The most important of which was a cursor setting that allowed me to gain up to 400% performance. Find out how:
Continue reading ODBC for UDB and PHP - How I increased performance by 400%
Is it better to write your ‘for’ loops backwards in PHP?
July 27th, 2007 by Aaron
After listening to a javascript internals optimization talk, I wanted to see how these concepts could relate to PHP. The biggest thing that stuck out to me was the order of the for loops in javascript. According to the talk, loops written backwards (or using the deincrement operator instead of the increment one…) was a lot faster. They said comparing a value to zero was faster than comparing a value to another value. With the backward loop, you were always comparing to zero. I decided to try these tests on php:
Continue reading Is it better to write your ‘for’ loops backwards in PHP?
The Perils of the AT in PHP
July 27th, 2007 by Aaron
A lot of weird things have been happening ever since we introduced a new error handler at (”the triangle”). First of all, it took down our whole site for a good portion of time (oops!), then it created a large project for us to review our code. Turns out a lot of the errors were just weird little things that we ignored. However, there were a few times where the @ operator (http://us3.php.net/manual/en/language.operators.errorcontrol.php) was a huge problem. I, for once, don’t think that the @ operator should ever be used again. Let me detail out what it does and why I don’t think we should use it:
Continue reading The Perils of the AT in PHP
How to use PHP to generate downloadable content
July 22nd, 2007 by Aaron
I was looking at some code I had written about 3 years ago - how sad! I was creating a PDF of my resume using PHP to grab my qualifications out of a database. Unfortunately, I never researched into the header php command, so I made my job harder. Instead of writing it with a php file, I made a php file, and renamed it as a .pdf file. I modified my .htaccess file to process that one particular file as a php script. This way, the file executed as php but was mime/typed as the pdf.
Instead, I should have done it the smart way - with the proper use of the header command.
1 2 | header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="filename.pdf"'); |
Of course, check out and read the entire header manual page for more.
