Sunday, December 6, 2020

Before You Learn To Code - Part I

Foundational Concepts of Programming

Being able to code is an exceptionally useful skill, but learning that first language can be challenging.  Generally the first step to learning to code is finding a tutorial, opening an editor and start coding.  I understand and sympathize with this instinct entirely, but I believe there are some important concepts everyone should understand before learning to code.

One challenge when learning programming is the foundational knowledge that in some cases is assumed. By understanding these concepts your ability to learn to code will be much easier and more productive.

Concept #1 : type

To understand how something behaves and how something can be interacted with, you must understand its type.  As an example, let's take a cup. 


Something that has the type of cup tells you actions you can take with it.
  •   I can fill a cup.  
  •   I can empty a cup.
This really simple concept is an essential foundation of programming.  Think of all the different cups you have seen in your life; with handles, without handles, big, small, glass, ceramic, wood, and thousands of other varieties. You know how to interact with everyone of those cups because you know its type is a cup.

Here are some of the foundational types that are included in all programming languages:
  • int - Number without a decimal place
  • float - Number with a decimal place
  • char - A single character
  • string - Multiple characters

Concept #2 : value


The concept of type is a general one while value is a specific concept.  A value has a type.  I say cup and you, knowing the type cup, can envision a conceptual cup in your mind.   I say here is your coffee in my Baby Yoda coffee cup.  That is no longer a conceptual general cup.  That is a very specific cup.


Think of the object in your hand as a value with type cup.  If this seems a little confusing, hopefully the next concept will start making things clearer.

Here are some values with types found in all programming languages.
  • 5 is a value with type int
  • 26.8 is a value with type float
  • c is a value with type character
  • hello  is a value with type string

Concept #3 : variable

A variable is a name with a type and a value.  You express actions when programming using the names of variables.  So let's define a variable with type cup which refers to the value of the Baby Yoda mug.  The name of the variable is yourBabyYodaMug.

Now with yourBabyYodaMug variable which is of type cup your program can take actions on the value Baby Yoda mug.  Hopefully these kind of contrived descriptions start give you a understanding of the foundational concepts. 

All programming languages have ways to define a variable. Some languages require you to declare the type and name of a variable:

int myInteger

type variable

In these languages requiring variables to be declared with type, those variables can only hold values with the type defined.

Other languages have ways of just declaring variables with just a name:

myInteger

variable

In those languages, only requiring variables to be declared with just a name, then the type of the variable is defined by the type of the value the variable refers to.

Concept #4 : assignment

Variables are only useful when they refer to a value.  A variable refers to a value through the action of assignmentAssignment is generally communicated by using the equal symbol =, with a variable left of the = and a value to the right of the =.

int      myInteger           =     5

type   variable     assignment     value

This code describes a variable with the name myInteger with type int, is assigned to the value 5 which has a type of int.  An important point is the type of the variable and the type of the value is the same.

Thank you for taking the time to read Part 1.  I will describe a few more important concepts in Part 2, scope, functions and references.

Before You Learn To Code - Part II

 More Foundational Concepts Of Programming In  Part I we covered type, value, variable and assignment.  Please read Part I before reading t...