C# Coding tests.
Over the past couple of years testing prior to interview for
roles has become more prevalent. This
has resulted in some interesting anomalies, most notably of how much of the
question is open to interpretation.
Simple multiple choice test only test the knowledge that you have at
your fingertips, and never the breadth and depth of understanding of that
knowledge. Similarly, essay type scenario tests asking you to build a system
based on some given facts, always miss vital parts or are open to interpretation.
This is about the essay type question, in a normal requirements
gathering phase of a project any anomalies, missing parts or clarifications can
be ironed out at the start. If an Agile
process is being used then questions and clarifications can happen at any time.
Let’s examine a typical essay type scenario;
An object is moving
across a 10 x 10 grid and you need to work out its final location. Using a web service you will be provided with
the movements of the object, Forward, Left (90 degrees) or Right(90 degrees).
Each step is a single move. After the
first move the object is in position 1,0.
Once you have the location and final destination send this via web
service.
If we examine this a bit closer, in other words the
requirements gathering, and see if we have all the pieces to create a system.
An object is moving
across a 10 x 10 grid. How is this
marked, 0 to 9 across the x and y axis, -4 to +5, mixture of both and do we
need to care? If we are given a location
and movement then we need to know the reference points. We can assume, as it is fairly common, that
it would be 0 to 9. Then we have the to
decide where 0,0 is. If we are told we
can turn left or right and we start with 0,0 at the bottom left this would be
completely different to stating at top left or bottom right. Now the assumptions become a little more difficult. Mathematically, you could assume the 0,0
would be bottom left as in most graphs.
However, if you are from a HTML5 canvas background where would you say
0,0 would be. What about windows forms
or apple ios, android Windows 8 mobile?
Movements of the
object, Forward, Left (90 degrees) or Right(90 degrees). Each step is a single
move. Not too difficult at first glance, but does this mean the object should
just turn 90 and not move or turn and move?
Anyone ever played asteroids on the old Atari, I was in the navy in the
eighties and this caused me to miss a lot of dates! If we look at doing a Forward Left Right,
does this mean that we have only moved one grid or three. After years of asteroids I would assume one
grid move many might assume three.
After the first move
the object is in position 1,0. There
are two problems which we need to overcome with this statement. Firstly, which grid did if move from? It would be easy to assume 0, 0, but what if
it was 2,0 or 1,1. We know it only moves
one grid per step, and we have assumed that a left or right is a turn not a
move. If we have made other assumptions,
starting at bottom left of a 0-9 grid with x on the vertical axis and y on the
horizontal axis. Then moving from 0,0 to
1,0 turn left then forward would now mean our object would be in 1,-1 and as
there is no -1 on the grid do we just assume that we stay at 0?
Let’s move onto the coding style.
One thing I try and teach junior developers
is that there is more than one way to write and piece of code, however, consistency
is the key. Not just consistency in how
we individually code but in the way we code as a team. I’ve had enough experience to know that in
every project something will go wrong!
If it is all done the same way then at least the fix should be
easier. There are some principals which
are always good to follow, and I will cover this in a few moments, but this is entirely
down to the company and the team. Each
company, especially if using a process, should be following a set of guidelines. Now just the ones similar to Microsoft’s
best practices or SOLID
principals but ones that have been adapted to suit the requirements of the
business.
When an essay test is provided it rarely comes with the
companies coding principals, leaving it to the whim of the marker to decide if
his principals are better than yours so all you can do is follow your instinct,
training and skill – follow both the Microsoft best practice and SOLID principals,
throw in a bit of defensive programming and hope the person on the other end is
looking for breadth and skill of an developer rather than someone who ticks
boxes. This is always going to be the
difficult bit as the feedback from the company will never provide the solution
they were looking for as a comparison tool.
Let me ask a few questions;
1)
Would you make a Console application, web
application, widows application, class library or mix?
2)
What assumptions would you make?
3)
What would your design look like, not the code,
just the design?
No comments:
Post a Comment