Pages

December 9, 2009

A Float is NOT a Currency

Do not use floats when representing currency.This is just asking for trouble.

Anytime you have to deal with floating point representations you can always get unpredictable results. I cannot count the number of times I have seen the "phantom penny" situations where balances are a penny off and you end up spending half a day with your accountant hat on trying to find where the penny went. You look and look and then you realize that somewhere in the code someone used a float inside the calculation. You change the variable type and your penny "magically" appears.

There are many alternatives in the modern programming languages for representing currency and they should be used. If those are not available, you can always go old school and use the int primitive type to represent currency.

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...

July 2, 2009

New Beginnings

I decided to change the name of the blog to be more relevant to me (and to rid myself of the possibility of getting a stink message from the Dilbert folks if this blog ever picks up any traction). I have some crazy things going on at home right now as I am preparing for a new addition to the family that will be here soon, but I will soon be giving this blog the attention that it needs. I am starting with the look and feel and with that I have already created a new feed for this blog:

http://feeds.feedburner.com/MrWillSoftware

In about a month I am going to turn off the original feedburner feed, so be sure to update any RSS readers you are using.

May 26, 2009

World Class Computer Science Courses for FREE!!!

For those of you who do not know, MIT and Stanford both offer free computer science courses. they are comprised from courses in previous semesters and in some cases the current semesters. They cover many topics and provide you to get some world class education at the price of $0.00. Can't beat that... Just try the links below.

MIT Computer Science Courses


Stanford Engineering Everywhere

Stanford on iTunesU

If there is enough feedback, I would be very much open to starting an online study group to go through some of the contents in particular classes.

May 4, 2009

Reviewing Requirement Specs for New SW Devs

One of the most difficult things for new software developers to do is to review a requirements specification for a new feature or module. Too often they simply read through the spec and do not bother to question it. This would be fine if all specs were complete when they reached the developer's hands, but this is usually not the case. In this case, it becomes the developer's job to ensure the spec finds its way to completion by raising any concerns. This is where the Requirements Checklist in Code Complete comes into play.

The Requirements Checklist is not a list of things that must all be present, but they create a nice guide for checking the completeness of specifications. You should apply these questions to any requirements specification you receive and if the answer is no to any of them, you should question the writer as to why.

Here is a snippet of the checklist with some explanations as to why they are important. The rest of the checklist can be found on the Code Complete site (http://www.cc2e.com/0323).

Specific Functional Requirements

  • Are all the inputs to the system specified, including their source, accuracy, range of values, and frequency?
  • Are all the outputs from the system specified, including their destination, accuracy, range of values, frequency, and format?
  • Are all output formats specified for web pages, reports, and so on?
  • Are all the external hardware and software interfaces specified?
  • Are all the external communication interfaces specified, including handshaking, error-checking, and communication protocols?
  • Are all the tasks the user wants to perform specified?
  • Is the data used in each task and the data resulting from each task specified?

April 28, 2009

Series of Posts on Code Complete Coming

With my decision to turn this blog into what I hope will be a resource for beginning developers, I have decided to return to Code Complete by Steve McConnell and create some posts on various topics in the books. So in the next few weeks I will begin a weekly post on a topic, starting with the beginning of the book and will work my way towards the end pulling out things I think are helpful to new developers.

As these posts appear, feel free to give feedback on anything. I am doing this to give back to the community and not for myself.

April 1, 2009

Change Is Coming

I took some time to take a step back and think about what it was that I really wanted to achieve with this blog. In the past I had posts about my graduate thesis progress, but there was slowly a transition into more posts about various topics in the software engineering community. I didn't gain much of a following and I just wasn't happy with the content I was generating. So I sat back and thought about what I would have really wanted to read in a technical blog and with that I have made a decision.

I am going to resurrect this blog into something that can be very helpful to those individuals who are just starting out their careers in software development. I can think back to when I first started working after college six years ago and I had no idea what I was truly getting myself into. I had a strong grasp of the theoretical parts of software development, but didn't have much exposure to real world concepts that would help me in the long run. If I knew then what I knew now, I would not have felt so lost. So my road map for the future of this blog is to provide posts and tutorials on things that can help when you first step foot into the office for the first time. I aim to have mostly technical posts, but I will occasionally provide some input on business sense and dealing with different personalities on a team.

So be on the lookout for more posts coming soon. Black Dilbert will be reborn and will be better than ever!!

March 16, 2009

Finding Focus

I have decided that my blogging here has been lacking focus. What I originally planned for this blog was to follow my work on my graduate thesis, but when it was complete I was unsure of the next direction to take. I started to dabble a little in some small software engineering/development topics I encountered, but I never really got into any real detail. So I think I need to take some time to figure out the focus and direction I am going to take with this blog.

So stay tuned for a new and improved Black Dilbert. In the meantime, if you have any suggestions on what you would like to see here please let me know.

March 5, 2009

Thesis Is Alive and Well in the WWW

I was bored today so I did a quick search of my name and wireless mesh networks and my graduate thesis was returned at the top of the list. If you have some free time and want to spend some time catching up on IEEE 802.15.4-based wireless mesh networks you can find my thesis at http://hdl.handle.net/10106/741.

Just skimming through it sent me back to the long nights I spent slaving over simulations and data analysis. I must admit that I kind of miss it...

February 24, 2009

Laid Off Developer?? Get Free Training

Steve McConnell is doing a very honorable thing by offering laid off software developers free seats in his seminars and training sessions through his company, Construx Software.

Personally, I think this is great thing he is doing. There are a lot of our software brothers and sisters who have found themselves suddenly out of work due to the current financial climate. This is probably one of the biggest times we need to pull together as a community and help others.

Click here for more information.

February 5, 2009

Unfuddle, Free Subversion and Git Hosting

I have been working on a few small projects and I wanted to get my source into some sort SCM repository so I could easily keep track of changes. Well I found a nice site, Unfuddle, that will allow you a free repository for personal projects. It is perfect for what I am doing and allows me to update my source from any computer.

Free Online Java Training Courses

I recently found the Java Passion site by Sang Shin. If you have not been to the site I recommend you do.

Sang Shin has created numerous online training courses that are all free!! He covers all sorts of Java topics from the basic beginner's of Java lessons to advanced Java EE topics. In these times where companies are cutting back on training expenses more than ever, this is a very easy way to keep your skills up to par and learn new technologies.

I have actually started the course on Spring as I have missed the Spring train in my current job and have not had the chance to sit down and learn it. So far it is going very well. Each lesson has a nice presentation, followed by very detailed step-by-step examples and a hands-on lab. So I have no doubt that I will be "Springing" in no time.

January 23, 2009

Springing into Action

So I have decided that I need to become more familiar with Spring. Many consider this to be the main technology that should be learned for those making the move to be involved in Java EE development. So I am doing everything I can to learn about Spring and more importantly dependency injection.

So far I am working my way through a nice tutorial. I found a great package of examples, notes, and assignments on Java Passion. This is an excellent site for people wanting to learn more advanced Java technologies. The site creator, Sang Shin, has created a number of lessons and even has free online classes. So I will be using is to hopefully become a Spring natural. It will come in handy with a nice idea I have been working on for a local furniture business...