A Day in the Life of a Programmer

A Day in the Life of a Programmer

The Big Picture

Casey Patton said that "Programming is thinking, not typing." Although programming is about building apps, there is a mental (the thinking) and physical (the doing) dimension. The mental side of things is involved with specifications, systems analysis and design, and planning. The physical side involves coding, the actual writing of computer instructions that will eventually become the software application.

So, without becoming too technical, let's see what a day looks like in the life of a programmer. We will focus on a micro project to fit all this into a day.

Our Project

Our first client is Mike from Mike's Tiles. Mike has been selling tiles for the last 12 years and needs a break. He decided to leave the business in his son, Tayler's care. Here is the problem. Mike knows exactly how many tiles a customer needs to cover a floor. It's a gift he was just born with. Tayler, on the other hand, has not been blessed with this gift. So, Mike asked us to build a small application to help Tayler calculate the correct number of tiles while he is away on his long-deserved holiday.

The Software Development Life Cycle

We will use the Software Development Life Cycle, or SDLC, to deliver a quality application. A Software Development Life Cycle is nothing but several defined stages that occur during the development of an application.

Other names you will encounter are System Development Life Cycle and Application Development Life Cycle. They all refer to the same thing.

SDLC Stage 1 - Initial Meeting

The first thing we do is meet up with Mike at the shop. Spending time with the client and observing the client in action helps developers understand the problems the client is trying to solve. Depending on the scope of the problem, it can be helpful to spend a few days with the client, just observing and asking questions. As this is a small problem, one meeting should probably suffice.

During this meeting, we determine who will be our Subject Matter Expert (also called Domain Expert). This person knows the business inside out and is at our disposal should we have to meet or if we have questions that need answering. In this case, it is Mike himself.

SDLC Stage 2 - Analysis of the Current System

This stage is missing from many SDLC articles I have read over the years. This always surprises me because how can you know where you are going if you don't know where you are?

During this stage, Mike tells us about his special gift of calculating the correct number of tiles needed to cover a floor. It is our job as analysts to see if we can figure out a formula that Mike may not even be aware of.

It turns out that Mike calculates the product of the number of tiles for the width and the length of the floor. Should an exact number of tiles not perfectly cover the width or length of the floor, he adds an extra tile for that dimension. So much for a special gift! Mike also adds a few extra tiles to cover for breakage.

So we end up with these two drawings:

The Perfect Fit Case

The tiles cover the floor width and length exactly, so we need 4 x 5 = 20 tiles, assuming there is no breakage of tiles.

The Not-So-Perfect Fit Case

Here, we are going to need 6 x 5 = 30 tiles. (It is clear from this picture that the cutoff piece of tile 6 can be re-used but we are going to keep things simple as it is our first application. The same goes most probably for the bottom left tile 5).

SDLC Stage 3 - Analysis of the New System

Now that we know where we are, we need to figure out where we want to go and how to get there. We know that Mike's gift was just plain old mathematics, which is good because computers love formulas. So what does the new system need to do?

Mike tells us his true gift shines when calculating tiles for round and odd-shaped rooms. But, he said, for now, he needs an application that can calculate the number of tiles for rectangular rooms only. That is going to make our job very easy. So, room shape is the first constraint. The second constraint is that we are not to worry about extra tiles for breakage for now, as Mike's tiles are virtually indestructible.

We tell Mike that he can do these calculations with a calculator or even a spreadsheet. However, he insists on a dedicated application.

SDLC Stage 4 - System Requirements

Now that we know where we are and where we need to go, we can draw up a document detailing the requirements of the new application. This is also called a Specifications Document or Specs for short.

SDLC Stage 5 - Planning

At this point, we meet with Mike again and present him with the Specs. The idea is to ensure that Mike didn't miss anything and that we didn't miss anything. As Mike decided not to go with a manual calculator or Excel Spreadsheet, we discussed possible technologies we could use for Mike's new application. One can often use existing Infrastructure, thus saving the client money.

SDLC Stage 6 - Design

It is decided not to store previous calculations; thus, no database will be used. Similarly, because it is such a simple application, no Graphical User Interface or GUI will be used. The application will be a console application which is about as basic as it gets.

SDLC Stage 7 - Implementation & Testing

We have decided to build the application with DOT NET Core Version 8 and C# Version 12, which is the latest at the time of writing. Please note that we could just as well have built the application with Java, JavaScript, Python, or Go, for that matter. I just decided to use C#.

The Code

// display app name
Console.WriteLine();
Console.WriteLine("Mike's Tile Counter");
Console.WriteLine("-----------------------------------:");

// get the length of the room in centimeters
Console.Write("Length of Room                 [cm]: ");
var lengthOfRoom = Convert.ToInt32(Console.ReadLine());

// get the width of the room in centimeters
Console.Write("Width of Room                  [cm]: ");
var widthOfRoom = Convert.ToInt32(Console.ReadLine());

// get the length of a single tile in centimeters
Console.Write("Length of Tile                 [cm]: ");
var lengthOfTile = Convert.ToInt32(Console.ReadLine());

// get the width of a single tile in centimeters
Console.Write("Width of Tile                  [cm]: ");
var widthOfTile = Convert.ToInt32(Console.ReadLine());

// get the price of a single tile in dollars
Console.Write("Price of a Single Tile          [$]: ");
var unitCost = Convert.ToDecimal(Console.ReadLine());

Console.WriteLine("-----------------------------------:");

// calculate the number of tile to cover the length of the room
var numberOfTilesForLengthOfRoom = lengthOfRoom / lengthOfTile;

// add an extra tile if if there is a gap
if (lengthOfRoom % lengthOfTile > 0) numberOfTilesForLengthOfRoom++;

// calculate the number of tile to cover the width of the room
var numberOfTilesForWidthOfRoom = widthOfRoom / widthOfTile;

// add an extra tile if if there is a gap
if (widthOfRoom % widthOfTile > 0) numberOfTilesForWidthOfRoom++;

// calculate the total number of tiles needed
var totalNumberOfTiles = numberOfTilesForLengthOfRoom * numberOfTilesForWidthOfRoom;

// calculate the total cost of the tiles
var totalCost = totalNumberOfTiles * unitCost;

// display the results
Console.WriteLine($"Number of Tiles for Length of Room : {numberOfTilesForLengthOfRoom}");
Console.WriteLine($"Number of Tiles for Width of Room  : {numberOfTilesForWidthOfRoom}");
Console.WriteLine($"Total Number of Tiles Needed       : {totalNumberOfTiles}");
Console.WriteLine($"Total Cost                      [$]: {totalCost}");
Console.WriteLine("-----------------------------------:");
Console.WriteLine();

If you wish, you can download the code here

Running this application, we will enter the length and width of the room in centimetres. Next, we will enter the length and width of a single tile in centimetres. Lastly, we will be asked the price of a single tile in dollars. The app will then supply us with the number of tiles needed and the total cost.

Here are the results of a perfect fit room:

Here, we have the results for a not-so-perfect fit room:

A Short Explanation of the Code

Lines 7 to 24 contain the code that asks the five questions. The length and width answers are converted to Integers, and the price per tile is converted to a decimal value. This conversion of values is necessary because we will do some mathematics with them.

  • Lines 29 to 44 contain all the calculations, also called the Business Logic.

  • Line 29 calculates the number of tiles needed for the room's length by dividing the room's length by the length of a single tile.

      // calculate the number of tile to cover the length of the room
      var numberOfTilesForLengthOfRoom = lengthOfRoom / lengthOfTile;
    
  • Line 32 adds an extra tile for the length if it is not a perfect fit.

      // add an extra tile if if there is a gap
      if (lengthOfRoom % lengthOfTile > 0) numberOfTilesForLengthOfRoom++;
    
  • Lines 35 to 38 do the same for the room's width.

      // calculate the number of tile to cover the width of the room
      var numberOfTilesForWidthOfRoom = widthOfRoom / widthOfTile;
    
      // add an extra tile if if there is a gap
      if (widthOfRoom % widthOfTile > 0) numberOfTilesForWidthOfRoom++;
    
  • Line 41 calculates the total number of tiles needed by multiplying the number of tiles for the room's length by the number of tiles for the room's width.

      // calculate the total number of tiles needed
      var totalNumberOfTiles = numberOfTilesForLengthOfRoom * numberOfTilesForWidthOfRoom;
    
  • Line 44 calculates the total cost by multiplying the total number of tiles by the unit cost per tile.

      // calculate the total cost of the tiles
      var totalCost = totalNumberOfTiles * unitCost;
    

Again, if this does not make sense, don't worry. We will get to coding in due time.

SDLC Stage 8 - Deployment & Training

Assuming we have a well-tested application, we are ready to install the application on Mike's PC and train Mike and Tayler on how to use the app.

For the record, the code shown earlier will crash if you enter it wrong. For example, for the price per tile, I entered ten instead of 10 and ended up with a system crash:

To prevent crashes like these, we have to do defensive coding. It means that we have to validate all user input and let the app act accordingly. In the example above, the app should tell us that it cannot convert the word ten into a decimal number and prompt us again for a value. To keep the code simple, I have not done any validation in this example.

SDLC Stage 9 - Monitoring & Maintenance

Once the application is in use, it gets monitored to see that it runs effectively (giving the correct answers) and efficiently (answering as quickly as possible). Mike might get back to us later with a request to expand the application to cater to odd-shaped rooms. That is when we go into maintenance mode and repeat the SDLC.

In Conclusion

Do not underestimate the value of small applications. I have written many small applications that made a significant impact on the way people work. I remember this one application I wrote for a lady that allowed her to do double the amount of work a day with a fraction of the amount of stress. And it took me less than a day to write the app for her! At least this post gives you some insight into the Software Development Process and a small glimpse into the code itself.

Now we are ready to start learning how to become a programmer. And we are going to start with the Database layer. See you in the Database Fundamentals Courses!