Bad Investments

This is not your ordinary coding-related post, so bear with me.  My daughter received a monetary gift many years ago.  It was invested in a bank in Ohio and she wasn’t allowed to touch it until she turned 18.  It wasn’t a huge sum, but it wasn’t $10 either.  Here’s what happened.  Let’s use a starting point of $1000 as an example.  After 11 years in the bank, a very safe place to put your money, it was worth $1170.  That’s a tidy increase of $170.

Not so fast, though.  The S&P 500 went up around 2.7% over that time.  If the money had gone in there, she’d have $1341 now.  What about a balanced mutual fund?  The Fidelity Puritan Fund went up an average of 5.2% per year, which would have given her $1747 now.

It gets even better when you add inflation.  The cumulative rate of inflation over the same period was 34%.  If you had invested in the S&P 500 over that time (it was a rocky up and down time) you’d still be even with inflation.  In the Puritan Fund, you’d still be ahead.  In the bank, you’d actually have lost money.

So, why am I giving you this little lecture?  Because I used to work with a group of developers who were afraid of the stock market.  They kept their money in the bank in safe investments.  And they were going to lose a lot of money due to inflation, which is the hard part to detect.  Interest rates in bank savings accounts are less than 1% right now and CDs aren’t much better.  Meanwhile the stock market has been on a tear since the recession has eased.

Your best strategy for retirement is a mix of investments in stocks, bonds, commodities, etc. and thinking for the long haul.  Try investing in one of the newer “retirement date” funds that some firms have now.  You pick a year for your retirement and they adjust the mix of stocks and bonds for you.  It couldn’t be simpler.  And you might actually retire with something to live on.


Financial Incentives

Recently, I worked on a Linux-based project.  After spending most of my recent years in Windows land, it was interesting to see where Linux has gone.  Yes, there are some visual tools so you don’t have to ls and cd your way around the file system if you don’t want to.  Yes, there’s a nice way to install software (thank goodness).  There are even some decent applications for code development.

But, what struck me was the overall clunkiness of the environment.  I still hear people talk about setting up a Linux box for their home and I don’t get it.  It’s capable and secure, but the average home user would be lost.  It’s an environment for people who like to, or need to, tinker with the engine themselves.

This brings me to my point.  I see Linux as the largest example of open source software.  It has lots of functionality and tons of contributors.  However, how many times have you downloaded an open source project or freeware in any environment, just to discover that the support has disappeared a year ago.  It’s interesting because sometimes a project like this is the only thing that fits your problem well, but when the support disappears, you’re out of luck.  I started using a java user interface toolkit that was amazing, but the developer just shut the project down and I can’t even find the documentation online anymore.

I believe the answer is in the lack of financial incentive.  For all the talk of the greater good and free software (for which I’m very grateful), the quality and support is usually better when someone is trying to make a living producing it than when it’s just a pet project.

The next time you’re sitting at work, writing code for a living, think about what you owe to your employer who’s paying your salary and benefits, and the users, who rely on your software.  Or think about the potential users, whom you are trying to lure into buying your software.  If there’s money involved, will this change your attitude on how you work?

Who’s Your Data?

I’ve worked on a lot of different projects and products over the years.  Most of these have been PC-based, file-based storage, applications.  The latest project I’ve been working on has been similar, except that its data is stored in a database.  My colleague, Steve, and I were talking about global data recently, and it got me to thinking about the some of the more horribly structured projects I’ve worked on in the past.

Now, envision that you’re new to a project that’s been in the works for a few years.  There have been a couple of revisions released to the public.  The code has patches scattered around it, copied and pasted code, sparse comments, and data and operation code are intermixed.  In order to write new code, you not only need to understand the data, but the hierarchy of objects that contain the data.  Storing this in files is a recursive process that filters through object after object.  Touch something and something else breaks.  Sounds like most code you’ve worked on, doesn’t it?

Again, envision this code, but with the data stored separate from the operations on the data.  Sounds a bit like Model-View-Control doesn’t it?  Well, even if you aren’t working on something that’s well laid out in a nice, interface-based, MVC pattern, or you want to build something that’s quick and less painful, or you want to migrate some of your code to something similar, a global data area might solve your problem.

I’m not talking about a wad of global variable strewn all over the place (that’s a mess).  I am talking about an in-memory database, with structured information.  In other words, the information that you need to save could be stored in a set of arrays, classes, or structures, that do nothing but hold the information.  All of the other work would be done by other classes.  Think how easily you could write new code to operate on the data without interfering with the other classes that operate on it.  Think how easy it would be to find data.  Think how easily you can implement persistence (save and load).  This could be a simple step in cleaning up some of the spaghetti that’s already in your code-base.

Extra Conditioning for your Career


Really, it’s all in here.  I don’t do an enormous amount of hawking my book on this site, but the other day, I realized that I’m doing a disservice by not pushing you into buying it.  Why?  It’s not because I want your money.  Buy it from Amazon for only $18.96 and it will pay for itself.  How does it pay for itself?  I’ll enumerate some of the reasons:

  • Don’t screw up another interview, get the next job you apply for.
  • Once you get offered the job, you’ll get a better salary and/or benefits by using some of my tips for tactful negotiation.
  • You’ll improve your organization with your leadership skills you get by following some of the ideas on organizational and personal habits.
  • You’ll keep your nose clean by avoiding risky practices that can get you in trouble with human resources and management.
  • You’ll understand marketing and sales better and learn to work more effectively with them by understanding that it’s a partnership, not a leash.
  • Your place in the software organization will improve because you’ll realize that it’s not just your coding that counts, it’s the intangibles as well.

It took me a long time to realize that my biggest benefit to my employers wasn’t my coding skills, but my leadership and big picture knowledge.  The sooner you read this book and come to the same realization, the sooner your career takes another step forward.

What You See

What you see might be indicative of what you don’t see.  I was looking for some software today to use at work.  I had it narrowed down to three choices, based on recommendations from people on various websites.  I read numerous comments and finally went to the three websites to investigate for myself.

Two of the products looked slick and their websites were polished and helpful, including documentation and screenshots for the product.  The third one, the most expensive of the three (although it was still pretty cheap) had the weakest website, relatively little information, no screenshots, no documentation – in other words, very little to instill confidence in me that they would have useful documentation or that their product would be complete either.

In an ideal world, I’d have time to thoroughly investigate all three products regardless of their initial presentation, but I needed to get my job started and if my first impression was bad, and I still haven’t found the other products useful, then I’ll give them a second shot later.

In the meantime, I needed some documentation to help get me started.  I found examples on the websites of the other two products and lists of features so I knew I wouldn’t have to leave the comfort of their environment to start using some command-line interface.  Yes, I’m a programmer, but I don’t go looking Toolsfor excuses to do more work than I have to.  If I can find a simple, easy to use UI that makes a job clear and easy and does all the messy work in the background, I’m in.


It should be common knowledge by now that smaller functions are generally better functions.  It may well take the same amount of code to get the job done, but by subdividing the functionality into small functions, you have more opportunity to reuse the code.  Additionally, it usually makes it easier to modify the code as well.

This past week, I was adding some functionality to the IDE that I’ve been developing for uCLinux development on Windows (it’s called Fusion – see  The current version supported application development in the form of one executable or library at a time.  We wanted to support the concept of a solution, so that you could have several libraries or executables in the IDE at the same time.  After looking at all of the locations in that code that would be affected, I guessed that it would take me a couple of weeks to add this and make the other modifications to the existing functionality.

Fortunately, I’m a big fan of small functions and C#.  The small functions let me make some quick modifications to the application-development specific code in Fusion so that it could accommodate solutions.  Adding new functionality allowed me to reuse the small functions that I already had and I created some new task-specific functions to help with the job.  Finally, C# helped me by providing some awesome XML import export functionality.

I can’t speak highly enough about C# and Java in their inclusion of UI and base functionality that just lets developers write the new code without having to reinvent the wheel.  By the same token, every time you write a small, self-contained function that does a particular job, you do the same thing to your own code base.

Get an IDE

A few weeks ago, I had a project where I switched from the comfort and all-encompassing world of C# development with Visual Studio to Linux land.  It reminded me of programming in the dark ages.  Opening every file in a basic editor that knows nothing about the code.  No code completion.  No “Go To Definition” or “Find in Files” (grep?  seriously?).  No bookmarks.  The constant switching between gedit, command consoles, and file browsers was exhausting and time-wasting.  My friend Steve was just accustomed to it.

I started researching an IDE.  Since we were running “make” to do cross-compilation, I wasn’t worried about integrating the build process.  Still, I wanted to see if I was crazy or if I was right that an IDE would help me focus on the job at hand rather than on finding the right code to modify.  After much reading, I settled on something small and easy to install that several people recommended – code::blocks.  It has the basics of any reasonable package:  projects, solutions, bookmarks, easy switching between files, Find in Files, etc.

Suddenly, even though I was in the world of C, which is light-years behind C# development (no flames, please), at least I could work more productively.  I know that die-hards will probably use vi or emacs (I was a big emacs user back in my unix days) and using all the basic tools available in unix/linux, but I think they’re missing out on the possibilities of not needing to do it all yourself.  Let an IDE give you a hand.  It’s not a crutch to lean on, it’s a step stool to start from.

The Important Things

I’m still working on my project to restructure the application where the original programmer cut and pasted thousands of lines of code.  So far, my fellow programmer, Steve, and I have eliminated over 100,000 lines of code.  In the process, we’ve improved performance and added functionality.

So, what are the important things mentioned in the title of this post?

1. Write decent code in the first place.  How?

  • Make good base classes to hold common functionality.
  • Constantly design and refactor code to keep it flexible, reusable, modifiable, and understandable.
  • Comment your code!  It’s usually obvious when a comment is out of date or inaccurate, but the value of an accurate comment, especially for confusing or complicated code is immense.
  • If you think you need to copy a fragment of code, think about putting it in its own method, base class, or separate class.
  • No, you won’t think of everything.  We all write code that we later regret, but the closer you get to good, the easier it will be to get to excellent later.

2. Think ahead.  That doesn’t mean that you should build in tons of functionality you don’t need now or may never need.  It means being conscious of what could come in the future.  Using reasonable data hiding to keep internal functionality flexible is a great way to start.  If you expose all of your data directly to other code, you have more places to change it if you find performance bottlenecks.

3. Stay creative.  Even when you’re working from a specification or set of requirements, you often have some flexibility in your coding.  Some amount of flexibility is usually included in the functionality.  If you work on consumer software, there’s usually a lot more flexibility.  It can’t hurt to bring it to someone’s attention or sometimes, to just go ahead an implement it.

4. Think globally.  It’s not just your code and your little part of the world.  Your personal value increases when you pick your head up out of your code and look at the application as a whole.  As long as you don’t step on everyone else’s toes, you’ll make the whole team look good.

Take away that man’s copy and paste


Looking for the perfect gift for a programmer or software engineer?  Try Design, Code, Test, Repeat.  It’s a fun, funny, and helpful read.

Now, on to today’s post.  I recently started working on a new project which involves modifying a large application.  After talking with the boss about what needs to be done, the first task became obvious.  The large application needed to get smaller.

To give you an idea of he horrors in this project, let’s start with the UI code.  There are three types of interactions you can have with the UI and they all look similar, but with slight modifications.  This UI is essentially duplicated for two units which you are interacting with.  So, what’s the best way to handle this?  Well, any normal programmer would write a bunch of methods or subroutines and divide the work, reusing the common code and making some exceptions here or there.  Or you might want to create a few classes and use some object-oriented way of differentiating the mechanics.

But, no.  Here’s what our hero did:  he copied all of the code.  So now, there are five extra copies of a ton of code that need to be maintained and modified for future work.

Next, there is a massive amount of data that is read from a database, put into an in-memory structure, and then set in the UI.  When the user wants to save, the data is read from the UI, put back in the in-memory data structures, then written back to the database.  There are hundreds of possible pieces of data to read and write.  Is any of this work done with a clever class or technique that uses a lookup table(s) or some other maintainable/enhanceable manner?  You already know that the answer is: no.  It’s all done one piece of data at a time, copied five more times.

I won’t tell you that I haven’t copied code; of course I have.  But, all of us have our tolerance for doing this.  Every time I copy a small section of code, I think, is this the time to add a method or class that does this job?  If it’s a large chunk of code, the answer is always yes.  If it’s just a few lines, I’m likely to say, next time for sure.

Here’s the real issue.  If you find yourself having to repeat the same procedure constantly to handle differences in names of data and their UI counterparts, it’s time to get creative.  I’ll be doing this shortly and I’ll let you know what I come up with.  Be sure it won’t be a copy and paste answer.