Side Project – Connect 4

Hello?

You have probably like me almost forgotten about this blog. Life has got in the way over the last few months, but lets see if I can restart my blogging habit.

Connect 4In 2017 I want to start a side project for a few reasons. I want to improve my coding skills and look at things I wouldn’t normally during my day job.

I have been trying to decide what to build. The actual project doesn’t matter too much, it is the techniques I use during build that matters the most. I would like something that I can start off as a windows app and then extend onto the web or mobile apps.

I started off thinking about a Rubik’s cube app, however my initial coding has lead me to believe it is probably too complex for my first app.

Last year I spent an evening looking at Connect 4 during a York Code Dojo session. I think this should be complex enough that I can code some logic to efficiently solve the game, however not too complex I get defeated before building too much.

So far I have built a console app that displays via Console.Write() commands, a grid to represent the game, with 0 meaning empty, 1 red and 2 yellow etc. I am currently working on the logic to solve the game, once I have that in a good state I can extend into a winforms app, into a web (MVC most likely) app and finally a mobile app (I have no knowledge about how to do this yet, but something I would like to try one day).

Over the last few days I listened to .NetRocks where they discussed Progressive Web Apps. This sounds like a great challenge for me to aim for. A progressive Web App is a website that automatically detects various properties to give you an app that runs well whatever the state of your internet connection and whatever browser you are in.

I have lots to learn but I can split it down into small sections and I can build something that demonstrates some of my skills.

Model View Controller (MVC)

MVCModel View Controller or MVC is a software architectural pattern for implementing user interfaces on computers. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.

I have been trying to get my head around the concept of MVC for a while, hopefully writing this article will help solidify my understanding of it.

One of the core concepts of MVC is the ability to separate concerns so you can concentrate your energies on one aspect of the application.

Model This is the data. If your application uses a database the model often mirrors what you have in the database and concerns itself retrieving information from the database.

View This concerns itself with displaying the data to the user. Typically this is the html pages of your application.

Controller This concerns itself with actually doing things and deals with user interaction. Typically it will get data from the view and send data to the model.

The three concerns can be developed in isolation as they do not depend on each other, for larger development teams you can even divide up development much easier that a traditional app.

The basic concept of MVC I get and understand, however I find myself getting bogged down in the details.

The database doesn’t matter. I need to remember this and not get sidetracked in writing custom methods to connect to the database which end up unmanageable. I know SQL, so can easily write SQL commands to copy data into the format I need for my app. The app I am currently working on involves a large amount of existing data, and I need to concentrate on the MVC parts and worry about the database later.

In previous attempts I have tried to build my model against many tables, but instead I can write a query against many tables and insert that into one table which the Model can then use.

Changing the model often results in an error informing you that the context has changed since the database was created. The easy solution to this in my case is to drop the database and allow entity framework to recreate the database each time. As long as my database contains no new data, I won’t loose anything.

One of the core advantages of MVC is the ability to test it or even use test driven development (TDD). I haven’t really dabbled with testing yet as I am still trying to get my head around the fundamentals, but once I have made some progress with my app I want to test, so next time I get asked to add a new feature I have no fear about breaking stuff.

For the first time I have got an app with a working Authentication system from the start. And it is remarkably easy to implement with one keyword. Adding [Authorize] to the top of your controller is all that is needed. Building the actual Authentication system is relatively easy from Visual Studio, as it has templates for Azure AD, Forms Based, Open Auth like google/twitter etc.

It is still very early days for my MVC app and my understanding of it, but I feel I have turned the corner and can actually build something with it now, rather than be stuck in a downward spiral of confusion.

What do you think about MVC why not leave a comment below? For more info about MVC I have been looking at http://www.asp.net/mvc which has more information and tutorials.

Coding myself into a corner

coding myself into a cornerI spend an awful lot of my working life adding new features and improvements to a legacy database system.

A legacy system is an old method, technology, computer system, or application program, “of, relating to, or being a previous or outdated computer system.” Often a pejorative term, referencing a system as “legacy” often implies that the system is out of date or in need of replacement.

My particular legacy system is Microsoft Access. We use Microsoft Access to provide the front end for all our internal databases. The particular technology we use is ADP files which are only supported in Access 2000, 2003 or 2010.

Microsoft has already dropped support for Access 2000 and 2003, and support for 2010 is due to be dropped in 2020.

So why am I coding myself into a corner? Its simple for every feature or improvement I create in Access, I increase the amount of features I need to create or port to a new front end.

This is a very depressing thought, everything I create will need creating again. I am not saving myself work but increasing the amount of work I need to do again.

The bad news is that my employers like almost all businesses demand results and like a good employee I have been delivering them. I have been promised the mythical “when we are quiet” you can work on rebuilding the database front end. I know this will likely never happen so what are my options.

Do nothing I have warned my managers that this work needs doing and it is up to them to give me the resources I need. This is not an acceptable option. Firstly I am not future proofing the business, 2020 will be here before we know it. Also I am not developing myself as a developer, as the only experience I am getting is with Legacy technology that has expired or will do very soon. No one wants to employ someone who only has legacy experience.

Do something I need to keep delivering results and doing what is asked of me. Like any good engineer I should be multiplying my estimates by four, meaning that I have some time that can be used for looking at the bigger picture. This is a win-win option really. Employer gets a solution that is future proof, Employee gets valuable experience in up to date technology.

What do you think? Have you been tied to legacy technology? Why not leave a comment below.

The Christmas count down with code

In December we count down the days to Christmas. People often have advent calendars filled with chocolates or even Lego.

But what about if you are a programmer, how can you count down the days till Christmas? What about if you had a daily Christmas themed coding challenge? Well www.adventofcode.com is the answer.

Christmas coding challenges

Each day a new challenge is available. So far the challenges are related to Christmas and Santa delivering his presents. The challenge is split into two closely linked parts. You are given a randomly generated input and your need to give an answer using a short string or number.

The challenges are getting harder, with some completely defeating me, (not surprising with my limited programming knowledge). The challenges are language independent so you could try them in javascript or c#. I have been using Visual Studio and C# and my code is viewable on github.

So far I have completed Challenges 1 to 6 and also 10. Partly because I found challenge 7 very difficult but I am hoping to have another go at it.

While coding through these challenges I have done a fair amount of refactoring. I started off with a simple console app with most of my code in one method. As the number of challenges increased I started moving the code for each challenge into its own class, with methods and properties that were unique to the challenge. I also added a main menu so you can choose which challenge to run. Some of my code to answer the challenges takes some time to run so this was quite a time saver over running each challenge in order.

These challenges are very good at teaching me things about coding. I have got to think about data structures, what is the best way to store this information, classes and methods and return types, how to output data to the screen, how to input/import data.

Before I try and work on the next challenge lets have a look at the first challenge:

Santa is trying to deliver presents in a large apartment building, but he can’t find the right floor – the directions he got are a little confusing. He starts on the ground floor (floor 0) and then follows the instructions one character at a time.

An opening parenthesis, (, means he should go up one floor, and a closing parenthesis, ), means he should go down one floor.

This is a simple loop through a long string of ( and ) and keep track of the floor number you are on to calculate what floor Santa finishes on. The second part of the challenge asks at what point in your input string does santa reach the basement (floor -1)

Due Dates

HTML for Babies Due DatesAs I write this I have less than 2 days until the due date for the birth of my first child.

Its a very exciting time, but it is also infuriating waiting for it to arrive. Even in the 21st century science can not predict with any accuracy when a baby is going to arrive and we just have to wait for mother nature to do its thing.

I feel like I am stuck in limbo at the moment I have lots of work to do, lots of development changes to do on the databases, but I also know that at a moments notice I need to drop what I am doing and try and be a father.

Due dates for babies is based on average pregnancies lasting 40 weeks, but there is no such thing as an average pregnancy. But to keep this blog post on topic I somehow need to compare due dates for pregnancy with software development.

In software development we often get asked for estimates on when a particular development task will be finished. Estimates in software development are very difficult to make accurate as there are so many variables that you do not know the answer to until you start getting stuck into doing the work. One technique is to try and split the work down into small steps and estimate how long each small step will take and then add them all together. But even this technique still has a large margin of error.

What would it be like if when management asked we gave an estimate similar to what pregnant women receive? Instead of a deadline when all work has to be finished by, you have a date when there is a 50% chance of the work being finished.

I think management would have a difficult time dealing with this amount of uncertainty, I certainly am waiting for this baby to arrive.