Programming Fundamentals [1]: Visual Studio, Variables and Data types

Welcome to the first post on Programming Fundamentals! If you haven’t set up Visual Studio, check out this previous blog post.

Creating the project

First of all, let’s set up a new project to work in. One way to do this is to select the File dropdown, New, and Project. As you can see, the shortcut Ctrl + Shift + N will also work in the future.

 

SS_1.PNG
Creating a new project

 

Once selected, an additional window will appear with numerous options. The left-hand side shows the various languages that are installed, while the middle section displays the various application types. The right-hand side meanwhile gives further information on the select option.

For the purpose of this post, let’s select ‘Visual C#’ on the left, and ‘Console App (.NET Framework)’ in the middle. Finally, we need to name the project below this – please note, there is a project name and a solution name. Visual Studio will automatically allocate the solution name as the project name, so we needn’t worry about that for the moment.

I will rename my project ‘Programming Fundamentals 01’ and then select ‘OK’.

 

SS_2.PNG
Setting up the project

 

Variables

You will notice immediately the sheer amount of code already in the project file. Essentially, everything we will write in this blog will be inside the following:

SS_3.PNG

I will expand on what it all means at a later point.

Variables are one of the key building blocks of a program, allowing the programmer to store information for later use. Any data that needs to be reused, such as user input, will need to be stored in variables. The key thing to remember here is that the value of variables can be changed – they are not immutable, and are often temporary.

Variables are declared with a structure similar to the following:

<Data Type> Name = Value

A variable has to be declared before it is used – a declaration must have a type and a name, but a value doesn’t need to be immediately specified.

Data Types

Data types are what essentially defines the type of value a variable can hold. These correspond to what we use in maths, more often than not.

Here is a list of the most common ones:

int – Any whole number (25)

float – Any number with a decimal place (25.0f)

bool – A value of true or false (true)

string – A collection of characters (“String”)

char – A single character (‘c’)

Implementing a variable with a data type

It is fundamentally important to assign the right value that works in accordance with the type of the variable. Failing to do so will result in an error, and the program will not run.

Consider the following:

SS_4.PNG

This is a correct declaration for a variable, of type int. Conversely, if we do not initialize it correctly:

SS_5.PNG

This happens. The name and value are underlined in red, indicating that the variable cannot hold this value. An error would occur if we tried to run a program with this since the syntax is at fault.

Now, it is your turn. I have demonstrated the basics of variable creating, try creating one of a different type and value. Remember, keep it within the static void Main() section.

Your variable/s should be something like this:

SS_6.PNG

Assigning variables

Lastly, before I conclude this post, I wish to touch upon assignment. A variable can either be assigned upon declaration or later on. This is done through the ‘=’ operator – I will talk more about operators in another post. Since a variable represents a value of a specific type, if another variable shares the same type, it could be assigned to the first, opening up many possibilities.

If you have any questions regarding this topic, feel free to grill me in the comments below. With that said, au revoir!

 

Setting up your IDE (Visual Studio)

Before we start on the juicy bits of programming in a later post, we should first set up the software that enables us to code. Visual Studio is widely used on the Windows platform for software development and game development, which makes it the ideal IDE (Integrated Development Environment) to use.

In the soon-to-come Programming Fundamentals posts, we will explore Visual Studio Console applications. However, once such foundations have been established, it can be used for much more.

First of all, let’s locate the website for Visual Studio – simply ‘www.visualstudio.com’.  There are four options displayed on the page; the one on the furthest left, Visual Studio IDE is the one we need. There are three versions of Visual Studio: Community, Professional, and Enterprise. The Community edition is free, with all the features we need to get started with. Let the download commence!

SS_1.PNG
Three versions of Visual Studio – select Community

After a little bit of processing and extraction, a little window will appear like this:

SS_2.PNG
Visual Studio terms and agreements

You can simply click continue, and accept the terms – they are nothing special.

The next window is an important one, detailing the features that we would like installed. This is essentially the configuration of the features we will use. While additional features can be added later on, it is easier to add what we need to begin with. This is largely up to you, but there are some default options that I would strongly recommend including:

SS_3.PNG
The base features you will need for Visual Studio

The three of these allow for us to use a range of programming languages: C#, C++, Visual Basic and more. We also gain access to various application types that will become handy later on.

To finalize the process, simply click Install – then wait for it to set the environment up for you. The IDE will ask for an account to log in, which can be a Google account or a new one.

SS_4.PNG
Visual Studio, with the installation complete

Once installed, Visual Studio may greet you with a sight similar to the above. This is the main page, displaying recent projects and various other options – ignore them for now.

Before using Visual Studio, we should first familiarise ourselves with Solutions, Projects, and Files.

Whenever you create a new project, a solution will be created along with it. Projects essentially belong to a solution, and therefore a single solution can have different projects. Files are contained in projects, acting as the content. A file is created by default for us to write code in.

You can think of those three in a hierarchical way: Solutions > Projects > Files.

With that said, Visual Studio should now be set up, and working correctly. The next post will introduce how we create projects in Visual Studio, the idea of variables and the various data types that exist within programming. Until next time.

Coding – what is it, and where do I start?

developer-coding-in-php_925x.jpg

In this first blog post, I wish to address a few important fundamentals when it comes to programming before we dive into the substance.

Coding, or programming as its otherwise known, is the idea of writing a set of instructions for a computer to follow – this may be to fulfill a specific task. However, this is where an issue occurs: computers don’t speak English, so how do we do this? Since computers operate in binary, 1s and 0s, any instructions that are given by the programmer must be converted into it, particularly since we humans are unable to understand binary effectively in the context of a fully-fledged program.

Programming languages are designed to be comprehensible to humans, while also translatable to binary. This translation is done automatically, so our brains don’t have to worry about it.

The important thing to remember is that there are different levels of languages: high level and low level. Higher level languages are closer to what we understand, while lower level languages are more easily understandable for computers – binary is one of the latter. Further up from binary, we have assembly languages, which operate through keywords to store and allocate data. On the highest level, we have the languages that are used commonly: C++, Java and such. These are what programmers use to develop applications of various kinds, high-level languages.

There are a vast array of languages, with different intricacies. However, don’t run away yet. It is an exciting world full of possibilities hidden below the surface.

Now, where to start? I would say, learning the fundamentals of programming. While the idea of developing an amazingly advanced game or a complex piece of software may be appealing, one must first gain an understanding of the foundations.

However, what can you do with programming? Below is a list of the numerous possibilities and languages:

  • Game Development – C++, C#, Java
  • Web Development – CSS, HTML, JavaScript
  • Software Development – C++, C#, VB.NET

 

After selecting a language, you need a piece of software to facilitate your ability to write code. In other words, an Integrated Development Environment (IDE). This gives the programmer all of the tools they need to write code, including a lot of helpful ones. There are many IDEs available, varying depending on your Operating System, but some of the best ones include:

Since I use a Windows PC, I shall be using Visual Studio throughout the entirety of these blog posts. The next post will talk in depth about how to setup Visual Studio, and configure it to your liking. Until next time!