Monday, April 16, 2007

Why Encapsulate? – a punch in the head.

When I was first presented with encapsulation and shown an example of its implementation I wondered, “Why? You haven’t really stopped someone from getting to that private data you just added a public method to act as a willing accomplice in the crime.” Then I realized, it’s not about security, it’s about integrity and logical delegation of responsibility.

I shall illustrate…

Imagine we have three fictional people, we’ll call them …oh I don’t know …. Lets call them Raj, Clint, and Andy.

Now let’s say these three are sitting at a bar and Andy wants to punch Raj in the head, and Clint is sitting in between them.

Andy could take hold of Clint’s arm and use it to punch Raj in the head.

This is just silly.

As we can see Andy is not very effective at using Clint’s arm to punch Raj in the head. He could only generate the force of a small girl recovering from the flu.
Andy shouldn’t touch Clint’s arm, he doesn’t know where that arms been.
Its Clint’s arm, wouldn’t it make sense for Clint to throw the punch?

Lets do this a smarter way, lets use….ENCAPSULATION!


Now that’s better! Encapsulation works out better for everyone.

It works out better for Andy, because he doesn’t have to get involved in the process. He wanted Raj punched in the head; uppercut, rabbit punch, short jab it doesn’t matter as long as it happens.

It works out better for Clint, because he doesn’t have to have Andy touching him in inappropriate ways. It’s his arm he knows how to make it punch something.

And it works out better for Raj, because… Ok it doesn’t work out better for Raj but that’s not the point.

The point is encapsulation is good.

Disclaimer: The characters depicted in the above illustration are fictional, any resemblance to actual persons, living or dead, is purely coincidental. The artists involved in this example do not endorse the punching of Raj in the head, or condone violence against Raj in any of its various forms.

Wednesday, April 11, 2007

State of the Course 1.25

I’m half way thru the first semester, second year of my university course (B.Sc. Professional Software Development) at Swinburne University, so I thought I would outline some of my thoughts on the subjects we’re covering.

Disclaimer: Aside from marrying my wife, selecting the PSD program is the best decision I ever made. Any and all critiques must be viewed in this context. Even a giant can benefit from “Standing up straight”.

Subject: Data Structures and Patterns
The pace started off a little frantic, but it’s beginning to find a good rhythm.
The material is solid, could use more comprehensive implementation examples of the patterns.

One thing that has impressed me about the lecturer, you get the feeling he takes care to keep his finger on the pulse of his class. I have him for another class and this same attention towards the overall state of his students is evident there as well. It’s refreshing, it tells me his head is in the game, at times a teacher can seem to be just blindly presenting information with little or no regard for their audience.

Subject: Object Oriented Programming in C++
Having already taken a subject on OOP, with C#, the design principles are familiar ground (This subject was a prerequisite for the games programming subject.). This is presented by the same lecturer as Data Structures and Patterns, and for the most part the academic situation is identical.

With that in mind my focus is primarily on the C++ language. Where C# and Java are so close in syntax and structure, almost annoyingly so, C++ seems to me a different animal altogether. There’s more moving parts here, offering greater complexity and flexibility proportionally. We’ve only scratched the surface so far and I’m looking forward to the challenges ahead. I reckon if I can get proficient at C++ it’s all down hill from there.

There is one technique we’ve been presented that seems powerful but disturbing, overloading the extraction and insertion operators. It gives you a highly adaptable way to present and set attributes of an object. However, when I use it I feel dirty, like I’m bypassing the get and set functions and violating encapsulation, or at least making a mockery of it.

Subject: Software Development Practices
This is a fascinating subject, very interactive and fluid. It primarily presents a technique for designing an application from the context of a client’s narrative. So far the technique seems comprehensive and effective, if slightly unrefined.

Some of the areas of analysis can bleed together; the ambiguity can bog down the process. In the end the finalized assessment does seem to give you a good base of operation from which you can launch your project.

Subject: Data Communications and Security
The actual subject matter is great. The lecturer is very enthusiastic about teaching, knowledgeable, and dedicated to the cause. However, the desire to express the entirety of a subject can sometimes obscure the fundamentals.

As Frederick the Great said “He who defends everything defends nothing”.

Two points:
1. If you find yourself consistently having to “speed up” to try and meet the objectives of a presentation, it may mean that the overall scope is too wide or too deep.

2. This is really subjective and just my personal opinion. A lab session should have a single objective that can be accomplished within the time span of that session (and maybe factor in some time for discussion and reflection). You can have some supplementary objectives for a student to “try at home”, but I honestly think they should walk away from the session having accomplished something.


The Professional Software Development course continues to deliver. I can honestly say I have never once regretted my decision to make it my number one choice. I highly recommend anyone considering their university options for a career in software to put any curriculum toe to toe with the PSD degree program.

The method for teaching software development should reflect the characteristics of software development. Creative, Structured, Challenging, Fun.

Saturday, April 7, 2007

Embarrassing moments in Geekdom - “Oh the redundancy!”

So here’s a little background for the story.

For whatever reason I was under the impression that bubble sort was, in fact, selection sort and was blindly unaware of the existence of selection sort, as a reference.

One night I was lying in bed thinking about sorting algorithms. Alright are you done snickering? Good we can continue. I fell asleep. Around two-thirty in the morning I bolted wide awake, I had an epiphany “Hey what if I wrote a sorting algorithm using a while loop instead of for loops!”

So I did. It worked brilliantly!

Fast forward about a week. I was having a discussion with Daniel, a friend of mine from school. The scenario unfolded something like this.

Me: “Dude I came up with a sorting algorithm, I’m pretty sure it’s faster than bubble sort.”
Daniel: “Really, let’s check it out.”
Me: “Alright cool”
I fire up the laptop and open the file containing my Magnum Opus.
Daniel: “Dude isn’t that bubble sort?”
Me: “No, bubble sort uses the two for loops.”
Daniel: “I’m pretty sure that’s bubble sort.”
Me: “No it's not.”
Accesses wikipedia, loads page outlining bubble sort.
Daniel: “See that’s bubble sort.... At least you thought of it yourself.”
Me: “Just shut up.”

Thursday, April 5, 2007

Azimuth Check

At the time I joined the Infantry the plugger, a GPS system used by the military, was not widely used, if at all. We were taught the archaic and joyous art of Land Navigation, LandNav. You had coordinates, a protractor, map, compass, some rocks for counting, and a pace count, and you were on your merry way.

Now there were several techniques one could use to help ensure accuracy: terrain association, dead reckoning, the box method, etc. However, at several points along the way it was always a good idea to stop, pull out your compass and map, and perform an azimuth check.

An azimuth check is a way to make sure that you are still journeying towards the objective you set out to meet.

Do one once in a while, and like healthy living it’s better if you do it before you have to.