2018-09-01 - In IL: Print the Alphabet (Do Until)
In the last few parts we've been looking at C# loops, today we're going to look at a couple Visual Basic .NET loops. VB has a lot of the same loops as C#, with some syntax differences, but the Do Until and the Do ... Until loops are VB only. The Do Until loop is similar to the while loop except that instead of looping while the condition is true it loops until the condition is true, hence the Until keyword.
One thing you might notice about this code is the strange way the character is incremented. This is because Visual Basic .NET has different rules about implicitly converting characters to integers which requires us to explicitly convert the value to an integer, increment it, and then convert it back to being a character. Now let's compile it and see how that looks.
Except for the different instructions to increment the character this looks almost identical to the while loop version we saw previously.
Now let's look at the other version of the Do Until loop which puts the Until after the loop similar to the do ... while loop.
and if we compile that we get.
Again that looks very much like the do ... while loop we saw last time. The language gives you two ways of doing something but the compiler converts them into a single way by reversing your logic. The Until syntax is simply a tool for you to better describe your program's intentions using words.
Next time we will look at continue and break statements.
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.