Contents

Using the Command Prompt

After Kata 1, you’ve become a pro at using the Command Prompt. You’re almost ready to start programming for real.

However, before we start, let’s discuss exactly what we mean by ‘computer programming’.

Programming languages

Computers can’t understand human languages, which is a bit of a problem for us - how do we get computers to do what we want them to do?

In order to communicate with a computer we have to use a specific language that the computer can understand. Such languages are called ‘programming languages’.

Programming languages are instructional - they tell the computer exactly what to do and when to do it. Someone who writes in a programming language is a ‘computer programmer’, and the script written by a computer programmer is called a ‘computer program’.

You can also use the word ‘code’ as an alternative to ‘program’, as in ‘coding language’, ‘computer code’, and so on.

Like any human language, programming languages require text to be written in a certain way, abiding by specific rules. These rules are known as the ‘syntax’ of a language. Remember the cd command from Kata 1? If you type:

cd ..

That’s fine, but if you wrote:

cd . .

The computer might not understand what you are trying to tell it to do. This is because the second example breaks the syntax of the language. Even the smallest difference, such as including an extra space between the two dots, can cause the program to fail.

A simple program written in a made-up programming language might look like this:

If Today is Saturday or Sunday Then
    Output 'Go to sleep!'
Else
    Output 'Go to work!'

Now this is a little unnatural to read, but hopefully you can follow the logic. The top line checks what day it is. If it’s a weekend we output a message telling the user to sleep, otherwise we tell them to go to work.

Notice also that the code is read from top to bottom. In a computer program, instructions are always executed sequentially - that is, one after another.

Most computer programs are written in a similar way to this example. However they can be made up of thousands, hundred thousands, maybe even millions of lines of code!

Compilation

In order for a program written in a programming language to run on a computer, it needs to be converted into something the computer can understand. This process called ‘compilation’. The compilation process is performed by special computer programs called ‘compilers’.

You may be thinking, ‘but I thought the computer could already understand programming languages - why do we need a compiler to make a program run?’ Good question! It’s because, at their most fundamental level, computers can only perform a (relatively) small set of instructions, known as an ‘instruction set’. The instruction set is defined by the physical parts that make up a computer, known as the ‘hardware’.

A compiler takes a program written in a programming language, and turns it into a new program made up of instructions that match what is in the computer’s instruction set - known as ‘machine code’. Now it’s actually the machine code that the computer can truly ‘understand’. Once a computer program has been compiled into machine code, it can be run, or ‘executed’ on your computer.

Many programs on your computer are already in an executable format, like your web browser, or word processing software. As it turns out, programs written in programming languages generally aren’t executable straight away. They must be compiled into an executable format in order to run them.

Fortunately, most computer programmers rarely need to think about the gory guts of computer hardware, compilation, and so on - we just focus on writing code in a programming language and let the compiler do the heavy lifting for us.

Hello C#!

The programming language we’re going to be using in this book is called C# - pronounced ‘See - Sharp’. This is a riff on the concept of ‘sharps’ and ‘flats’ in music theory. A ‘sharp’ note is considered to be a a semi-tone higher in pitch than the original. So ‘C#’ is like the note ‘C’, but a bit higher in pitch.

This might seem a bit random, and quite frankly, it is! C# is actually named like this because it’s sort of designed to be a more advanced version of an old programming language called ‘C’. As far as the world of computing is concerned, C is ancient - over 4 decades old! Yet despite it’s age, C is still heavily used for many computer systems.

C# came on the scene in 2001 - so a relative newcomer compared to C. It is a language developed by Microsoft, and has skyrocketed in popularity since it’s launch. Microsoft have developed C# into a sort of ‘jack-of-all-trades’ programming language. With C#, you can write desktop applications, computer games, mobile applications, web server software, and many other things.

.Net Core

The specific ‘flavor’ of C# that we’ll use first is based on something called ‘.NET Core’. This is another Microsoft technology that allows you to compile C# programs that can be run on Windows, Linux, Mac OS, and even mobile devices.

So, C# is a good programming language to get your feet wet with! Once you understand it, you’re in a good position to start developing all sorts of computer applications.

Taking on the Code Katas

We’re about to start Kata 2 - which is the first Kata where we’ll look at C#. Before you start, it’s important to briefly discuss how best to work through the Katas.

Pair programming

As mentioned earlier, I recommend completing the Code Katas with a friend if possible. To make this style of working most effective, I recommend following a few rules.

When you try the Code Katas in a pair, each person should take on one of two distinct roles, the Driver and the Navigator.

The Driver is responsible for writing the code. They have control of the keyboard and mouse at all times. However that doesn’t mean they do all the work!

This is because the Navigator is responsible for being the brains of the pair. They have to direct the Driver as to what code to write.

So, a pair might start by reading through the first part of the Kata instructions. The Driver then prepares the text editor, whilst the Navigator reads through the Kata instructions once more. The Navigator then tells the driver what code to write, pointing out what the Kata instructions say. The Driver then writes the code, whilst the Navigator double checks what the Driver is writing.

Both the Driver and the Navigator are active - both should be thinking aloud about what they’re doing, and communicating with each other. When done correctly, pair programming should be more engaging and thoughtful than working through things by yourself.

The Driver and Navigator should swap every so often - perhaps every 10 minutes or so. This is to ensure both are learning new skills, and to prevent each person in the pair becoming complacent about their role.

Before you start, discuss with your pair partner who would like to take on each role first.

As an aside, the process I’ve just described is actually a simplified version of Extreme Programming, which admittedly sounds like a joke from a bad Sci-Fi movie! Actually, Extreme Programming, or XP, is becoming increasingly common in the software world, so it’s good to get used to it now if you’d like a career as a software engineer!

Now we’ve covered that, it’s time to start Kata 2…

Copyright Mikiel Agutu 2019