Category: Training

  • Beginning C++ 43-52: Variables and Constants

    So this time we have come to variables and constants. Probably some of the most important things in any software as you need somewhere to store the input and data your program uses.

    This post is a long one, but hang in there and let’s see where this section leads us.

    The course can as always be found on Udemy. I just realised I have forgotten to link it before. 🙂

    abstract achievement bright business
    Holy variables declarations, Batman!!!

    Lecture 43: Section Overview

    Yeah, well. Again a quick overview of the section.

    I like these overviews because then I have some idea of what we’ll learn and expect from the section, and I don’t go in “totally blind”.

    Lecture 44: What is a variable?

    A nice little overview of what a variable is, what it does and how it is used.

    This might seem like a general overview of variables in general programming, but it’s important to remember that this course goes through how variables are used in C++. C++ is a static programming language which simplified means that you have to declare both the variable AND the type before using it.  The instructor does mention this, but it’s easy to miss.

    Other programming languages have completely different rules about variables. Just because of the description, I personally have a fondness for duck typed languages. Those languages find out what kind of a variable it is, using the idea of If it walks like a duck. I’m not saying it’s better or worse, I just like the name. 🙂

    Lecture 45: Declaring and Initializing Variables

    This lecture goes through the rules for declaring, naming and initializing a variable and I think this is the second time the instructor goes into best practices in programming. This is something that I personally am very interested in and I’m keeping my eye out for more of this.

    BTW, the first time he talked best practices was when he talked about the using directive. Go back in the course and review it if you don’t remember what he said about it, but in short: Don’t use it! 🙂 And that’s why I use it in my code during this course. 😀

    The naming rules are pretty straight forward but it’s also very important to know these rules or you might end up in trouble. For instance it’s easy to think that the names Foo and foo are the same variable, but in C++ they are not.

    A standard for naming things you use in C++ is important if you want to make your code clear and readable. The instructor goes through some examples, but there are many style guides out there and if you start working as a programmer somewhere, that company should have a style guide that you  need to follow. Google for instance have published their C++ Style Guide on GitHub.

    It might be interesting to read through some style guides when you get proficient in C++ and find one you like, but I might hold off on that until I know more C++. I skimmed through Google’s guide, and much of it was confusing as they talked about stuff I don’t know anything about yet.

    The lecture ends with some practical examples on how these things work, so start up your CodeLite IDE and play around with what you’ve learned.

    I think that the most important thing to remember from this lecture at this moment in the course is that you have to initialize your variable to avoid unexpected results. The compiler helps you with this as it throws up warnings if you’ve forgotten to do this, so check the errors and warnings when you compile your program.

    woman holding plastic arrow while smiling
    Is she pointing at a global variable?

    Lecture 46: Global Variables

    Pretty short and sweet lecture that discuss the difference between local and global variables. Pretty important to know the difference, as it has some consequences and pitfalls.

    The punchline is to use local variables and global only when absolutely needed. Which is pretty seldom, as I’m sure we’ll learn how to pass values between functions pretty soon.

    Lecture 47: C++ Built-in Primitive Types

    The lecture goes into the fundamental data types that are built into C++. The fun thing in C++ is that there are some differences between the sizes of these types depending on what system you are on.

    The instructor goes into all the four main data types and shows tables describing all the intricacies, which is really not that intricate but there are some things you need to be aware of, for instance when doing math.

    The last half is a practical demo of the different types using CodeLite and some C++ code. There are some pitfalls you can get into, but if you’re being smart when initializing your variables the compiler will help you by throwing errors or warnings at you.

    Lecture 48: What is the Size of a Variable (sizeof)

    Remember I told you that the sizes of a data type varies in C++. Happily C++ has a built in operator for showing you the size, naturally called sizeof.

    But when other courses only tell you about sizeof, Frank goes into where this operator gets its values from and how you can use those include-files in your own code. If you want to, you can check out my code with some examples. Go get the code on GitHub.

    Lecture 49: What is a Constant?

    A constant is almost the same as a variable, but their value is constant. Well, duh… 🙂

    The instructor goes into why you would use constants instead of variables with some examples. Since C++ also have different types of constants, he shows us some examples of literal,  declared and defined constants.

    Be aware that in modern C++ you should NOT use defined constants. The replacing of defined constants are done by the preprocessor and since that is pretty dumb and don’t have the error checking capability of the compiler it can lead to errors that might not be easy to spot.

    Lecture 50: Declaring and Using Constants

    This is a loooong video, but happily it’s a practical example of using constants so nothing to worry about.

    The code starts really easy with just one variable and several literal constants. Then he refactors the code to make it easier to read and update. You see the instructor create and run all the code as he writes it, errors and all. I find that to be a nice touch, as the also teaches you things and makes the instructor “more human”.

    This section also introduces pseudocode as a way to start your programs. Solve the problem using natural language statements first and then you translate that to C++ code later. It makes it easier to think about the problem and how to solve it than doing it directly in code.

    white black game fun
    Now it’s time for a challenge

    Lecture 51: Section Challenge and Quiz

    So, the challenge. This is based on the previous lecture, just a little expanded.

    You are running a carpet cleaning service and this program should calculate and give a price estimate to customers. The customers provide the number of small and large rooms and then the program spits out the cost, the tax and total estimate and how long it’s valid.

    Pretty easy and straightforward, but a nice little review of what you learned through the section. My solution was a little different than the instructors, but both of them works quite nicely. I use some extra variables in there, so I don’t have to do the same calculation several places. Saves some typing and time.

    The quiz is a nice little recap of what the instructor has told us earlier. You have all the info, but I think he only mentioned some of it once, so you need to pay attention to the lectures.

    As much as I like the “Good job!” when you answer correctly, I would like some more feedback even when you answer correctly. It might be that you just had a lucky guess and don’t really know why the answer you gave is correct.

    The solution and the rest of my code from this section can be found on my GitHub page.

  • Beginning C++ 36-42: Structure

    This section teaches us the structures of a C++ program. C++ being a static language imposes some pretty strict rules on what you can do and not, so learning how a program is structured is pretty important.

    These early videos don’t really do much coding, so there’s not really much to do for me here other than summarize them. Hopefully, there will be more coding later where I can show you my solution and my thoughts behind it.

    architecture-iron-steel-building-53176.jpeg
    The structure of a C++ program is very important.

    Lecture 36: Section Overview

    Again the section starts with a quick overview of what we will go through in later videos. Always nice to have some knowledge of what you are going to learn before you get the details.

    Lecture 37: Overview of the Structure of a C++ Program

    This lecture starts by showing us the keywords of C++. It has over 90(!) defined keywords, which is much more than many other languages. Luckily many of them are not used so you don’t have to remember all 90.

    Then the video goes on to talk about identifiers and what’s the difference between them. It also gives you a quick overview of operators and points out some specific C++-operators. Lastly, we go into punctuation and show some examples of that.

    All of these elements put together gives us the syntax of C++.

    Lecture 38: #include Preprocessor Directive

    Here the instructor gives us a brief overview of what the preprocessor is and what it does.

    It’s a program that goes through the code before the compiler gets hold of it. It doesn’t do anything with the C++ code, nor does it understand it. It just goes through the source code, does some finessing with it and then spits it out and into the compiler.

    Lecture 39: Comments

    // This is a one-line comment.

    /* These lines of code
    are comments that go
    of several lines, aka. a multi-line comment. */

    I saw somewhere else that comments using // was the C++ style code, while /* */ was C-style. Don’t know if anyone can confirm or deny that?

    Comments should just be used to explain complicated code. Clear to understand and obvious code doesn’t need comments.

    The course also discourages the use of comments for version control. It’s much better to use Git, Subversion or other systems to get real version control of the source code.

    BTW, one of the jobs of the preprocessor is to strip the source code of comments so the compiler doesn’t have to bother with them.

    food-plate-restaurant-eating.jpg
    This main() course looks SOOOO good! 🙂

    Lecture 40: The main() function

    Now we’re coming to the main() course.  😀

    The main()-function is an important part of a C++ program as each program must have one, and only one, main() function. This is where the program starts its execution, so whatever your program does, it all starts here. Most of the code is actually not in the main() function at all, but without it the program won’t do anything.

    The course describes two different versions of main, depending on if the program accepts command line arguments or not, int main() or int main(int argc, char* argv[]).

    In another course I take I see them using void main(…). After watching this lecture I wanted to find out why they do it differently, and the answer is that one does it right and the other one doesn’t.

    The correct way to do it is to use int main(…). The using of void main(…) is something that Microsoft Visual Studio allows, but it is just wrong and should not be done. Trying it with g++, as is the compiler used in this course, will give you an error message.

    Lecture 41: Namespaces

    Namespaces are a way to avoid conflicts between different libraries or frameworks that might have functions with the same name. Using namespaces and the scope resolution operator (::), will avoid using the wrong function.

    C++ has a “standard” namespace called std. Those three letters plus the two ::’s are something you will learn to type a lot.

    You can use a directive to avoid typing the namespace names all the time, but it comes with some dangers. This is fine for small programs, but large and complex programs should avoid this to make sure you don’t use the wrong function due to a naming conflict.

    Lecture 42: Basic Input and Output (I/O) using cin and cout

    Most of the other videos in this section has been around the 3- to 4-minute mark, but this video comes in at a whopping 20+ minutes. Time to prepare for a HUGE chunk of info.

    We learn about cin, cout, cerr and clog and more from iostream. This is really the first course I’ve taken that mentions cerr and clog. Probably because it’s mostly not used, but again this is a nice touch and shows that this course goes deeper than most.

    Another nice point is that Frank, the instructor, talks about the difference between using \n and using endl when adding a line break. For the user, it looks the same, as the end result is that the next text that is written goes to the next line, but behind the scenes, there is a difference. Especially when working with files you will want to be aware of the difference.

    The instructor also goes quickly through the pitfalls of using cin for reading inputs.

    The lecture ends with examples of everything that’s talked about and again Frank does a pretty good job of explaining what happens and why you need to be careful when using cin. He actually says that usually, you don’t use cin to get user input without going into further explanation. I guess we will come back to that later.

    Quiz 2: Section 5 Quiz

    So no Section Challenge this section, but a nice little quiz. We didn’t really learn any new statements etc in this section, so a challenge would really just be a repeat of what we’ve already done in earlier sections.

    The instructor sneaks some nice little traps into this quiz, so it’s important to read the questions and answer alternatives thoroughly before selecting your answer. I didn’t so I ended up with just 9 out of 10 correct on the first try. Was pretty easy to figure where I went wrong, but a nice touch from the course so you just don’t cruise through these.

  • Beginning C++ 25-35: Getting Started

    So, we are now entering a new section and we are Getting Started. Yeah, that’s the title of the section, so I must believe that we are now finally going to write some code.

    norm-mac-1.jpg

    Lecture 25: Section Overview

    This is just a section overview, just as the title say. Nothing special, let’s continue.

    Lecture 26: An Overview of the CodeLite Interface

    This is a very nice video as it tells you how you can change the layout of the CodeLite IDE to your own personal preference.

    I personally didn’t change it up to much. Just removed a few tabs the Workspace view I don’t think I will be using for now and also moving it to the right side of the window. That way it looks a little bit more like my setup in Visual Studio 2017. I also fiddled around with the themes to find one to my liking and ended up using Tomorrow Night as my theme.

    Lecture 27: Writing our first program

    We write a small program to type a message to the user and get an answer from him. We started with the template we made earlier, but deleted the source and wrote everything from scratch. This is a nice educational move as it will teach you more about the structure of a C++ program when you have to write everything yourself instead of starting from a random template.

    We learn some basic input/output functions of C++ and the difference between the insertion and the extraction operator. There is a small mention of namespaces, variables and how we include libraries.

    We end up with a short little program that we compile and hopefully end up with zero errors and warnings. I managed to bork it with some missing colons, but happily nothing I didn’t know how to fix.

    The instructor also shows us that since we made our own template and based this project on that, we can see that CodeLite instructs the compiler to use the C++14 standard.

    So again nothing special, but this is Beginning C++ after all and we all have to start somewhere.

    Lecture 28: Building our first program

    We learn more about compiling and building a project. What are source-files, object-files and executable files? The instructor also goes through the different options CodeLite have for compiling, building, rebuilding and cleaning files and projects.

    The course also tells us more about the difference of the files we see in the Workspace and what is really on the disk. There are many files on the disk that we as developers don’t need to know about, at least not at this moment, but it’s nice that the course explains them anyway.

    For beginners in C++ this is maybe not fully understood right now, but it’s something you need to know when your projects gets bigger and more advanced. But we’re still in the introduction stage learning basics that are important to know to set up your workflow and understand what’s happening if something goes wrong.

    Lectures 29-33: What are different types of errors?

    pexels-photo-277052.jpeg

    These videos goes through the following types of errors:

    Compiler errors

    The instructor creates a new project and shows us some common compiler errors and some ways on how to fix them.

    Compiler warnings

    What’s the difference between a warning and an error? Well, here you get an explanation. In short, it’s not “real” errors in your program, but it warns you about things that might give you unwanted or unexpected results.

    Seems like g++ is fairly good at giving error messages and warnings that you can understand. And CodeLite also helps you find the error as if you click on an error message, the IDE will jump to the place in the code where the error is reported.

    Linker errors

    These errors are a little bit more tricky to find. A program might compile without warnings, but when you build it you might get a linker warning. These errors can be more tricky to find in your source.

    This is something we probably won’t be having much in this course since we’re doing all the coding ourselves, but when you create large projects and try to link other libraries etc this is something that can happen.

    Runtime errors

    Runtime errors are errors that happen when you’ve taken care of all the bugs in your program, compiled and built it and made the executable file. Then some user runs your finished program and gets an error and yells at you, even after all your hard work.

    These are errors that you can’t really avoid. Sometimes a user gives you strange inputs, a file can be missing or something like that.

    These errors can make your program crash, so you have to use Exception Handling to deal with them. Exception handling will be a topic for later in the course.

    Logic errors

    Logic errors are errors that the compiler won’t help you with and doesn’t stop you from building your program. These errors are made by the programmer during writing of the code.

    These errors can really only be found by doing thorough testing of the program before you send it to end users.

    Lecture 34: Section challenge

    Fairly easy challenge here as everything you need has been shown to you in the previous videos.

    What you need to do is to make a program that asks the users for his favourite number and get that from him. You will then say that it’s also your favourite number and confirm that the number the user typed really is your favourite number.

    s2o7pty
    This is the output of my solution to the challenge

    If you want to see my solution you can check out this gist. You shouldn’t really need to look at my solution to solve this challenge, but it’s there if you need it.

    Lecture 35: Section Challenge – Solution

    Well, not surprisingly the solution the instructor shows us are more or less identical to my solution.

    Quiz 1: Section 4 Quiz

    The section ends with a quiz with 10 questions relating to the topics covered. Shouldn’t be too hard, but it’s nice to get a review of the topics to see if you understood the material.

  • Time Management & Productivity course review

    So, the time has come to do a review of the Udemy course Time Management & Productivity.

    What is important is seldom urgent and what is urgent is seldom important.
    – Dwight D. Eisenhower

    The course is designed to get you better at scheduling and managing your tasks using a method called the Eisenhower Decision Matrix. It’s a fairly short course, so I went through all of it in an evening. And these are my thoughts about it.

    pexels-photo-908298.jpeg

    This course is a hard one to rate fairly for a couple of reasons.

    1. It’s short. But does short mean something is bad or of no value? Of course not, sometimes a 10 second pep talk can be all you need to get something done.
    2. The material is very well known. Search on Google for “Eisenhower Decision Matrix” and you get 148 thousand hits.

    But I’ll make this article pretty short also and say that I’m a little “meh…” about this course.

    First reason for that is the cost. They want $49.99 for it, which is WAY to much. I got it on a sale for $10, which I think is the maximum I would pay for this course.

    Second, but more importantly is the content of the course. They explain every part of the matrix and how to use it, but I feel that they could have done a better job of giving real life examples of the topics.

    There is a video in there which is labeled “Personal Example”, and I’m sure it IS a fairly real example from the instructor. But all he ends up with is to repeat what has already been said on the previous videos.

    If you want to learn about this topic and try it out I would recommend you start with this article from The Art of Manliness, The Eisenhower Decision Matrix: How to Distinguish Between Urgent and Important Tasks and Make Real Progress in Your Life.

    There is one thing the course does better than that article and that is it’s methodology of HOW you define which of your tasks goes where. In short how they do it is:

    1. List all your tasks
    2. Rank them first by Urgent or Not Urgent
    3. Rank each block into Important or Not Important

    And one HUGE point about that 3rd step is that you rank them on the importance FOR YOU! Does the task help you further your goals or is it a task that help some other peoples goals? Only tasks important to you should go in the Important category.

    So to sum up, will I recommend the course? If you can get it for cheap, then feel free to do so if you feel you need more than the article I linked above.
    If you do some more Googling about the topic and think that is better use of your time, then give this course a pass. If you have some more questions about the topic, then drop a comment below and I will answer to the best of my ability.

  • Beginning C++, section 1-3

    I chose to do these three sections in one blog post since they don’t really contain much specific C++ teaching. When I get to more specific lectures I’ll make more in depth posts about what I’ve learned from those lectures.

    CodeLite

    Section 1 – Introduction

    This section goes into why you should learn C++ and a little bit about the history of the language.

    The simple reasons the teacher gives for why is two; salary and popularity.

    At least in the States it seems like C++ developers can earn good money. How it is over here I don’t know, but I see that there are several open positions for people knowing the language.

    The course points to several websites that make different indexes about the popularity of different programming languages. The most interesting link might be a ZDNet-article called Which programming languages are most popular (and what does that even mean)? It is sort of a rundown of all of the other pages linked in the course and it has some discussions about which way to go. You’ll see that C++ is ranked as one of the top 6 popular languages used now and it recommends you choose either C++ or Java as your first language to learn.

    Section 2 – Installation and Setup

    In this section the course just goes through some of the tools you can use to program C++. The teacher has gone for something that is cross-platform and has low requirements and has ended up with CodeLite as the IDE and they are going to use GNU compilers.

    Since I’m using Windows I ended up with using MinGW and CodeLite, but the course also goes through setting up systems for Mac OSX and Ubuntu Linux.

    It also links to some websites you can use if you quickly want to test some stuff and don’t have access to your IDE in the moment.

    Section 3 – Curriculum Overview

    As the title of the section explains pretty good, this is just an overview of what the course will be about and also how the course is built up with lectures and challenges.