Kinnu

Coding skills

Introduction to Coding

What is coding?

Whatever a Backend Developer is working on, one thing is central to everything they do, and that's the ability to code.

Computer code. Image: Lionel Rowe, CC0/Public Domain, <https://creativecommons.org/share-your-work/public-domain/cc0/> via Wikimedia Commons

Coding is the process of instructing a computer to perform specific tasks. These instructions are delivered through a terminal, also known as a command line interface (CLI) – you can think of it like a messaging app that lets you talk to your computer directly.

A terminal is available on any normal laptop, but most of us never have a reason to use it. We interact with our computer using icons and menus, otherwise known as the graphical user interface (GUI). But the GUI can be too limited for the needs of a Backend Developer. They need a terminal, because it lets them deliver specific, code-based commands.

When writing lots of code at once, a developer can also use an Integrated Development Environment (IDE). This is similar to a word processor, but tailored specifically for writing code. It’s easier to use an IDE than it is to use a terminal directly.

Choosing a language

Backend Developers need a strong understanding of at least one programming language. However, they often use multiple languages over the course of their professional career. This not only broadens their skill set, but also makes them more versatile and adaptable to new projects and requirements.

For anyone new to backend development, it's a good idea to start with a beginner-friendly programming language such as JavaScript. These languages are not only easier to learn, but also have large communities and extensive resources that provide support and guidance along the way.

Another example is Python, which is becoming the go to language for Machine Learning and Deep Learning. Ruby is another common language, known for its focus on developer happiness and productivity.

When choosing a language, it's important to consider the type of project, the size of the language's community, and how much you enjoy coding in it. If a backend developer has a dream employer in mind, they can also check which languages they prefer to work with. For example, Facebook famously uses Hack, a programming language they created themselves.

Syntax

Every programming language has its own set of syntax – that's a set of rules that define how the language should be structured. Think of it like grammar in human language: “Dinner? ready is” doesn’t make sense. In the exact same way, a programming language won't make sense to a computer if syntax isn't used correctly.

Let’s use Python as an example. This language’s syntax dictates that every parenthesis has a pair. This code would lead to an error message – print("Hello World!" – because the parenthesis is missing its pair.

But if this code was rewritten with the correct syntax – print("Hello World!") – it would make sense to the computer, and the words Hello World! would appear in the terminal window.

Hello World. Image: Shaddim, Public domain, via Wikimedia Commons

Remember, this example is specific to Python. Other languages have different sets of rules.

Core Programming Concepts

Variables

Just like syntax, variables are an important part of coding. A variable is a kind of placeholder – you can think of it like a sign that represents a piece of data.

For example, a developer might use 'pi' as a placeholder for a complicated number like '3.14159'. After setting this variable, the developer can use 'pi' while writing their code, and the computer will know that the letters represent the number. This is a lot more efficient than typing the number every time, especially if it appears in the code on multiple occasions.

Variables can represent many types of data, including strings of text ("Hello World!"), integers (1, 2, 3), floating point numbers (3.14, 10.2), or booleans (true, false).

Using Python as an example, a developer could set a new variable – b = "Banana". They could then give the computer a command – print(b) – and the word Banana would appear in the terminal window.

Data structures

Variables become even more powerful when you start incorporating different data structures – these are specialized formats that a developer can use to store a number of variables at once.

Lists are ordered collections of items, which on Python, might look something like this: fruits = ["apple", "banana", "orange", "pear"]. If this list was set up for a grocery store, the computer could track all the fruits available, and share this information with a user. For example, the computer could print the entire list, or just one specific item.

Often programming languages will use zero to represent the first element in an array; this is known as a zero-based index. The command print(fruits[0]) would get the computer to print the first item: apple. The command print(fruits[1]) would print the second item, banana, and so on.

Dictionaries, meanwhile, store data in key-value pairs, like "fruit": "banana", "price": 0.45, and "units": 126. After a dictionary is set up, the computer can start retrieving data from it, checking things like a store's current price for a single banana, and how many bananas they currently have in stock. Again, this information could be shared with users, and form a crucial part of an online grocery store's backend.

Conditionals

Backend development really starts cooking when you incorporate conditional statements. These use commands like if and else to let a computer make branching decisions, often in combination with comparison operators like equal to (==), not equal to (!=), greater than (>), and less than (<). Using Python, we can see an example of this:

if banana["units"] > 0

print("Would you like to buy a banana?")

else:

print("Bananas out of stock.")

Conditional statements can also be used to check things like a user's password. If they enter their password correctly, they can access to their profile, else a message is printed: Access to bananas denied.

If-else flowchart. Image: Snubcube, CC BY-SA 3.0 <http://creativecommons.org/licenses/by-sa/3.0/>, via Wikimedia Commons

Advanced Programming Techniques

Loops

Loops let developers write a piece of code once, then have it executed over and over again until a given condition has been met. This can save a lot of time, help to automate repetitive tasks, and provide a method for interpreting lots of structured data.

For example, you might have a list for every aisle in a gardening store. Each list contains all the products which can be found on that particular aisle: Aisle1 = "pots", “baskets”, "troughs", Aisle2 = "rakes", "shovels", "shears", and so on.

A user might want to find out which aisle has watering cans. Instead of manually searching for the “watering cans” variable in each list individually, a loop could be used to automatically check them one by one. When it finds the variable it’s looking for, it stops searching and prints: You’ll find watering cans in Aisle 4.

Functions

Functions are pre-packaged sets of instructions that developers can define and reuse in their code. Basically, a developer can write a complicated block of code, give it a name, and then call that block when they need it.

Imagine you have a clothing store, and you want to offer a deal to every customer who happens to buy a tophat. Instead of writing the same code to check for tophats every single time a customer checks out, you can create a block of code which you define (‘def’) as tophat_deal:

def tophat_deal:

if "top hat" in customer.cart

print("Congratulations!")

else:

print("Are you ready to pay?")

Instead of running this entire block of code whenever a customer checks out, a developer could call the tophat_deal function, which performs all the steps automatically. Functions save time, and make a developer’s code more organized and easy to maintain.