What is a Program?

What is a Program?

We’re going to look at some rather interesting stuff today. If you’ve read my other posts you’ve probably been thinking “When are we going to start coding dude?” but I wanted to give you at least a small introduction to the larger picture before getting stuck into actually writing any code, don’t worry though we’ll be looking into that shortly

So today I wanted to take the time to look at What a Program is (see What is Computer Software? for more information) and how we can create them. I hope you enjoy this part of your introduction I know I did quite a few years ago.

What is a Program?

Essentially, a program is just a set of instructions given to a computer to solve some problem or to perform a task. So if we wanted to work out someone’s annual business mileage, we would do the following.

  1. Ask the user “How many miles do you drive for work per day?”.
  2. Wait for the user to provide us with the number of miles.
  3. Store that number in memory using something called a “variable”.
  4. Ask the user “How many days in a year do you work?”.
  5. Wait for the user to provide us with their days.
  6. Store that number in memory using a variable.
  7. Create the user’s mileage by multiplying the number of miles by the number of days, also stored in memory using a variable.
  8. Display the annual mileage to the user on the screen

As a whole, the above steps would be called an algorithm (we’ll be looking at Data Structures and Algorithms in the future). For right now an Algorithm is just a collection of clear logical steps used to solve a problem or to perform a task. As you can see we perform the above steps in the order given and we will get the output we expect, while some elements could be rearranged we can’t perform steps 7 and 8 before steps 1-6.

One thing we must be absolutely clear about is that a computer does ONLY what we tell it to do, unlike us (humans) it does not interpret the meaning of things, it does exactly what it is told to do. So how do we use the above steps to tell a computer how exactly to do what we want, there are a few steps involved:

  • The first is we need to use is a programming language to put our intent into a human-readable format using code
  • The next is to convert out intent into a format the computer can interpret
    • This has several steps:
      • In some languages, we turn it into something called object code
      • Then we convert the object code into a machine-readable language, 0s and 1s called binary or machine code.

What is a Programming Language?

A programming language is just a way in which a human can provide their intentions to a computer. We have two categories of languages that we use:

  • Low-level
    • This language category resembles something closer to Machine Language
  • High-level
    • These languages resemble something closer to a human language

Low-Level Languages

We won’t be looking into these languages (for now at least anyway) but as mentioned these languages tend to resemble Machine Language and for a lot of your programming tasks won’t be something you need to have a great understanding of. Having said that it doesn’t hurt to have a quite overview.

Depending on how low into the Low-level category we are, the code itself may run directly on the computer, being executed by the CPU (check out my post on Computer Hardware if you haven’t already), and this would be called Machine Code, there are some further steps such as Microcode, I won’t be going into that but feel free to check out google if you’re interested.

We also have Assembly Language, this is classed as any low-level language that has a strong relationship with a program and the machine code instructions. As mentioned, I don’t intend to look at this in much more detail but we’ll see how things go.

High-Level Languages

Now that we’ve had a, very brief, look at Low-level languages lets check out some more high-level stuff. There are a lot of high-level languages that have been developed over the years and we’ll discuss the differences between the language types later:

Language Description
C A general purpose language. Developed by Dennis Ritchie for Bell Labs between 1969 and 1973. Many languages are related in some way to C.
C++ A general purpose language and based on the C language. Developed by Bjarne Stroustrup in 1979 to add “classes” to C. We’ll check out classes in a later post.
C# A general purpose language and is part of the C family of languages. Developed by Microsoft and used with the .NET platform.
Java A general purpose language developed by Sun Microsystems and now owned by Oracle. This language is not linked to JavaScript
JavaScript A general purpose interpreted language and is one of the core technologies involved in the World Wide Web. Originally designed by Brendan Eich at Netscape. This language is not linked to Java.
Visual Basic An event-driven Windows-based programming language used to create applications quickly. Developed by Microsoft and used in the .NET platform.
ADA A general purpose language used predominately within the defence and aviation sectors. Named after Augusta Ada the Countess of Lovelace who is regarded as the first programmer.  Developed by the US Department of Defense in the 1970s
Ruby A general purpose interpreted language quite popular with programs running on web servers. Developed by Yukihiro “Matz” Matsumoto in the mid-1990s.
Python A general purpose interpreted programming language. Quite popular in commercial and academic domains. Developed by Guido van Rossum in 1990.

High-level languages allow humans to provide instructions to computers in a format that we find easier to associate with a written language, such as English, which is considered the universal language of software development with almost all code being written using English text. I’ll be primarily using C# and C++ through my posts but may occasionally use Python, Java, and JavaScript just to add some variety to life.

Ok, so we’ve seen some information on low-level and high-level programming languages but what exactly is involved in creating a program. Let’s take a look:

Most programming languages have a lot of similarities:

Language Component Description
Key Words Keywords can only be used for specific purposes, they are words defined as part of the language and have a special meaning. They are also called Reserved Words.
Developer Defined Identifiers These are symbolic identifiers defined by the developer of the program. 
Punctuation Punctuation is used to identify the beginning and end of statements or separate items.
Operators Operators are used to perform actions on pieces of data known as Operands
Syntax Syntax defines the rules that must be followed in order to create a program. The rules determine how the above Keywords, operators, punctuation, and developer-defined identifiers can be used. 

Simple Program: Hello World

So now we’ve got a decent overview of programs and what is involved let’s create a very simple, and pretty standard first, C# program and look at the parts.

namespace WhatIsAProgram
{
  class Program
  {
    static void Main(string[] args)
    {      
      // First assign the text we want to display to a variable
      string outputText = "Hello World";

      // Next use the language provided features to send 
      // our text to the console.
      System.Console.WriteLine(outputText);
    }
  }
}
Key Words:

We have a couple of keywords defined within this simple program including:

namespace, class, static, void, string

These words within C# have special meaning and can only use for that purpose.

namespace

Used to organise code and wraps anything within a namespace removing the risk of conflicting names.

class

Used to create a class, I’ll be putting a post out on object-oriented programming (OOP) so will cover this in more detail, but a class is a blueprint, with state and behaviour, for something we want to represent within our code. Such as a car, person, or book, take a car the state could be speed and mileage and behaviour would be Increase Speed and Increase Mileage.

static

This is a little complicated but static means we are referring to the type and not to an object we’ve created. So if we had multiple objects with a static state, each object would reference the same state. Again, once we’ve done some OOP it should be clearer.

void

We can use blocks of code to perform tasks for us in some cases the code may give us something back and in others, it won’t. Use in this context void keyword tells the program nothing is given back.

string

string is a class, notice we are using string in two places, first at line 5 then at line 8. At line 5 we are saying, this block of code will receive multiple separate strings (defined by the use of []) and in line 8 we are saying I want to create an object and it will be of type string.

Don’t worry too much if a lot of the content here is confusing, as we progress and more of the holes are filled in the concepts will begin to fall into place.
So as described the keywords above have a special meaning and we use them to get specific functionality from the C# programming language.

Developer Defined Identifiers:
This one is a little more straight forward, there are 3 (technically 4) developer defined keywords within our small program. Developer defined identifiers relate to the parts of the component the developer has control over to define the names of such as classes, methods, namespaces, and variables. We can name these almost anything we want EXCEPT for the Keywords mentioned above, the main goal, however, will be to ensure you give them meaningful names but this is a whole other topic that we will be returning to in the future.

WhatIsAProgram

This allows us a means of identifying the name given to the wrapper around our code.

Program

The name given to our class, again keep an eye out for the Object Oriented post and we’ll go into much more detail there, but the use of Program here is simply convention.

outputText

This is the name we’ve given to a variable, think of this as a container which can only hold text and we can identify that container by use of its name. We will be looking at this in more detail shortly.

Additional

Main

The text ‘Main’ identifies the name of something called a method, while method names are developer defined this is a unique case, in C# when we convert our code to be closer to low-level ( this is called ‘compiling’) and usable by the computer that process requires ‘Main’ to be available, for executables, and is used as the entry point of our program. That means every single C# program MUST have a Main method in order for the program to be compiled.

Punctuation:

Nice simple one here, punctuation is simply a means for developers to show the end of a code statement or to identify separations within a list. So in our example lines, 8 and 12 show the use of punctuation in the form of a semicolon, representing the end of those code statements. At the moment it may be confusing because as you can see not every line shows a semicolon but remember they are only used to show the end of a code statement.

Operators:

In our example we only have one operator in use:

=

This is called the assignment operator, it takes the value on the right-hand side and stores it in the left-hand side.
There are many other operators available, (Quick Note: We follow the rules of BODMAS (google for a refresher)):

*

This is called the multiplication operator, it multiplies the two values. Normally used in conjunction with the assignment operators. e.g.

int result = 3 * 4

The value of result would be 12.

/

This is called the division operator, it takes the value on the left and divides it by the value on the right. Normally used in conjunction with the assignment operator. e.g.

int result = 8 / 4

The value of result would be 2.

+

This is called the addition operator, it adds the two values. Normally used in conjunction with the assignment operator. e.g.

int result = 5 + 2

The value of result would be 7.

-

This is called the subtraction operator, it takes the value on the right and subtracts it from the value on the left. Normally used in conjunction with the assignment operator. e.g.

int result = 8 - 3

The value of result would be 5.

We’ve got many more but we’ll look at them in good time.

Syntax: 

So as mentioned the syntax is the rules we must follow in order to create a program. As with natural languages we have rules we must follow in order to create a correctly formatted sentence, the same is true for programming languages. Each programming language has its own sets of rules, much of them shared. Especially with those, I’ll be showing, C++ and C#, and as I post more hopefully these rules will become apparent. We could go through them but I think that would get tiresome quite quickly and we can learn by doing really.

So there we have it a somewhat longer overview of What a Program is than I was expecting however I think this gives us some good details to move forward with. Next up lets setup our machines so we can create some programs…

I welcome feedback, especially at this very early stage, so any improvements you think I can make please get in touch either in a comment below or send me a message and I’ll get back to you.

On the road to MCSA certification…

Been quiet recently because I took a Microsoft exam yesterday, the 483: Programming in C# exam (it went rather well) and I’ve been primarily studying for that.

Good news is I passed it so very happy with that, took me about an hour to get through all the questions which just flew by. That means I’m one exam down on my goal of getting an MCSA certification, though by passing the exam I’ve also received the ‘Microsoft Certified Professional’ certification.

Microsoft, quite nicely, has a decent path system in place and once you’ve completed an exam it shows you the certification options available to you (though I imagine anyone taking these exams will have that decided beforehand anyway). So because I’ve completed the 483 exam I can go onto do the certifications for ‘Universal Windows Platform’ or ‘Web Applications’ with the latter being my initial goal. Though I’m now thinking that as I’ve done some UWP previously, released a few apps to the Windows store (and got a few thousand downloads in total), and recently achieved my Xamarin certification I may aim for both. Mainly because my long term goal is to become very fluent in a variety of Microsoft technologies with the aspiration of getting MCSA and (additional) Xamarin certifications.

The plan now will be to apply my spare time to developing ASP.NET, UWP, and Xamarin skill sets and develop some sites and apps hopefully for clients but there are some ‘internal’ projects I want to do so looking forward to getting stuck into those.

If anyone is considering it I’d certainly suggest you give it a go, the exam was about £113 and I took out the practice test package which was very useful in giving a general idea of what to expect. Can’t really say much about the exam itself as you sign an NDA about it and best to say nothing in that respect that to tread a fine line. Though feel free to get in touch and I’ll try to give help where possible, as mentioned won’t be talking about the exam specifically though but my prep etc all good.

Just wanted to get the exam details out and to continue getting content done, I’ve got another post due out in the next few days so hopefully, that’ll be of interest.

What is Computer Software?

What is Computer Software?

We’ve had a very brief overview of Computer Hardware if you haven’t checked it out feel free to do so. I thought it would give those with a little more curiosity a starting point and is not required to move forward.

Now then, let’s check out a quick overview of Computer Software before getting stuck into checking out our first programming language.

In order to get our Computer Hardware to do anything useful we MUST have software, it is not optional. As soon as we start the computer, the software kicks in and controls the hardware. In general, we can split software into two separate categories:

    • System Software
    • Application software

System Software

The software that controls or provides access to the hardware and general operations of the computer is called the System Software and can be further broken down into 3 categories

  • Operating System

This category provides the most crucial collection of programs found on a computer. The Operating System provides many services, from controlling the operations of the Computer Hardware, spawns other programs, allows data to be saved and read, and manages connected devices. In the (distant) future I want to provide an Introduction to AOSP, this is looking at the Android Operating System and we will get ourselves a copy, build it for a commercial device, then flash our version of Android to that device, I did this in one of my jobs and it is some seriously exciting stuff.

  • Software Development Tools

This category will be very important to us as we progress, Software Development Tools provide us (Developers) with the ways we create, modify, and test our software. There is a lot for us to look into in this category and I’ll also be putting together a post on the types of IDEs (Integrated Development Environments) and text editors we can use and what languages (I personally think) are worth learning. We’ll even be learning some languages together, so I’m looking forward to getting stuck into that.

  • Utility Tools

This collection of programs are used to enhance the operation of a computer by performing very specialised tasks, this includes programs that provide data-backup and scan for viruses. There is currently no intention to delve into this area but we can see how things progress.

Application Software

I’ll keep this one short because we will be looking into it a lot but, essentially this is almost every other program you find on a computer, and importantly the same software I intend on teaching you how to develop for yourself. So this will be anything from the browser you’re using to read this, any word processing application, the previously mentioned IDEs and text editors, to computer games. This is the category of software that the vast majority of computer users spent their time using. So keep an eye out for the next post where we will look further into Programs themselves and how we can go about making our own.

This was quite a short one but it provides the information I intended and gives us some useful information moving forwards, the next stage will be looking at software and programs in more detail. Check it out here

I welcome feedback, especially at this very early stage, so any improvements you think I can make please get in touch either in a comment below or send me a message and I’ll get back to you.