My Blog

contains PHP and other web related content. (Sometimes there are some off topic things - don't freak out!)

Posts Tagged ‘programming’

chaining methods in PHP

Wednesday, November 4th, 2009

I rarely find myself needing to chain methods in PHP – but its not an altogether bad idea. The only caveat that is necessary is that your code must be written in such a way that a method can fail, but other methods can still continue. For example, you couldn’t have one method return false… that would break the chain. You also couldn’t have a method depending on the actions of the previous method to be successful if it is allowed to legitimately fail. There is no intermediate step to check ‘is it valid to continue?’

At any rate, here is my test code that PHP method chaining works great:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class foo
{
    public function bar()
    {
        print 'bar<br />';
        return $this;
    }
 
    public function splat()
    {
        print 'splat!<br />';
        return $this;
    }
 
    public function twin()
    {
        return $this->single();
    }
 
    public function single()
    {
        print 'single<br />';
        return $this;
    }
 
    public function neato()
    {
        print 'neato';
        return $this;
    }
}
 
$ohNo = new foo();
$ohNo->bar()->splat();
$ohNo->twin()->neato();

As expected, the output is:

bar
splat!
single
neato

Each of these methods are pretty self explanatory. The only one that is slightly different is the twin()/single() methods. Note how the twin() method is returning the value of another method directly. The chain remains solid and connected.

Email to SMS/TXT address list

Wednesday, October 28th, 2009

The website http://www.emailtextmessages.com/ keeps a database of most of the email addresses that correlate directly to a txt for mobile phones. However, their version is in HTML – and I see no feed. I’ve compiled the list into a .csv file so that its easier to use in programming. Do visit their website and click on an ad to support their hard work.

download email_to_txt.csv

Multi-Version Programming to Successfully Leverage Overseas Programming

Saturday, September 19th, 2009

Today, I read through the paper titled ‘An Experimental Evaluation of the Assumption of Independence in Multi-Version Programming’ (Find it here).

The basic concept is that in N programs written by N different programmers, they will have N*N bugs and inconsistencies. However, the probability of them having the exact same fault is very small. By executing the same programs at the same time and comparing the output to each other automatically, you can take the majority of exact same output and call that the bug-free result. Those who have not matched the output of everyone else theoretically have a bug.

Now, this got me thinking about people who outsource their technology. Lets say I have a wage of $50 an hour. I make a pretty good program. However, lets say you can hire an outsource programmer for $10 an hour who has average accuracy in their program. You could hire 4 of them, saving yourself $10 an hour, and run those programs together. Compare the output, use the majority of the answers that match, and money is saved.

Now, mind you, I am not a fan of outsourcing at all – but I just thought it would be an interesting idea.

My Progression through Forgot Passwords

Monday, March 2nd, 2009

I thought I’d take some time to look at the 3 main ways that I’ve handled forgotten passwords on my websites, why I did them that way, and if there was anything wrong.

Disclaimer: there is a lot of bad code in here – and thats on purpose! This is a historical piece… :)

The n00b Times: send the password back to them

The very first ‘forgot password’ attempt I made was a long time ago on a website about computer security. This was really quite funny because this was the least secure way to do it. Users would request their password, and I’d send them their password, in clear text, to their email. Not very secure! Side note: this means I had to be able to decrypt their passwords to send it back to them – and newbie me actually skipped that step – just a plain varchar of their password. OOPS.

The non-scalable times: hash the time away

The next step in my programming mutuation was at least more secure: send the hash through email and let them reset their password. This way, I never send their password through the email – and never actually stored it in a decrypt-able (is that a word?) state. Of course, I did it wrong again:

Um, don’t do this:

1
2
mysql_query("Insert into resets (userID, key) values($userID, '" . md5(time()) . "');
mail($to, 'Password reset', "Please click this link to reset your pass: http://website.com/resetpass.php?key=" . md5(time()));

You DO see all the problems, right?

The biggest one is that if two users were creating a forgot-password request at the same time, they both would get the same ID – and you could end up resetting someone else’s password and gaining access to their account.

Of course, the next issue was that it was pretty easy to guess a password reset key for someone if you saw when they did it.

Then, I didn’t store the key – so theoretically, the first line could be a different time than the url that was sent to the user – especially if there was a high sql load!

Better Hash – not based out of Amsterdam

The next thing I realized was that I had to make this hash a bit more unique, so I ended up adding the userID to the time as a prefix… (should also point out that one time I also went with generating a hash based off of their userID and then sending a timestamp as a separate parameter… its relatively the same thing as this example)

still not good enough!

1
2
3
4
$time = time();
$key = md5("{$userID}{$time}");
mysql_query("Insert into resets (userID, key) values($userID, '$key');
mail($to, 'Password reset', "Please click this link to reset your pass: http://website.com/resetpass.php?key=$key");

At least I fixed the key – um – sorta. However, if you knew the user id – you could at least make a better educated guess at this hash – especially if you knew the time was. Point being, it was a step up, but not my final resting place.

Break: Some of you might wonder why I didn’t just use a uniqid() and md5 that… well… yah… but we all make mistakes when we first start out right? ;) Just trying to help out any new programmers not to make the same mistakes

What are you doing now?

Ok – so for something thats pretty secure like that, I wanted to have a very long, extremely random string. I thought of sending mt_rand()’s next to each other and hexadecimalling them – or md5ing them. But I settled on something hopefully with even more of a chance not to be guessed: base64 encoding.

What?

Well, let me show you.

1
2
3
4
5
$forEncode = '';
for ($i=0; $i<300; $i++) {
	$forEncode .= chr(rand(1,255));
}
$key = strtr(base64_encode($forEncode), '+/=', '-_.');

Granted, I left out the mailing and mysql storage, but you get the idea. Real quick, a run-down:

First, start out wiht my blank string. I plan to generate 300 random characters – so I create that for loop. Then, I choose a random number between 1 and 255, corresponding to the ASCII table, and generate the chr() value of it. Then that is added to my string. I now have a string that has 300 characters of any character from 1 to 255 on the ascii chart. Finally, I base64 encode it – and then replace the items in it that are not good to have in an URL.

How do YOU do it?

Please Use Public Accessors in your Object Oriented Programming

Wednesday, February 4th, 2009

I really hate to see people accessing and designing objects with public attributes. So many times I’ve seen this backfire. Lets take a few examples and see why this matters:

(more…)

Understanding the Observer Pattern in PHP

Monday, November 17th, 2008

For a while, I’ve been looking at plugin systems, but not really fully understanding the pattern behind them. Don’t get me wrong, I see how they work, but I didn’t know the reason why – the theory or pattern behind it. Well turns out, generally, they’re based upon the observer pattern. I decided to write my own observer pattern demonstration here.

Our example is going to be very simple: post a message to twitter. We’re not going to work with any credentials or anything, just want to post a message. I do want to add an observer that will shorten any url however. In this example, we’ll be making the logic classes stubs (you can create these later), and using ‘[url]‘ to stand for an URL we might replace.

Lets start in:

Our two logic classes

Remember, we’re just going to have some blank stub logic classes here. They are for demonstration purposes only.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class twitterTransport
{
    public function __construct()
    { /** logic here **/ }
 
    public function tweet($object)
    { /** logic here **/ print $object->message . ' was just tweeted'; }
}
 
class urlShortener
{
    public function shorten($message)
    {
        return str_replace('[url]', '[u]', $message);
    }
}

Pretty simple, the first class all it does is post to twitter with a public method called tweet(). This accepts an object of the twitter message (which we’ll list next!). It prints out the message so you know what we would have sent to twitter. The url shortening class – all it is is your logic to shorten urls inside of a message. In this case, pretty simple.

Ok – as promised, here is our twitter message class:

1
2
3
4
5
6
7
8
9
class twitterMessage
{
    public $message = '';
 
    public function __construct($message)
    {
        $this->message = $message;
    }
}

The actual launching code

We’re going to jump a head here and show what code we’ll be using to add the url shorterner as well as post the message. It’s really short – but it’ll give us an idea of what class we need to create next:

1
2
3
4
$tweeter = new twitterTransportObservable();
$tweeter->registerObserver('PREPOST', new urlShortenerObserver());
$message = new twitterMessage("this is my message [url]");
$tweeter->postMessage($message);

Ok good. First off, we create a new instance of twitterTransportObservable. By the keyword Observable, we can tell that this class is something that will “do something we can watch” or observe. Any time a class is Observable, it has to have a method to add watchers to itself – or registerObserver(). In our example, we’re sending in a type – “PREPOST” – so before we post the message, and a new object.

The new object is of type urlShortenerObserver(). We can see that this will be a ‘watcher’ by the name. No more details are given here, so its methods must be used/exposed inside of the Observable class.

Next, we’re just making a new twitter message object, pretty simple.

Finally, we’re calling postMessage() sending in our twitter message. Remember, $tweeter is an instance of twitterTransportObservable, so there must be a method called twitterTransportObservable::postMessage().

So far so good.

Looking at the Observable Class

So now we know we need to build twitterTransportObservable. I’m going to post the code here, but don’t worry, we’ll take it apart, step by step:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class twitterTransportObservable
{
    protected $_observers = array();
 
    public function registerObserver($type, $observer)
    {
        if (!isset($this->_observers[$type])) $this->_observers[$type] = array();
        $this->_observers[$type][] = $observer;
    }
 
    public function postMessage($object)
    {
        $this->_notify('PREPOST', $object);
 
        $sender = new twitterTransport();
        $sender->tweet($object);
 
        $this->_notify('POSTED', $sender);
    }
 
    protected function _notify($type, $object)
    {
        if (isset($this->_observers[$type])) {
            foreach ($this->_observers[$type] as $observer) {
                $observer->notify($object);
            }
        }
    }
}

Ok – pretty big – lets go slow:

First off, we have the $_observers. Since this class is of type observable, we know it has watchers. Well, it has to be aware of its watchers, because it registers them… so we need an array to hold all of our watchers, or $_observers.

The first method is registerObserver(). You’ll see this takes in a variable called $type and a variable called $object. Well, we saw this used in our launching code. It appears that this was started with ‘PREPOST’ as the $type and a new urlShortenerObserver as the $object. Moving along, the $_observers array is keyed by $type – so we just did some good programming: if the key is not set, set it by creating an empty array. Finally, the next line grabs that array, and adds the passed in $object to the internal array of $_observers. So now, our observable class has its first observer. An important thing to note is that the order you add them using registerObserver(), is the order they will remain in the array in the Observable class.

Quick reminder: Remember, objects are passed by reference!

Next, we have the postMessage() function – which takes in an object of a twitter message. The first thing the function does is notify our self that we’re PREPOST, while passing in the $object to that notify call. Think of this as the ‘hook’ – or someone yelling at the watchers saying “Anyone of type PREPOST, I’ve got this $object for you to deal with!”. Next, this function creates a new twitterTransport and tweets the object. Remember, the $object has now returned from the notify call and may be changed. Finally, there is another call to _notify with “POSTED” as the type. This is just for example, our example doesn’t really need this. But, imagine you created an observer which logged the output of twitter’s response to your post? This would be perfect for that hook.

Ok, so the last thing we have to look at is the _notify() function – which we’ve called a few times during our postMessage(). This simply looks to see if there is an observer that we’ve been storing locally keyed on the $type key. If there is a key of this $type, we loop through each observer of that $type, and pass in our object to its notify() function. OK – don’t get confused, that notify() function is different than our _notify() function. It belongs to the observer (in our example, urlShortenerObserver::notify()). So basically, it calls all the observer’s notify() with a reference to the object, and its done.

Whew, that was a lot – but we have one more part left:

The Observer class

We have another class that is used to observe or watch the observable classes. In this case, we wanted to have any URLs shortened before we posted a message to twitter… so we registered this observer with PREPOST. During the Observable’s _notify() function, we called this observerable class’s notify() method. So, lets finally take a look at the code:

1
2
3
4
5
6
7
8
class urlShortenerObserver
{
    public function notify($object)
    {
        $urlShortener = new urlShortener();
        $object->message = $urlShortener->shorten($object->message);
    }
}

Pretty simple class. It has only one method, called notify() which accepts an object – of type twitterMessage. The first line just creates a new urlShortener() – you remember from way up top? Just a quick str_replace type method. Then, the next line accesses the urlShortender::shorten() method – by passing in the public $message variable of the twitterMessage. The return value is assigned to the twitterMessage::$message var. And remember, since objects are passed by reference, when the next line of the the observable’s class is called, the object will now be modified.

Wrapping Up

Ok – well this was a pretty simple example of this behavior. There are definitely more complex ways and more business logic intense scenarios to use the observer in. Another thing we didn’t do is use many of PHP’s OO properties – but we could always refactor and do that in the future.

All the code

In case you want to run it yourself:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class twitterTransport
{
    public function __construct()
    { /** logic here **/ }
 
    public function tweet($object)
    { /** logic here **/ print $object->message . ' was just tweeted'; }
}
 
class urlShortener
{
    public function shorten($message)
    {
        return str_replace('[url]', '[u]', $message);
    }
}
 
 
class twitterMessage
{
    public $message = '';
 
    public function __construct($message)
    {
        $this->message = $message;
    }
}
 
class urlShortenerObserver
{
    public function notify($object)
    {
        $urlShortener = new urlShortener();
        $object->message = $urlShortener->shorten($object->message);
    }
}
 
class twitterTransportObservable
{
    protected $_observers = array();
 
    public function registerObserver($type, $observer)
    {
        if (!isset($this->_observers[$type])) $this->_observers[$type] = array();
        $this->_observers[$type][] = $observer;
    }
 
    public function postMessage($object)
    {
        $this->_notify('PREPOST', $object);
 
        $sender = new twitterTransport();
        $sender->tweet($object);
 
        $this->_notify('POSTED', $sender);
    }
 
    protected function _notify($type, $object)
    {
        if (isset($this->_observers[$type])) {
            foreach ($this->_observers[$type] as $observer) {
                $observer->notify($object);
            }
        }
    }
}
 
$tweeter = new twitterTransportObservable();
$tweeter->registerObserver('PREPOST', new urlShortenerObserver());
$message = new twitterMessage("this is my message [url]");
$tweeter->postMessage($message);

Why your company needs a System Architect/Analyst

Wednesday, September 10th, 2008

In this post, I’m going to cover what a System Architect/Analyst (SA from now on) is and why you need one.

A System Architect/Analyst is…

A top level programmer with a lot of experience.
Experience is king here. No matter how many theoretical classes or book knowledge, experience can trump all of those. It is just impossible to run into as many situations in the class room as in the real world. This person should be continually updating their knowledge of programming concepts as well as …

Still keeps hands in the code.
A common problem with the SA’s I’ve seen is that their programming time continually declines until there is no more hands on involvement from them. It is still important for an SA to keep their hands in the code, whether it is making quick bug fixes, creating complex algorithms or, at the very least, making shells of classes and methods.

Understands advanced architecture concepts and can implement if need be.
While the current project or code base may not necessarily be in the place where advanced concepts can be applied, the SA should still understand these concepts and be able to apply them in other projects. This helps cement the fact that this individual will be the first person that is consulted on a rewrite… which means…

Knows where the code base is going.
Code bases, for the most part, are more of a living/moving entity than a stable patch based system. There is always a need to add more features while refactoring. The SA should know about where the code is going in order to give design guidance to make the new features partially on the road to the refactored code or a rewrite.

Understands where the company is going
It is important for the SA to understand some of the company’s strategic plans for future development and planning. This way they can make design suggestions about existing projects’ architecture to afford for easy upgrading to the future planned additions. This familiarity is accomplished by working somewhat with the management team or decision makers as well as the project managers.

Why You Need One

Heads off problems ahead of time.
When you have an SA in the mix, a good portion of their time is dedicated to analyzing and thinking about the current projects. Having a good knowledge of all of these projects helps them foresee any projects and take care of them ahead of time. Additionally, with all of this knowledge, they can help make educated decisions without having to bother the stakeholders. A lot of times, however, stakeholders will suggest throwing an SA into the mix for the wrong reasons – to code faster, to push out product quicker, etc. This is never a good idea. Once you pull them away from looking at the big picture, its almost as if you don’t have one – or sometimes even in a worse place than before.

Makes recommendations on how teams can accomplish work.
I’ve covered this before, but it bears repeating. While not actually accomplishing a lot of work themselves, they do get involved in many of the projects and give guidance to the team and team leaders on how to best work in the current constraints as well as plan for the future.

Authority from a technical aspect on how code is finished, peer reviewed.
When teams are having some issues solving something or a peer review doesn’t go right, the SA would be the authority on what is the solution. For example, if one peer reviewer says the code isn’t right but the other feels like it is, the SA, from their experience and other understanding, will resolve that issue immediately.

Analysis first saves work later.
Time and time again, analysis is cut short because there are not enough resources to work on the projects as well as analyze the stuff. Well, just off the bat, if you’re suffering from this problem, it sounds like you’re not putting a lot of emphasis on the analysis – or not learning from mistakes. I can’t point to ANY example where analysis first was the ‘failure’ of the project – but I can name a million where it could have helped or did help (search “software” on google for a million examples). Point being, this SA’s primary responsibility is analyzing past, existing, and future code and ideas. This is an important part of any project’s success. Just like every other skill, with practice, this becomes better. It is important to dedicate a person to this task so they can continue to become better at the analysis as well as protect from any project design misses.

Reduces work for managers.
Since the SA knows both the future plans of the business as well as has an eye for the technical solutions, they can jump in and resolve a lot of questions before they have to get queued against a manager. This is not to say that an SA should be at all responsible for personnel issues or anything – but they can help make snap decisions with the notion of what is best for the company and the architecture.

Do you agree?

I’d love to see any comments talking about if you agree with this summary/description, if you’ve recently acquired an SA and any positive or negatives you’ve seen, or if you have other things I missed. Thanks!

What I believe MVC is – or MVCFDH

Thursday, August 28th, 2008

There are many interpretations of MVC – there are less definitions but more implementations. I want to cover what I personally do when using PHP for MVC. I call it MVCFDH.


What is MVC?

A real quick definition of MVC for those who are not familiar. MVC is a design pattern that consists of separating the logic, action and display from each other. The three parts of this are Model, View, and Controller. The Model contains the logic and business content, the View contains the way of displaying that content, and the Controller interprets the actions being requested by the user to glue the Model’s usage to the View. Theoretically, you should be able to swap out any one of the components with another of the same interface – and function flawlessly. A common example of this is using multiple views – 1 for HTML on the screen, 1 for WAP devices, 1 for web services, etc. Now, if you’re not familiar beyond this quick refresher, I recommend doing more research on the web.

What do I use? Why MVCFDH of course!

After many implementations in PHP, I’ve discovered that the general simplistic example of MVC didn’t work exactly as I would want. There was still so much over lap, confusion on how certain functionality should act, etc. I added two more components called F and D. This means, I have Model View Controller Frontcontroller Dataobject Helper. Let me detail each one of these:

Steering Wheel or… Front Controller

The front controller intercepts the first request to the code. This may be a web page URL with parameters for a surfer or a request to a web service for data exchange. Either way, every single request comes through this first controller. (Practically implemented, this is usually the index.php file in the base directory for the web server with some apache rewrite rules in most examples.) This front controller is responsible for knowing how to locate every single other file in the system. It also stores some global knowledge about the request for later usage – such as the request time, the method of request (browser, xml request, etc). It doesn’t do any processing necessarily on this information – it just makes the information available. Finally, it methodically can interpret from the request what type of controller to request – and passes execution to said controller. I’ve seen people use various types of garbage collection or logging in these front controllers. I don’t know exactly if that fits or not. The most important thing is to make it quick and clean – this is just the front door of the house.

Mr. Bossy TakesAction JR, or … Controller

Each specific requested action has a controller. This controller handles that request, and uses some of the information freely available from the front controller – to determine what model to include / invoke. The controller is basically just a bootstrap for validating that the request type is a valid request – ie – something that CAN be done – and then determines what WAY to implement the requested feature based off of request type. For example, you may prepare data differently for a web page than you will for a PDF file. A common misconception is that this is referring to different models with the potential for code duplication. Instead, this is referring to specific portions of the same model that it has determined. (Practically, your code might know the request was for a PDF of the sales details, so it calls the model function getForPDF() which in turn calls a private method generateSalesDetails(). A request for the same items for a web page might call getForHTML()). The controller calls the proper models and then is responsible for applying the returned content to the view.

This is why I’m hot… or… Model

The model is where I move away from many ways of implementing the traditional MVC pattern. The model should have generic functions to perform whatever business logic is required as well as more specific functions to cater to any type of request that the controller may make. Finally, it is responsible for applying the Dataobjects – waking them up – and knowing how to extract data from them. The model always returns data to the controller.

Stop treating me like a piece of meat… or… the Dataobject

The data object is a very precise object that connects to an entity of content. Only the model directly ever works with this. It makes sense to have all Dataobjects have the same interfaces for the models to use. Additionally, they should be built in a way that allows them to couple efficiently with each other. Resist taking short cuts and putting common business logic in these objects. (For example, if your business always uses a ‘fullname’ you may want to make a function for your data object that returns full name by combining the first and last. Do NOT do this. You never know – maybe the next usage of this will require the fullname to be first, MI, and last.) Data objects may use various ways of acquiring their data. In theory, they should be transparent enough for you to swap out a mysql database and use an xml data store – and no one would know the difference.

Ladies Gossiping – … or… The View

I find that the biggest hurdle for new users of MVC is the view. Understanding that there can be code that displays data while not performing any manipulation is usually hard to comprehend. Or knowing that logic can happen in the model – but it can’t ever output its final result. This comes from PHP’s embedding features – so its not a surprise to see this. The view contains the general markup to display the content that the controller received back. The controller invokes the proper view for the data – which is to say the proper view for the current request type and action type. Basically – any sort of HTML, CSS and JS will be in your view. Two common questions: what about separating CSS from HTML – and what about Automated JS generation from Helpers or Models. First of all, CSS/JS separation from your markup is a must – and indeed another topic entirely – but suffice to say the view is your implementation of proper client side design and development with content being pumped into it afterward. Follow all of the rules that you know to be good practice when adding your CSS and JS. Second – JS that is generated and how to import that is generally a very long conversation. Just follow the directions of your library you are using. I’ve seen examples as easy as just injecting it mid HTML to generating an include .js file that contains JS for only the current request. That is not the focus of this article.

Jared’s got aids… or Helpers

I would be remiss if I didn’t talk about those little bits of code that you just can’t live without – and that MUST be brought out into something else in order to eliminate code duplication. Helpers refer to those small bits of code that help us perform needed tasks – such as connecting to a database, generating repetitive HTML code – like forms, retrieve configuration options, etc. These are a necessary evil – and are usually held outside of your main application tree – but still part of the project. These should never contain any business logic or generate any output.

Wowzies – thats quite a lot

Granted, setting up your first MVCFDH project can be daunting – there is so much to know, so much not to forget, and more so to actually code. However, as with all good things in life, it usually takes a bit of work. From experience, I can say that this has worked the best for ME. My project has survived multiple versions of browsers, now two distinct request types, and 4 php upgrades (3 of which started using the MVCFDH).

Also…

That name – MVCFDH – is too hard to say. Major props to Billy.brokeit for asking me some questions at #superdev the other day about what I thought about MVC. Such inspiration ;)

Eclipse Testing with TPTP – help me?

Monday, December 10th, 2007

I recently came across this tutorial here about Testing with TPTP- and I’m confused. Whats the benefit of this type of testing (um… creating JAVA code for a JUnit test… right?) compared to running some PHPUnit, Selenium and AB (from apache, or something…)? What am I missing – does anyone have any other good hands-on tutorials?

5 Things this PHP programmer learned from System-i/as400 programmers

Sunday, December 9th, 2007

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.

  • twitter loader

Follow me on twitter: @aaronsaray

The views on this website are my own and do not reflect the opinions of my employer or clients.
Creative Commons License Home | Open Source | Book | Music | Art | Bio | Resume | Contact
My Baby