home comics writing pictures archive about

2017-08-12 - Don't Plan Outcomes

I like planning. It makes me feel better to know what I'm going to do, or what I have to do. I also find that having a plan for what I want to accomplish helps me to be more productive and that it encourages me to be more diverse in my activities. That being said I've found that you need to be careful what you plan for.

When planning it's important to focus on what you can control. I think people have a tendency to focus on what they want to happen. I'm going to get a job, I'm going to buy a couch, I'm going to finish this project. I'm going to win the lottery. The problem being that sometimes you don't have the ability to make what you want to happen happen. You can make yourself look for a job but you can't make people give you one. You can make yourself look for a couch but you can't make stores have the one that you want. You can make yourself work on a project but you can't guarantee you're going to finish it. You can buy a lottery ticket but you can't pick which numbers will win.

If you plan to finish a project and you don't then you have failed which can be bad for your motivation to try again. If you plan to work on a project then you can consider the plan a success as long as you actually did work on it, even if you didn't finish it. it becomes a lot easier to feel good about the effort you did put in rather then what you didn't manage to do. Then you can plan to work on it more some other time.

The other week I wanted to finish a chapter of the F# book I've been working through.  I ran into so many issues working through the examples that I wasn't able to finish. The version of the plugin the book was using didn't work with the version of Visual Studio I was using. The version of the plugin which worked with the version of Visual Studio didn't work with the code from the book. Even after I managed to downgrade the version of the packages to match the book I still had issues running certain examples. I only managed to finish the chapter because I figured out which parts were causing issues and skipped over them. Which goes to show that just because you attempt something doesn't guarantee you can complete it. Sometimes the universe conspires against you and it's not really fair to blame yourself for the universe.

So when you are planning things focus on what you are going to do rather then what you want to happen. It will make it easier to feel good about what you have done rather than feeling bad about what you haven't managed to do.

2017-07-18 - Parts of Speech: Pronouns

Pronouns replace nouns which have already been introduced or can be determined from context. They are used to simplify sentences and allow us to talk about something without having to use its full name every time. For example instead of saying "The head doctor ran down the hallway and then the head doctor slid into the operating room" you can say "The head doctor ran down the hallway and then she slid into the operating room". Pronouns are special because they have a lot more forms depending on the person, number, or case of the noun they are a replacement for.

The person of a pronoun refers to the relationship between the person talking or writing and what they are referring to. First person pronouns refer to the person or thing speaking or writing (I). Second person pronouns refer to the person or thing being spoken or written to (you). Third person pronouns refer to someone or something outside the interaction (he, she, it). The number of a pronoun refers to the number of entities being referred to. Pronouns can be singular (I, you, he, she, it) or plural (we, you, they). The case of a pronoun refers to how it is used in relation to a verb. Pronouns can be used as the subject (I, you, he, she, it, we, you, they) or object (me, you, him, her, it, us, you, them) of a verb. Together these simple forms of pronouns are referred to as personal pronouns. Not because they deal exclusively with people but because they change form based on the person (First, second, third) being used.

Reflexive pronouns are used when the object is the same entity as the subject and usually end in self (myself, yourself, himself, herself, itself, ourselves, yourselves, themselves). The possessive form of a pronoun is used to indicate possession or ownership (mine, yours, his, hers, its, ours, yours, theirs).

There are also a lot more pronouns that can used in certain situations but these are good enough to start with. We may talk about the others at some point. Next time I want to talk about articles.

2017-06-24 - In IL: VB Grade Analyser (Select)

The Visual Basic .NET Select statement is a lot like the C# switch statement. The two have similar syntax and are used for similar purposes but the VB version provides more options. For example the C# switch statement requires exact values where as the VB Select statement allows you to enter conditionals.

Let's start by looking at a Select statement which performs the same operations as the switch statement from part 10.

Module1.vb
Module Module1
Sub Main()
Dim grade As Char = "B"c
Dim needToImprove as Boolean = False
Select Case grade
Case "A"c
Console.WriteLine("Your grade is excellent")
needToImprove = False
Case "B"c
Console.WriteLine("Your grade is good")
needToImprove = False
Case "C"c
Console.WriteLine("Your grade is OK")
needToImprove = True
Case "D"c
Console.WriteLine("Your grade is acceptable")
needToImprove = True
Case Else
Console.WriteLine("You failed")
needToImprove = True
End Select
If needToImprove Then
Console.WriteLine("You can do better")
End If
End Sub
End Module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

As you can see the syntax of the Select statement is very much like that of the switch statement. Now let's look at the generated IL.

Main
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 114 (0x72)
.maxstack 2
.locals init ([0] char grade,
[1] bool needToImprove)
IL_0000: ldc.i4.s 66
IL_0002: stloc.0
IL_0003: ldc.i4.0
IL_0004: stloc.1
IL_0005: ldloc.0
IL_0006: ldc.i4.s 65
IL_0008: sub
IL_0009: switch (
IL_0020,
IL_002e,
IL_003c,
IL_004a)
IL_001e: br.s IL_0058
IL_0020: ldstr "Your grade is excellent"
IL_0025: call void [mscorlib]System.Console::WriteLine(string)
IL_002a: ldc.i4.0
IL_002b: stloc.1
IL_002c: br.s IL_0064
IL_002e: ldstr "Your grade is good"
IL_0033: call void [mscorlib]System.Console::WriteLine(string)
IL_0038: ldc.i4.0
IL_0039: stloc.1
IL_003a: br.s IL_0064
IL_003c: ldstr "Your grade is OK"
IL_0041: call void [mscorlib]System.Console::WriteLine(string)
IL_0046: ldc.i4.1
IL_0047: stloc.1
IL_0048: br.s IL_0064
IL_004a: ldstr "Your grade is acceptable"
IL_004f: call void [mscorlib]System.Console::WriteLine(string)
IL_0054: ldc.i4.1
IL_0055: stloc.1
IL_0056: br.s IL_0064
IL_0058: ldstr "You failed"
IL_005d: call void [mscorlib]System.Console::WriteLine(string)
IL_0062: ldc.i4.1
IL_0063: stloc.1
IL_0064: ldloc.1
IL_0065: brfalse.s IL_0071
IL_0067: ldstr "You can do better"
IL_006c: call void [mscorlib]System.Console::WriteLine(string)
IL_0071: ret
} // end of method Module1::Main
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

The generated IL for the Select statement looks almost identical to that generated for the switch statement. This is to be expected since the two programs are doing the same thing.

Now we're going to change the program to take numerical ranges instead of characters.

Module1.vb
Module Module1
Sub Main()
Dim needToImprove As Boolean = False
Dim grade As Integer = 75
Select Case grade
Case > 90
Console.WriteLine("Your grade is excellent")
needToImprove = False
Case > 80
Console.WriteLine("Your grade is good")
needToImprove = False
Case > 70
Console.WriteLine("Your grade is OK")
needToImprove = True
Case > 60
Console.WriteLine("Your grade is acceptable")
needToImprove = True
Case > 50
Console.WriteLine("You passed")
needToImprove = True
Case Else
Console.WriteLine("You failed")
needToImprove = True
End Select
If needToImprove Then
Console.WriteLine("You can do better")
End If
End Sub
End Module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

This program isn't that different from the first one except for the variable being checked and the cases. If we compile this into IL however we see it's quite a bit different.

Main
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 126 (0x7e)
.maxstack 2
.locals init ([0] bool needToImprove,
[1] int32 V_1)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldc.i4.s 75
IL_0004: stloc.1
IL_0005: ldloc.1
IL_0006: ldc.i4.s 90
IL_0008: ble.s IL_0018
IL_000a: ldstr "Your grade is excellent"
IL_000f: call void [mscorlib]System.Console::WriteLine(string)
IL_0014: ldc.i4.0
IL_0015: stloc.0
IL_0016: br.s IL_0070
IL_0018: ldloc.1
IL_0019: ldc.i4.s 80
IL_001b: ble.s IL_002b
IL_001d: ldstr "Your grade is good"
IL_0022: call void [mscorlib]System.Console::WriteLine(string)
IL_0027: ldc.i4.0
IL_0028: stloc.0
IL_0029: br.s IL_0070
IL_002b: ldloc.1
IL_002c: ldc.i4.s 70
IL_002e: ble.s IL_003e
IL_0030: ldstr "Your grade is OK"
IL_0035: call void [mscorlib]System.Console::WriteLine(string)
IL_003a: ldc.i4.1
IL_003b: stloc.0
IL_003c: br.s IL_0070
IL_003e: ldloc.1
IL_003f: ldc.i4.s 60
IL_0041: ble.s IL_0051
IL_0043: ldstr "Your grade is acceptable"
IL_0048: call void [mscorlib]System.Console::WriteLine(string)
IL_004d: ldc.i4.1
IL_004e: stloc.0
IL_004f: br.s IL_0070
IL_0051: ldloc.1
IL_0052: ldc.i4.s 50
IL_0054: ble.s IL_0064
IL_0056: ldstr "You passed"
IL_005b: call void [mscorlib]System.Console::WriteLine(string)
IL_0060: ldc.i4.1
IL_0061: stloc.0
IL_0062: br.s IL_0070
IL_0064: ldstr "You failed"
IL_0069: call void [mscorlib]System.Console::WriteLine(string)
IL_006e: ldc.i4.1
IL_006f: stloc.0
IL_0070: ldloc.0
IL_0071: brfalse.s IL_007d
IL_0073: ldstr "You can do better"
IL_0078: call void [mscorlib]System.Console::WriteLine(string)
IL_007d: ret
} // end of method Module1::Main
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577

Gone is the switch instruction and the individual cases. Now we have a series of jumps. If you go back a few parts this actually looks like an If-ElseIf ladder. Which is how we would likely write this kind of code in C#. This goes back to what I've said before which is that the compiler is there to help you and make things easier. You don't need a Select statement which can accept ranges because you can already do that using If Else statements and the generated code will be the same in either case. The benefit of the Select statement accepting ranges is not in what it allows you to do but in how it allows you to express what you want to do.

Next time we are going to start looking at loops.

2017-06-04 - Computers were Created by Us

The problem with a lot of scientific disciplines is that they are trying to understand and rationalize the universe and the universe has very little interest in being understood. Every time we think we have it figured out something new comes up and turns everything upside down. Isaac Newton figured he had a good handle on the whole gravity thing. He said it was the attraction between objects with mass. That worked rather well to explain the orbits of the planets. Albert Einstein thought about it and decided that didn't quite work. He figured gravity was actually just an imaginary force caused by the curving of space-time due to massive objects. Now physicists are working to come up with a quantized model of gravity which fits into our current understanding of quantum mechanics. The more we learn about the universe the more complicated our models become.

Computer science on the other hand is about understanding things we ourselves have built. Computers are as simple as we want them to be because we built them to be that way. There's also really handy manuals and diagrams to explain how things work. If worse comes to worse and you still don't understand something there's a chance you can track down the person who's responsible for it and ask them why.

The benefit of this difference is that computer science is a lot more accessible than other fields. We are in control of every concept and idea which exists in computer science. We decide how things work. Now that's not to say computer scientists can't be weird and come up with weird concepts. It's just that there's usually an easier to find explanation. Instead of questions like "Why can particles jump through walls?" we have questions like "Why are the keys on a keyboard arranged the way they are?" which are a lot easier to answer.

This is one of the reasons I find working with computers to be appealing. I know that whatever I am trying to figure out it made sense to someone. If they can understand it enough to build it then I can understand it well enough to use it.