2018-07-08 - A Few Good Bugs
As a programmer a certain part of your time will be spent fixing bugs. Unexpected crashes, unhandled errors, or things not working as expected. Some times these bugs will be super simple and fixing them is trivial. Other times a bug will be almost impossible to solve because there's no clear way to reproduce it and it seems to happen randomly and never on a test machine, But sometimes you end up with a bug that falls in the sweet spot. It's hard enough to be interesting but not too hard as to be frustrating. Debugging these issues can be one of the most enjoyable activities you do as a programmer.
Ideally you want a bug that happens regularly or can be triggered without vague steps like "Press this button a bunch and sometimes something happens". It's also nice if you have logs or some other kind of trace, from there it almost becomes detective work. You look at the evidence, review trace statements, recreate the issue, build a timeline of events and figure out where things went wrong. As you investigate hopefully you will figure out what really happened. The best part is that unlike real detectives you get to change the scenario so that the next time it happens the "crime" isn't committed. Sometimes that means throwing an exception and blowing everything up but maybe that's the best outcome.
Sometimes you cannot reproduce an issue following the steps you are given. This usually means that there's something they are doing that they aren't aware of that's causing the issue. This requires watching the person go through the steps and having that "Aha" moment when you realize what they are doing and where the bug is coming from.
Of course you rarely get to choose the bugs you work on even when you are the one creating them.
2018-06-17 - In IL: Print the Alphabet (do while, for)
Last time we looked at printing the alphabet using the while look. Today we are going to look at the do...while and for loops. First up we have the do...while loop which is vary similar to the while loop except that it checks the condition at the end of the loop instead of the beginning.
Note that because the condition is checked at the end of the loop the ch will be printed at least once regardless of its value. Now let's look at the compiled program.
This looks very similar to the while loop we had last time. The only difference is the lack of the branch to the condition check at the start of the loop which makes sense since the do while loop doesn't check the condition at the start of the loop.
Now let's look at the for loop version.
and the compiled code.
This looks identical to the while loop version which makes sense given that they are doing the exact same thing. The main difference between the for loop and the while loop is where things are put. In the while case only the condition is a part of the loop syntax, the initialization and stepping of the variable are done separately. In the for loop case all of these actions are a part of the syntax of the loop. We'll see more about the implications of this later on.
Next time we will look at some Visual Basic .NET loops.
2018-05-21 - Parts of Speech: Adjectives
Adjectives are words attached to nouns to provide extra information about them. There are a large variety of adjectives and a wide variety of uses for adjectives. Last time we looked at articles which are a type of adjective that helps to provide information about which instance of a noun is being referred to. Adjectives can also be used to provide information about the colour of a noun, i.e. "The green frog", or the size of a noun, i.e. "The big frog". These are called descriptive adjectives compared to articles and other adjective types which serve more to identify the particular noun being referred.
Adjectives can be combined to but the rules about adjective order differ based on the language being used and mainly come down to what sounds right. For example it sounds better to say "The big green frog" as compared to the "The green big frog". Generally articles or other identifier nouns go first and then descriptive adjectives as necessary.
Some adjectives can also be used for comparisons. This is expressed using the comparative form or superlative form. The comparative is usually created by adding the suffix -er to the word or by adding the words more or less before it. The superlative is usually created by adding the suffix -est to the word or by adding the words most or least before it. Like the order of adjectives the rules about how the comparison forms are created are not very well defined. The word forms are almost always acceptable but the suffix form depends on the adjective.
Next we will look at special types of adjectives.
2018-04-24 - C++
C++ started out as an extension to C that soon developed into its own unique language. While C is simple yet powerful C++ is complex yet very powerful. C++ is an object oriented language which means that the language is focused around creating classes consisting of attributes and actions. These classes are used as schematics for creating instances of those classes called objects. The attributes provide information about the object and the actions define what the object can do. C++ also includes a vast standard library that provide classes for many common tasks.
C++ has grown over the years and tries to meet the needs of many different scenarios. The many features of C++ are one of its greatest strengths and also one of its greatest weaknesses. In C++ there are usually multiple ways to do the same thing and it's not always clear why one should be preferred over the others. In C the only way to cast a value from one type to another was to enclose the desired type in parenthesises before the value. In C++ you can do casts the C way which is discouraged or you can use the new dynamic_cast, static_cast, reinterpret_cast and const_cast operators. All of these different casts are meant for specific types of conversions. The problem is that now you have to think about your specific scenario in order to determine the best one to use.
C++ is by no means a bad language. It is simply a language that requires you to be very aware of what you are doing which might be the biggest thing it inherited from C. Instead of trying to provide a singular preferred path it instead went for many possible paths each meant for a different situation. Probably the best indicator of the importance of C++ is the number of languages that came after it. You can see the influences of C++ in the syntax and style of many modern object oriented languages.
Although C++ can be frustrating to use at time it's hard to give up the many tools it provides to you.