So, you want to learn to code? Part 1

To be honest, I’m quite sick of videos when it comes to learning things. Everything is either ten minutes or more, measured sufficient to the advertisement algorithms and filled out with high energy fluff about liking, subscribing, the channel and an immensely overstaying-its-welcome intro. I guess I’m old fashioned.

Let’s get to the point. Programming isn’t that hard, but it is something you have to learn all the way through. There are way harder things related to software development than programming, which is why impostor syndrome, in all of its iterations, is very present in the field. The main difference between a seasoned developer, who is in their own words, “not that good at math”, and a beginner who can carve an advanced algorithm in one line or do another singular feat is: only one of them can ship a software product and only one of them thinks they are a good programmer. That is not the same person.

Baby steps

So, let’s start out. The first thing you need to do is to find something to program with. Preferably something with minimal configuration and minimal tool learning.

We’ll be using C#, because that’s what Unity games use. Dotnetfiddle is a perfectly sufficient in-browser editor, so we can open that in another tab for now.

I will do something wildly different than what programming tutorials usually do and explain everything you see in a code block without needing to just memorize something that seems like it’s written in an alien language and is Just Something You Need To Write.

This might make it look overtly complex at the beginning, but you won’t be needing to do classes just yet. It’s important to know what they are so you understand the structure of the language better and how it’s all based on classes, namespaces, methods and properties.

Classes

Let’s start out with objects. Don’t open Dotnetfiddle yet.

public class Parent {
   private class Child {
   }
   public class Sibling {
   }
}

In C#, objects are called classes. If they are public, other objects can access them. If they are private, only the code inside the parent can access it.

The code is held inside brackets and their hierarchy is made more easily readable by indenting them with tab. Lines always end in semicolons. You won’t need a semicolon after a bracket.

using Parent;

Using means that you can access all the public classes inside the Parent class, which means Child class is not accessible, but the Sibling class is.

IF YOU ARE SKIMMING, PLEASE STOP IT

This is a friendly reminder that you should read the text instead of just skimming and skipping to the code parts. If you don’t read it, you will most likely learn nothing.

Let’s go to static classes. Static classes just are and you can call the code that’s inside of them without making an instance of them. Let’s check a few other basic things out as well.

/* this is a comment block. It won't be compiled in the code and it serves for the programmers to understand the logic. It needs a start point and an end point which are written with an asterisk and slash like in this example. */

public static class Helper {
   //this is a single line comment. It is defined with double slashes in C#
}

Variables and functions

These classes won’t do anything, though. They need two things. Variables and functions. Variables store a value inside of them and they are also objects. Let’s start with integers, strings, floats and booleans.

int firstVariable = 2; //integer is a number, no decimals. Good for indexes
string secondVariable = "Hello world"; //a string of text. Inside double quotes.
float thirdVariable = 0.23f; //a number with decimals
bool fourthVariable = true; //a boolean value. Can be true or false

Variables can also be functions. Functions are blocks of logic that return something or not. If they don’t they are called a void function. Functions also have parentheses to determine what variables they need to run. Namespaces work like classes but work more as something to sort and separate classes from each other.

namespace Helpers {
  public static class CounterObject {
    //value counter of the counter object
    public int Counter = 0;

    //adds addToCounter into counter.
    public static void VoidFunction (int addToCounter) {
      //there is a shorthand way to do this but let's do it like this for now.
      counter = counter + addToCounter;
    }
  }
}

The class in itself doesn’t do anything just yet. You have to call it.

//we'll need this to use the helpers static classes.
using Helpers;

//let's make a class called Program
public class Program {
//let's initialize the result variable first. It's 0 now.
int result = 0;

  public void Main () {
    /*call the code inside a function like this. Now you enter a number
    (defined in the class) into the parentheses:*/

    CounterObject.VoidFunction(4);
    CounterObject.VoidFunction(12);

    result = CounterObject.Counter;
    //result is 16
  }
}

After all of this, you’re ready to look at the hello world code which is by default in the Dotnetfiddle tab we opened earlier.

using System;
					
public class Program
{
	public static void Main()
	{
		Console.WriteLine("Hello World");
	}
}

What we see here is a class called Program with a function inside called Main, just like there is earlier. It doesn’t return anything but the fiddle is configured to run a public Main function inside a public Program class. It’s using System, which is a namespace that holds the Console class.

The Console class has a function called WriteLine, which prints out the string that you put inside the parentheses and the double quotes, which in this case is “Hello World”. You won’t need to write on the dotnetfiddle in this part yet, but it’s good to get acquainted with.

Assignment

So, we haven’t coded just yet. You can start out with Microsoft’s own simple tutorial to get acquainted with everything we’ll be moving on to in the next part. First of all, go easy on yourself. Don’t expect to understand everything in here after the first time you read it. We all have different brains and there are lots of overconfident and destructive software engineers out who understand everything the first time they see it, but also innovative and groundbreaking software leads and architects who started out by understanding absolutely nothing of basic programming concepts.

Microsoft dotnet browser tutorial part 1