Virtus Studios | C++ vs Blueprints... a handy comparison guide
2019, Blueprints, C++, IDE, Programming, Unreal Engine
17259
post-template-default,single,single-post,postid-17259,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-13.3,qode-theme-bridge,disabled_footer_top,disabled_footer_bottom,wpb-js-composer js-comp-ver-5.4.5,vc_responsive
 

Logical thinking for programming

Logical thinking for programming

Hey there Dev Squad, Virtus here. Today we’re going to be taking a look at logical thinking and pseudo code to help you along your way to becoming a programmer written by Dev staff Crabo.

Programming is a huge and varied topic with loads of intricate little details, which can be off putting to those up and coming in the programming industry. Admittedly, the syntax can be a little intimidating and confusing as it changes from language to language but at the core, programming is a mix of common sense and logic.

 

Pseudo Code

Pseudo code is used to plan a program and describe it when doing tasks such as explaining or writing a report.. When I studied Computing Science in high school, my teacher explained pseudo code as an English-Code hybrid. Essentially, it’s writing code without the syntax and in a way that anyone can understand it. Below is a quick example of some pseudo code for checking which of two numbers is larger and printing it:

 

  1. DECLARE VARIABLES*
  2. IF NUM_1 GREATER THAN NUM_2
  3. PRINT NUM_1
  4. ELSE
  5. PRINT NUM_2
  6. END IF

 

Breaking down a program into pseudo code, it makes it much easier to see what’s going on. When writing a program, it’s important to break it down into logical steps as to not overwhelm yourself. You can see in the above example that the pseudo code clearly states what it’s going to do and how it’s going. All you need to do is translate it into actual code. Learning the syntax is a whole other scenario and can also be confusing, but thankfully, there’s hundreds of online resources to help with that!

 

Errors

I want to quickly talk about errors, what are they and how to deal with them. There are three main types of error:

 

Compiler

A compiler error is when something goes wrong with the compiler or something goes wrong during compiling (such as missing a file, a linking error or a missing file). You could write perfect code with zero other errors but if something goes wrong with the compiler, it’ll throw back an error. Depending on that nature of the error, you’ll most likely need to google it. When you get an error, the compiler log will give you the error, although it may not be as obvious as the next two types of error.

 

Syntax

A syntax error is caused by the code being written incorrectly. For example, if you write some code in C++ to print a piece of text, you’d write it like this:

 

std::cout << “Hello World”;

 

That’s a perfect line of C++ code and would have no errors if you ran it within a program. Syntax errors are really easy to cause and are cause often, but they will return an error which can often help you find the error, and the code most likely won’t run. An example of the above code with a syntax error would be something like:

 

std::cuot << “Hello World”;

 

That would cause the program to crash and not run properly, even if the error is small (like the example above) and look how simple the mistake was. These are very common and you shouldn’t work yourself up too badly about them. The most simple case of causing a syntax error is misreading or mistranslating your pseudo code. For example, if you wrote the IF statement from the above pseudo code in C++, it should look a bit like this:

 

if(num_1 > num_2){

std::cout << num_1;

}

 

Very simple segment of code, but prone to lots of easy syntax errors. The most simple of which would look a little like this:

 

if(num_1 > num_2){

std::cout >> num_1;

}

 

Logic

A logic error is one of the worst types of errors because you don’t get any indication of it until the program runs. A logic error occurs when the result of the code is different than what you expected. For example, if you run a program and part of that program involves dividing two variables a and b, in that order.

 

For this example, let’s say that a is 1 and b is 2. The program should divide a by b and the output of which should be 0.5. When you run the program, it returns 2. There’s been no compiler or syntax errors and everything else still works the way it should be. When you check the code, you see that you’ve accidentally typed “b/a”. That’s a logic error. Like syntax errors, these are really easy to make, but if it happens, don’t be disheartened. Everyone makes these errors, even professionals make these mistakes.

 

If you come up against a logic error, it’s important to carefully read over your code and think logically. Like in the above example, the programmer made a really simple mistake and hadn’t noticed until they read over it and thought about it logically. That’s the key word, logically.

 

Morale of the Story

With these points in mind, programming is just a mixture of logic and common sense. Sure, it can sometimes be tedious and frustrating, but the result of your hard work will pay off as you watch the fruits of your hard work blossom. Don’t be upset if your code doesn’t work, just do some googling and you’ll find the answer eventually; just don’t give up. Those errors you’ve made? Chances are someone else has made them. You are not alone. We live in an age of information, all at your fingertips. All it takes is a quick google or a simple question posted somewhere, like our discord server for example. With some commitment, brain power and a touch of common sense, you’ll be make your life as a programmer much easier!

I hope you have all enjoyed this article and are now better informed on how you can logically think about the way applications are made and put it to practice writing your code.

Don’t forget, if you want to learn about actually writing code (C++), you can checkout our FREE course using the links below.

C++ Programming Course

As always guys, stay awesome… keep creating!

Your boy Virtus, signing out.