Pages

Showing posts with label software engineering. Show all posts
Showing posts with label software engineering. Show all posts

July 14, 2009

Breaking the Law...

Today I read a great post by Phil Haack on the Law of Demeter. I think I had read about it before, but it never sunk in until today. As I read it I had that uneasy feeling you get when you realize you have been unknowingly doing something you are not supposed to do.

The Law of Demeter is pretty simple:
A method of an object should invoke only the methods of the following kinds of objects:
1. itself
2. its parameters
3. any objects it creates/instantiates
4. its direct component objects
Essentially it means that in languages like Java you should not chain together method calls using the dot operator. A great example of this is detailed in the paper, The Paperboy, The Wallet,
and The Law Of Demeter by David Bock
. Bock goes through a perfect illustration of why the Law of Demeter should be followed, with an emphasis on scenarios where not using it can cause null pointer exceptions. Sadly, this is the exact case I ran into recently that would have been avoided if I had followed the law.

I had a client interface that needed to get information contained in an object returned from a different method. The needed information was always to be in the first item in a collection, so I immediately used dot operator chaining to get the iterator for the collection and then the first item in the collection.
Item i = (Item)object.methodReturningCollection().iterator().next();


Looking at that code now I see how naive I was being when I wrote it. I never thought of the scenario where the initially called method would return as null . Of course this was caught in testing, but was fixed by simply using a temporary variable and testing for null. This fixes the problem with the null object, but still goes against the law. What I should have done was to create a method in the called object that returned the information I was trying to obtain in the client code. Then the client would not need to know how to retrieve the information as it should be the responsibility of the called object.

I consider myself a fairly decent developer, but you learn something new everyday. I will now be looking out for this when I am doing refactoring. It's amazing to me how much software development is an ongoing learning experience. I love every minute of it...

September 25, 2008

How Did I Get Started In Software Development?

I am following the lead of many other software development blogs and answering the following survey questions that have been floating from blog to blog for a while now. Here we go...


How old were you when you started programming?
I think the first time I remember writing a program was in the 6th grade. I took a class where we did some programming in BASIC, but I didn't get hard core into programming until I was 18 in college. So I guess you could say I got a late start.

How did you get started in programming?
Going into college I thought I would give the Computer Science and Engineering department a try. I was intrigued at the thought of writing software so I took a leap of faith and it worked out for me.

What was your first language?
My first language was C. I learned it in my introductory programming course at University of Texas -Arlington. I think I just showed my youth there...

What was the first real program you wrote?
Hmm... I wrote many small Hello World programs as I learned C and C++, but the first meaningful program I ever wrote was in my second year of college. I had to write a program that was a discrete event simulation of the checkout process at a local Costco. I had to model the entire process and help determine the ideal number of checkout lines that should be open during peak hours. That was the first time I got the light bulb moment in my head and thought I might be pretty good at this.

*Side note* Obviously my results were never passed on to Costco or any other wholesale store as the lines are always so unbearable...

What languages have you used since you started programming?
Wow, I've used C, C++, VB, Perl, Java, C#, and even a little Groovy. I've somehow seemed to find myself in a position where people ask me if I can do something for them in another language and I can't make myself say no. I see the language being used as more of a tool because the actual business logic is the same regardless of the language used.

What was your first professional programming gig?
When I was in college I got hired to work in the IT department for the Army Corps of Engineers. I was able to work on some of the business applications they used in-house to work with data in databases. They were nothing big, just your basic CRUD applications.

If you knew then what you know now, would you have started programming?
Yes, I would still have gone into the software field. I just would have started my own company a long, long time ago. I think that would have saved me a lot of stress and put a lot more $$$ in my tiny pockets. ;-)

If there is one thing you learned along the way that you would tell new developers, what would it be?
Get the GoF design patterns book fast and learn it. This advice could have saved me a lot of time spent on refactoring and rework in the beginning of my career.

What’s the most fun you’ve ever had… programming?
That would be my senior design project back in my years as an undergraduate. We designed and built an automated baby monitoring device that included a motion pad, and A/V that could be automatically streamed to a remote computer if predefined settings were met. Those late nights in the lab only reinforced my love for this field.

That was a lot of fun. We often forget about those times when we are first introduced to something we enjoy and love. I know I had forgotten about a lot of things like that lately. I am slowly finding my way back to that and with that new ideas are coming. I am sure I will be sharing some of them soon. Stay tuned...

May 17, 2008

Possible Next Project...

I've come to the conclusion that I need a nice side project to do this summer. I spent most of last year working on a simulation for my thesis. It was done in C++ with the simulation framework created by my professor. The entire time I worked on it I wished there was a Java version of his framework so I wouldn't have to deal with all of the pointers and memory allocation/de-allocation issues that come with C++. At the time I wanted to create a nice Java simulation engine and framework to use for any simulations I, or others, might do in the future.

Now six months have passed since I finished my thesis and I still feel like I want to create the framework so I am going to do it. I will be creating a nice, simple, and easily extended Java discrete event simulation library and engine. This will be my first real experience with building software for the "community" so it should be something I will be able to use to further increase my craft.

After attending Dallas TechFest and getting to interact with some of the speakers in the time since, I've realized that I need to put my knowledge to good use. This means becoming active in some of the local user groups, attending more conferences, and creating projects that can be of use to others. Just going to work and doing the limited amount of development that happens in an office environment will not get me where I want to be. I have to take my craft and career development in my own hands and take them to the next level.

February 20, 2008

No Design Questions in Interviews???

I'm sitting in on a technical interview tomorrow and as I was skimming through the resume and coming up with questions I had an interesting thought...

Why do design techniques never come into play in technical interviews??

Now I know that some companies might possibly give someone an "oral examination" where they have them design a component on a white board, but in all my interviews I've never been given a test or had to answer real questions on OOAD. Now, I have been given programming tests out the wazoo. But honestly, who cares if you can program the world with C# delegates or perform pointer arithmetic (yuck!!) if you can't take a simple functional specification document and transform it into an end product that meets the end user expectations?

If software engineering is ever going to truly be considered an engineering discipline we need to move past the processes of simply testing knowledge of programming languages. Programming languages are nothing more than tools to a software engineer. We need to be hitting the software engineering concepts as the true gauge in hiring as I have met many a person who could ace a programming test and then turn in an application where all of the code existed in one long file...