Our industry is constantly changing. So much so, that it is difficult to keep up sometimes. This last May at Microsoft Tech Ed 2009, I heard the same comments from many attendees; “Which technology should I use?” “What should I learn?” “Why does Microsoft have to keep changing things all the time?” While there are no easy answers to these questions, and none of us has a crystal ball, there are a few things that are tried and true and have always worked in our industry that I recommend that you stick with.

I have had to re-invent myself many times in my programming career. I have gone from Basic programming on a PDP-11 to COBOL on a 360 mainframe, to Clipper, to Visual Basic, to Actor, to .NET. I am sure that you have had to do the same thing if you have been in this industry for any amount of years. One thing remains true: The basics in any language will always work.

  • Structured programming
  • Object-oriented programming (OOP)
  • Avoid copy and paste
  • SQL / Set theory

OK, granted, we did not have object-oriented programming in COBOL on a mainframe 20 years ago, but we did have structured programming. Now, some of you may be saying, “Yeah, but what do these have to do with WPF, WCF, and any other ‘F’s you might want to learn today?” Well, nothing and everything. When you use any of these new tools, you still have to apply the basics when programming these new tools. I still use OOP techniques, structured programming, and SQL when using WPF. I also avoid copy and paste when writing XAML by factoring out common XAML into resource dictionaries. Most of these new languages and technologies are quite often just syntax that needs to be learned. However, under the hood, you are still programming in .NET.

Structured Programming

You can use structured programming techniques with any language. Put simply, structured programming is a method by which a logical structure is imposed on a program to make it more efficient and easier to understand. Most modern languages are actually designed with structured programming in mind and will enforce a logical program structure.

Program flow in structured programming is very top-down oriented. Each section in a program should flow in one direction. In most cases you should only have a single entry point into a block of code, and a single exit point out of that block of code.

You need to keep many things in mind when developing applications. How you design your blocks of code is one of them. A block of code can be a function or procedure, an “if” statement, a switch statement, or a loop construct. Try to keep the amount of code in each block to a minimum. Each block should do one thing and one thing only. If the block of code you are writing does two things, break that block into another function or procedure. This process of breaking blocks into smaller chunks will have many advantages such as making the code more readable, reliable, reusable, and much easier to test.

Object Oriented Programming

Most developers have been doing some form of object-oriented programming for quite some time. Sometimes you might not even realize it. If you used VB 6, for example, then every control is a class, and you interact with it as an object by setting properties and calling methods on those objects. The advantage to this is you do not need to know how the control does its job; all you know is that by setting properties and calling methods, that job gets done. In other words, it hides all the messy details from you. You need to create your own classes, properties and methods so you can get this same level of abstraction in your programs. This will ultimately lead to less code in your own programs because you have hidden implementation details in classes that you now just use.

An easy way to start on your path to OOP is take a few functions, the properties those functions use, and place them all into a class. This is a good first start to creating your own classes. As you learn to put these related functions and data together you will start to see other ways to encapsulate your code.

“Try to keep the amount of code in each block to a minimum.”

Some old-school programmers wonder why they should use OOP techniques. OOP provides many benefits over just structured programming alone. This list summarizes the benefits you will derive from using object-oriented techniques:

  • Makes your programs more reliable by eliminating global variables.
  • Makes your programs more modular by placing related data and methods together in one place. This in turn allows you to…
  • Focus on a smaller set of data and functionality.
  • Unit test quicker and easier.
  • Reuse functionality in other programs.
  • Makes it easy to extend program functionality through the use of inheritance.
  • Hides the complexity of blocks of code.

Good developers understand that global variables kill productivity and make tracking down bugs very difficult. The ability to move data and the functions that operate upon that data into one place make reading code easier, makes code more reliable, and also contributes to better testing. In addition, you can reuse classes in other applications you write.

“If you don’t start using OOP, you could become a dinosaur and be faced with finding a new career.”

Each new technology that Microsoft comes out with today uses object-oriented programming techniques. If you don’t start using OOP, you could become a dinosaur and be faced with finding a new career. This may sound a little harsh, but it is true. If you want to take advantage of WPF, WCF, Silverlight and other technologies, you will need to understand OOP.

Avoid Copy and Paste

If I had my way, I’d outlaw copy and paste for developers. Copy and paste is one of the ways in which corporations end up with lots of bad code. I see it time and time again in my consulting gigs-the same piece of code in literally dozens of places. It will not only show up in the same application, but across multiple applications as well. This is completely unacceptable. The major reason for creating classes, methods and class libraries is to eliminate duplicate code and promote reusability.

Smart developers use cut and paste, also knows as refactoring, instead of copy and paste. Refactoring encourages that you cut code out that you intend to reuse and place that code into a new method. You then call that method from the location where you cut it out from in the first place, and you call that method from the new place where you wish to use it. Refactoring makes your code much more maintainable. So the next time you copy code, stop and think; maybe you should be cutting instead.

SQL and Set Theory

Using SQL statements and set theory is an area where I see a lot of programmers (and some DBAs) could use a little more training. Many programmers write too much code to loop through a set of records. Whether you write code to loop through records in a front-end program or in a stored procedure with a cursor, look and see if there is a better way to write that code. In most cases, the answer will be yes.

You can optimize SQL statements in many ways. One effective method is to avoid looping. Using sets of data as opposed to loops will always result in faster queries and less resources being used by the client and server.

Besides loops, multi-table joins are also very inefficient. Try to break apart the loop or the multi-table join and create a multi-step approach to the problem. Instead of a four table join or using a cursor, how about creating some temporary tables where you first join two tables and put the result of that join into a temporary table. Then take the next table and join it to the temporary table to get your next result and place that into another temporary table. Then finally, you can join the temporary table to the last table and get your final result. Here you use sets of data and reduce the amount of data used in each join, which makes the overall process consume far less resources.

So, the next time you see a 10-table join, you might look at breaking this join into several smaller steps. The next time you see a cursor being used, try this multi-step approach too. You should see huge benefits when doing this. I have been very successful using this technique in my 22+ year career and have optimized queries that used to take 10 minutes to run to running within seconds!

“If I had my way, I would outlaw copy and paste for developers.”

A Crystal Ball

Ok, so you are using all the basics described above, and you are familiar with .NET. So, which of the new technologies out today should you start working with? I suggest you look at those technologies that have been relatively stable for a few years within .NET. For example, at PDSA, Inc., we use the following technologies quite regularly.

  • ASP.NET
  • WPF (Windows Presentation Foundation)
  • WCF (Windows Communication Foundation)
  • Silverlight
  • Team System (especially unit testing and source control)

We have done project development in the above technologies for quite a while, or we will start new projects using them. While we certainly do not have a crystal ball into the future, we think these technologies will be core for quite a while to come. Some of the newer technologies such as LINQ to SQL, Entity Framework, Azure, and others that are just being introduced we are not going to use any time soon. These technologies are just too new and are changing too frequently. Once they have been around for a couple of product cycles, we will re-visit them-if they are still around.

Summary

You definitely want to keep an eye on the new technologies coming out from Microsoft. Learn a little about those technologies; keep an eye on what books are published on those technologies, and what people say in the press about them. Also, keep an eye on how many tools are created for those technologies. The more tools, the more books, and the more the technologies persist from version to version of .NET, then the more likely they will be there for the long haul. Yes, this means that you may not always be on the leading (bleeding) edge of software, but you will be viewed as someone that is very stable and gets the job done.