Sunday, November 8, 2015

What is Coding?

A friend had a request: to answer the question "What is coding?" This post is here to answer that question. The pedantic answer is that coding is the act of writing code. Which doesn't answer much, aside from creating the question "Then what is code?".  Code is a set of instructions for computers or programs to run. Think of a cooking recipe, but for computers. The computer runs the code step by step, and it's this code that enables our computers to be as useful as they are.

At its heart, a computer has a very simple instruction set, from which we can do very complicated things. After all, a computer is little more than a calculator. Most of the functions it can do consist of reading and writing memory, performing simple boolean math, and perform actions based on comparisons. Getting something useful out of that requires clever usage of numbers, or using lots of simple actions to create something much more complex. Displaying an image on the screen, for example, involves writing the color value of each pixel in memory. Clever, but simple use of numbers to create something useful.

While the process of coding involves creating those simple instructions for the computer to read, almost all actual coding is done using higher level language that then creates the simpler code. The more control I want over what actually happens, the closer the code becomes to machine language. Usually though, it's simple and quicker to write code the further away from machine language it gets. This means in part that some code can look like I'm writing actual English, while lower level code will look like I'm writing gibberish. For example, see if you can understand this:

Console.WriteLine("Please enter your age:");
int age = Console.ReadLine();
if (age > 18)
              Console.WriteLine("Enjoy your drink!");
              Console.WriteLine("Here's some milk for you kid.");

This is code that would actually work in a program, to do what you think it does. A simple console prompt, enter a number, and output a sentence based on what you wrote. The code itself makes heavy use of functions in order to reuse code and make for easier to read code. If you want, think of the recipe example from earlier. When it tells you to preheat the oven, does it tell you how to preheat the oven? No, it tells you the relevant command (Preheat the oven) and gives you an relevant data in order to follow that command (the temp to set it at). Functions work similarly in code. Here, WriteLine is a function that prints the input, the stuff within the parentheses. Easy, simple, and an example of how coding becomes easier as time goes on and people add on shared functions.

There's a whole slew of other coding strategies that are used to save time and make the job easier, but I wanted to give at least one simple example, but won't go into more depth. But coding itself may look different based on which language you're using. This type makes hefty use of brackets in order to split code. Another that I'm familiar with uses parentheses for everything, while another uses tabs as part of the actual code. Another requires as part of the code that each line starts with a number, and that each number increases in value from one step to the next. They all look different, but each involve writing out instructions in order for the computer to run something more complex. This is coding.

Perhaps you might also want to know what coding is, by looking at what is not coding. A markup language like HTML is not coding. While it has some crazy symbols that we don't normally use in our language like "<", this does not make it coding. There's no series of instructions in an html page. Instead, a page consists of content, where it is marked up in a way to indicate to the computer how things should look. A CSS style sheet is similar, and involves a computer merging a given html page with the information in a CSS style sheet in order to determine how things work. Again, no series of instructions, but content.

No comments:

Post a Comment