Programming Course: Lesson one

In the first class of programming course, we talked about a couple of ideas.

First, we talked about Boolean logic and the notion of TRUE and FALSE. These two things are very simple to think about. The examples we used involved a couple of students and a sibling.

We said “Nick is a boy” is TRUE. We also said that “Ryan is a boy” is TRUE. And we said that “Lily is a boy” is FALSE. Using that, we could expand to talk about the logical operators.

“Nick is a boy” AND “Ryan is a boy” is TRUE.
“Nick is a boy” OR “Ryan is a boy” is TRUE.
“Nick is a boy” AND “Lily is a boy” is FALSE.
“Nick is a boy” OR “Lily is a boy” is TRUE.
“Lily is a boy” AND “Nick is a boy” is FALSE.
“Lily is a boy” OR “Nick is a boy” is TRUE.

We also looked at logical negation, or the idea that NOT TRUE is FALSE and NOT FALSE is TRUE. This gets a little confusing when you try to fit it into English, but we tried:

NOT “Nick is a boy” is FALSE.
NOT “Lily is a boy” is TRUE.

Then we looked into code for these logical operators.

AND is &&, OR is ||, and NOT is !. Using T for TRUE and F for FALSE, we get the following values:

T && T == T
T && F == F
F && T == F
F && F == F
T || T == T
T || F == T
F || T == T
F || F == F
!T == F
!F == T

There’s a lot of ground to cover in logic, particularly with Boolean Algebra, but that got us started, so we’ll leave off there, with a final note: If you’re interested in more, you can find it here.

Moving on, we talked about variables. Variables are a little tricky because they’re pretty different in different languages. But for our purposes, beginning programming, we discussed what variables are for. Variables are there to hold stuff for us, so we can do work without always knowing what values are going to be.

We talked about a program that prints the greater of two numbers. The simplest way to do this, if you know the two numbers going in is to just write one line of code:

console.log(1);

if you’re comparing two numbers and 1 is the lower one. The problem is, when you’re programming things that are smarter than that, you won’t be able to know in advance what the values you’re using are. So, we added variables to our problem, like this:

var input1 = 1;
var input2 = 2;

So, we have two variables that we can use. We can change them if we want to, we can read them, we can compare them, we can print them out to the screen:

console.log(input1);

So, knowing that we can store things, and knowing that computers are good at making decisions, we need to find out HOW a computer makes decisions.

The easiest way for that is with a conditional statement — for our purposes, an if-statement:

if ([boolean equation here]) {
[do the stuff you want to do here]
}

That’s the syntax for an if-statement. We learned about boolean equations above, but we have to take a little time to learn a way to make those TRUE and FALSE values.

One way is to use mathematical comparators:
>, <, ==, !=, >=, <= That is, greater-than, less-than, equal-to, not-equal-to, greater-than-or-equal-to, and less-than-or-equal-to. There are more ways than this to generate boolean values, but these are the simplest, and they suit our purposes well. Greater than is a great place to start, because we want to see which is the biggest number of our two:

if (input1 > input2) {
console.log("The bigger number is input1, which is: " + input1);
}

Ok, there’s a little bit to talk about here. The console.log line has a + sign in it, but for now, let’s just say that when you’re dealing with a string, it just mashes everything together.

The first line is what we’re most concerned with. Greater than is true if the first number is bigger than the second. So, if input1 is 10 and input2 is 2, this would evaluate to true. The curly-braces {} hold everything that happens if this case is true. So you could have more than one line inside those curly-braces and it would only execute if the condition in line 1 is true.

Great, so assuming input1 is bigger than input2, we’re done. But, as we said, we can’t assume that. So, we need more. We could just add:

if (input2 > input1) {
console.log("The bigger number is input2, which is: " + input2);
}

That would definitely get us further down the road. I mean, you’ve got the cases where one is bigger or the other is bigger, and that should be just about it, right? Except that we’re missing one case. What about if they’re equal? That should be easy by now. We have another comparator to check equality:

if (input1 == input2) {
console.log("input1 and input2 are equal, and their value is: " + input1);
}

And that closes all the cases. If neither one is bigger, then they must be equal. So, we’re done. But that is a little bit of a bog. Three separate if statements. What if our comparison was more complex?

if (input1 > 0 && input2 > 0 && (input1 + input2) < 100) {
console.log("both are greater than zero, and their sum is less than 100");
}

That’s great, but how would you do something if that wasn’t true?

Sure, you could code it explicitly:

if (input1 < 0 || input2 < 0 || (input1 + input2) > 100) {
console.log("no they aren't");
}

But there’s a simpler way:

if (input1 > 0 && input2 > 0 && (input1 + input2) > 100) {
console.log("both are greater than zero, and their sum is less than 100");
} else {
console.log("no they aren't");
}

That’s the all-powerful else. If the condition in the initial if-statement is true, the block under it is executed. However, if the condition is false, then you can put an else statement there to be executed instead. You can chain if-else statements so they look like this:

if([initial boolean equation]) {
[first code block]
} else if ([second boolean equation]) {
[second code block]
} else {
[default code block]
}

So, if we go back to our original problem, we have something we can use for that:

if (input1 > input2) {
console.log("The bigger number is input1, which is: " + input1);
} else if (input2 > input1) {
console.log("The bigger number is input2, which is: " + input2);
} else {
console.log("input1 and input2 are equal, and their value is: " + input1);
}

We ended the lesson by coding up the reverse of this, which was to print out the smaller of two numbers, or if they were equal, then to print out the word equal. Most answers looked something like this:

var input1 = 1;
var input2 = 2;

if (input1 < input2) {
console.log(input1);
} else if (input2 < input1) {
console.log(input2);
} else {
console.log("Equal");
}

Then I tested the programs by entering different values for the variables, one where input1 was bigger, one where input2 was bigger, and one where they were equal.

There was a lot to think about by the end of the lesson, and the syntax can sometimes be tricky, that’s for sure. It starts out being frustrating that the language is so picky, especially for students who are used to the ambiguity of human languages, but once you learn to properly state things, there’s almost no opportunity to be misunderstood. Learning how to properly state things is what makes someone a programmer.

Career choices are a funny thing. I wasn’t thinking about a career as a programmer when I decided to go to university. I wanted to be a journalist. I wanted to be a professional writer, and I knew that the University of Lethbridge was a school that had a journalism transfer to Saskatoon. Little did I know that the journalism program at the Lethbridge Community College was all that I would have needed for that — two years less and more chance I’d get in.

While I was looking through the calendar for the U of L, I started thinking about the science courses they had to offer. Being a Liberal Education university, I was going to have to take four sciences. I was intimidated by math, having been through the wringer in high school. None of the core sciences were appealing either. I realize now that I probably could have taken some Geography, Logic, and something else, and that would have been enough. But I got drawn in by computer science.

Truth be told, that story was written a decade and a half earlier.

Picture it: 1982 or 1983, and my dad brings home a computer. A Commodore VIC=20, to be more precise. It was a clunky thing. It had a tape player as its only storage device. But it was fun.

We played a lot of games on that computer, but I got my first real taste of programming. The operating system accepted BASIC commands and you could write a program right on the command prompt and execute it in front of your eyes. Never mind that I didn’t know how to save anything that I’d written. Everything was in main memory, and I’ll never forget:

10 print “Liam is awesome.”
20 goto 10
run

Of course, I was six or seven, so I probably wrote something else, but the premise was there, and I was hooked.

Sean had some programming book, either it came with the computer or he got it at school, but I spent hours typing up the sample programs that were in it. I don’t remember anything about how any of it worked, other than when I tried typing out a game that they’d printed out. It rendered ok, but there was no interaction. Honestly, I was probably eight or nine by that point, and the fact that I got enough of it right to even run anything was amazing.

Then, after high school, I finally invested some money in a 286 8MHz computer. It was hopelessly outdated, it didn’t run any games or anything like that worth running, but it got me back interested in computers. We’d had a Colecovision ADAM, but I hated that thing. If you didn’t load the tape drive or the cartridge bay, it loaded into a word processor. I’ll grant that that’s something I’d appreciate nowadays, but back then, it wasn’t BASIC, so I didn’t want anything to do with it.

When I invested some money in a more modern computer after the 286, one that had more than sixteen colours at its disposal, and a whopping 8 MB of RAM, one of the very first things I got was a copy of Borland Turbo C++. I wanted to learn how to program, so I also bought a book. Yes, it was C++ for Dummies, and yes, the stupid thing had the requirement of already knowing how to program in C, so I did the next thing, which was pick up C for Dummies and start learning that instead.

Granted, the book was full of stupid things like Microsoft-specific commands that didn’t work when I started sampling Linux, but it got me started down the path to loops, conditionals, variables, and functions. By the time I started the intro to programming course at university, there wasn’t really anything for me to learn. But I studied. And I asked a pile of questions. Any time the professor said, “Let’s just pretend that it happens by magic for now,” I knew I had a question to ask. And he was more than willing to help me figure it out.

I did waver in my commitment to graduating. I struggled pretty mightily with it, especially over summer when I had a job that was paying me right then. Couple that with a suspicion that maybe I wasn’t good enough, and you had the fact that I only intended to come back after summer once, and that was the year that I spent taking classes over the summer so I could finish up at Christmas instead of in the spring. By then, I knew my back was basically shot and there wasn’t much chance I could do a full-time labour job anymore.

Then there were three very demoralizing years after graduation, when I worked as a Document Control Clerk, then a supervisor. I got what I needed from that job, mainly money to start my life as a married man and experience in an office setting. I struggled, as I failed to qualify for job after job, not even getting an interview, wondering if it would make more sense for me to go back to school for something like millwright training, and just start over. It felt stupid. I’d gone the Student-Loan route through university, and if I was going in for more training, it would be even more time before I could start paying that massive debt-load down, not to mention how much I would have to pay to get certified.

Eventually, though, I got through the resume process, I got into an interview, and I did well. Well enough, at least, that they hired me. Since then, the foot’s been on the throttle and, despite a couple of setbacks, I haven’t really spent a lot of time looking back. If someone asked me how I identify myself, the third thing on the list would be as a programmer. And if they had something to say about identifying too much with career, I would maybe partially agree with them, but honestly, it is so much more.

Programming is more than a job for me. It’s a mindset. It’s how I go about solving problems. It’s how I come to conclusions about things. Thinking this way got me my second and third mortgages. It helped me to decide to become a contractor and also to become a permanent employee again. I’m not saying I’m an unfeeling computer. Impulse and passion come into it a lot too, no doubt.

I like building things. I like to see them come to life. When all the pieces fit together and it not only works well, but hides the complexity of what’s been built from the user, that’s a satisfaction I get from very few things — the two things I identify with before programming providing those. When I’m faced with a problem, I don’t panic. When I hit a setback, I don’t usually whine. I look for other solutions. And that is because I’m a programmer.

Y’know, in case you were wondering why I do what I do.

Keepin’ Busy

Posted by: hadaad in Professional No Comments »

I find myself in the possibly-enviable position of being really busy.

I mean, I’ve been busy before. It feels like I’ve been busy since I finished university, with maybe a couple of breaks in there, but now, I’ve got so much going on, it’s almost like I should outsource myself.

First, there’s my family. They command my attention, and I would be a fool if I didn’t try to give them the best of my time, if not the greater portion of it.

There’s the full-time job, working for Gamesys on various projects. That’s going really well, and I would let the other work-type things burn if they threatened what I have there.

Then there are the other work-type things. They’re what have me excited and scared. I’m worried that I’ve over-committed, but I’m willing to give it a shot to see what comes of it. Starting on Tuesday night, I’ll be alternating between two different projects, in order to both supplement my income and sharpen my skills in technologies that I’m unfamiliar with.

I figure that a month will give me what I need to know, whether this is a realistic thing, or whether I’m kidding myself and I need to pare down. I haven’t been this busy in a long time, and I’m looking forward to the challenge.

Why Tuesday? What’s so important about Tuesday? Tuesday is the first day in a month where I won’t be participating in the summer blog challenge.

Have a good night,

Liam

Onward and Upward

Posted by: hadaad in Personal, Professional No Comments »

Last night, I posted about starting to teach introductory programming to some homeschoolers. I’m really excited about it, and I’m looking forward to using my programming skills to do something more than just putting food on the table.

In the same line of thinking, I was pondering a way to make more use of the skills I’ve learned. My kids are going through the pain of learning their multiplication tables. I didn’t struggle through that because of a tape my mom got for my brother that he used to listen to every night. I thought about doing the same thing for my kids, and I might just do that, but on another track, tonight I started writing a small program that would quiz them on their multiplication tables.

I mean, the premise is pretty simple: a question pops up, they answer it. If they get it right, they get a congratulations-message. If they get it wrong, they get the right answer and a consolation. That’s what I’ve got so far, but I’m thinking about extending it.

Enter a name, and the program keeps track of you, either through a flat file or something else, but it keeps track of things like right vs. wrong percentage, longest streak, things like that. Then you pit your kids against each other, with your love at stake, and you can’t lose. You’re leveraging their competitive nature and natural insecurity for their own good.

Ok, ok, never mind the parents love thing. But it might be something to get them working at their multiplication tables.

In a week, I’m going to be teaching for the first time ever. I’ve agreed to teach a small group of kids an introduction to programming.

I love learning. I love teaching. I think that teaching has the opportunity to teach the person in the instructor role as much as it does the one on the other side of the line.

However, I have never been the biggest fan of school. I guess I was too impatient to get on with the real thing.

It should be interesting. I do a lot of teaching on-the-job, and I have ever since I had enough experience to have something worth sharing. There’s something about when the light goes on for someone. You see them get it, and it’s just this feeling that the world is somehow better.

I should be nervous, but I’m not. These kids have a real interest in learning, and there are definitely things that I can teach them, not just about a programming language or a particular framework, but about problem-solving, and the best way to do it with a computer.

I’m wondering how I’ll consider it a success. I also wonder how fast it will be able to go. I’m guessing that will go however it has to go, but I’ve never had to deal with someone getting it faster than someone else.

I guess what I’m saying is that I’m excited for this opportunity to learn something about myself. Can I teach this? I know they can get it, but am I the guy to give it? I certainly hope so, and I hope that this becomes something more advanced, and something that I can give to the homeschooling community.

Cop-out

Posted by: hadaad in Personal, Professional No Comments »

[Note: This cop-out post comes after a ten-hour day at work, Scouts night and a bed time that ended near 10pm. –l]

CSS layout for one form: 13 hours
Dropdown population from a properties file: 6 hours and counting
Javascript interactions between form fields: pending
Data validation: pending

There are certainly days that are more humbling than others.

Better post tomorrow.

Liam

Books and Books

Posted by: hadaad in Personal, Professional No Comments »

There are books, you know, the kind that you buy that have words in them. They entertain us, they give us knowledge, and insights. They are wonderful. I have that kind of book-buying problem.

This is after a massive, massive cull about a year before we moved out here. Most of my books are electronic nowadays.

This is after a massive, massive cull about a year before we moved out here. Most of my books are electronic nowadays.

Then there are the other kind of books. You know the ones. They often come with horizontal blue lines on every page, with a single vertical one on the side (or maybe one on each side). I don’t buy those books very often. As a contractor, I used to get one for each contract, or if I filled one, I got another. Yeah, those kinds of books. I also have a problem with them.

Fear the pile!

This is what I could find immediately to hand and doesn’t include my new duo tangs or the five or six big binders that I also use for the same purpose.

The thing is, when I go to start a project, either writing or programming, I generally start by scribbling some notes, requirements, or even some snippets, in a book. Since I have so many books, I’ve found myself plunging through them to find the things I’ve been trying to write.

To get away from this, I’ve started in with Duo-Tangs. I have one for this programming project I’m working on. I’m slowly transcribing my notes from this one book that has a couple dozen other things in there, including two partially-written blog posts that I haven’t ported over to a book that I actually use for that, some notes on the Telus AMS 2.0 project — don’t worry, I don’t have anything damning — and a bunch of notes from my first contract at Intuit. I think there’s some thirteen-year-old C code snippets in there for connecting TurboTax Desktop to Revenu Quebec. Don’t worry, that stuff’s so out of date that it doesn’t apply anymore. Not that it matters. You can get documentation to connect to them on their website, if you so desire. (Trust me, you probably don’t)

The duo-tangs have been serving their purpose admirably. However, I required something more central, a place to put appointments, work notes, things I needed to do, and to catalog all the things I have in various locations.

“But Liam,” you say, “you have a Galaxy Note 3. what are you using that for?” And you’d be right. But while I love my phone and use it a lot, I can’t get away from paper and pen. I’m addicted. Take away my physical reading books if you replace them with ebooks, but you can’t take away my paper and pen. I need them. It’s how I pull the thinkings out of my brain.

So, now I have something central. Following in Kim’s footsteps, but starting a little closer to home, I picked up a Franklin Planner.

Leather that shines!

8.5×11 size, so I can just punch some holes in anything and go!

It’s a little bare right now, having only a task-list pad and a blank notepad that I had lying around with all my other books.

Featuring the biggest pen loops ever!

We’ll see how long the task pad lasts in the planner. It’s a bit confining.

I also threw in a nice little notebook Kim gave me, that I’ve started keeping work notes in.

Front cover

Millions of little pockets!

Given that I spend all day on the computer, it’s nice to have something physical to use to keep everything together. Plus, it’s more chance to write.

Drowning In Support

Posted by: hadaad in Professional No Comments »

The lights were out at work today. I noticed that right away. I flatter myself that I am one of the best people in the world at noticing when the lights are out and they should be on. Heck, I turn lights on at home all the time.
Later on in the day, the lights came on. I must have been really focused on what I was doing, because I just didn’t notice. The lady who sits next to me did notice and commented about it.
“You know what? You’re right!” I said, without even a trace of sarcasm. The lights really were on.
I really like that about me, how I’m willing to throw my support behind someone who says something that’s obviously right. I mean, I’m sure she knew that the lights were on. Or at least suspected it. She did declare it, after all. But to have it confirmed, to have her observation validated by someone as good at seeing light as I am must have been a real feather in her cap. Plus, in vocally backing her observation, I must have gotten some real respect in the eyes of my peers who had been sitting in the room, not noticing how bright it had suddenly gotten. Imagine, I was the first to back her up.
First.
You may now picture me leaning back in my chair, a contented sigh escaping my lips as I lace my fingers behind my head, the perfect image of correct contentment.
Yeah.

Coming out of University, the biggest snag was finding a job. Granted, the market was extremely depressed and tech companies, which had, until then, been basically printing their own money — in the form of stock — werte either out of business or extremely cautious in their hiring practices.

I remember the frustration of the job search and the fact that it took me three years of fruitless searching while I worked a clerical job, to find a position in my chosen career.

Now that I’m nestled comfortably in my career, I don’t spend a lot of time thinking about the difficulties that I had entering the industry. But a co-worker recently got me thinking about the catch-22 of the need and the gaining of experience.

Imagine a company that was comprised of experienced developers, maybe three or four of them. And every spring, the company hired three or four new graduates. In a pair-programming environment, the new developers would be innundated with mentoring, tutoring, and experience, whil delivering software. The first six months would be this. A crash course in Agile software development, source control, build automation, unit testing, and, of course, code.

After six months, there would be an evaluation, finding out what the new developer had learned. Provided they had made significant progress, they would be trusted with more responsibility — making design decisions, code reviews, unchaperoned implementation of features.

In this way, new graduates could get real work experience with a company, contributing to the deliverables, in a more sheltered environment. The job continues for two years, while the developer increases in ability and confidence. And at the end of the two years, the developers are sent out, developers in full.

I don’t know how realistic this business idea is but it is definitely a bit of a dream for me. I get energized by teamwork and mentoring and if I could make a go of it, filling contracts, while giving something back to the industry that’s been good to me, that would be great.

Yesterday, I talked about my desire to do my evening development while Lily goes to sleep and the steps I took to make that happen. Today, my new laptop showed up. Actually, we almost missed the delivery. Kim was heading out to run some errands and visit with some friends at the park. As she was leaving the subdivision, she saw the UPS truck turn in.

I wasn’t there, so I can only guess what happened. Kim gave me the basics but I doubt I’ll ever get the whole truth out of her.

Kim loaded the CD labeled “Chase Music” into the drive and the music started playing just as she completed the tire-screeching, smoke-emitting 180 burnout. She stomped on the accelerator, narrowly avoiding the old lady walking her small dogs. She hit the driveway going 70 and slammed on the brakes halfway up, stopping an inch away from the UPS truck. She unbuckled and leapt out the window, rolling to make Nick proud as she hit the ground. She sprinted up to the delivery man, bleeding from a roll-dismount that ended at the base of a pine.

The bewildered UPS driver handed her the package and a digital signature pad. She accepted the items, signed her approval, and handed it back. The UPS man didn’t waste any time in maneuvering his truck past the van. He would have asked Kim to move but, y’know, yeah.

So, putting that story behind me, my computer arrived today. I have wonderful pictures that I’ll show you. You’ll have to keep in mind that I’m no Peter Luu when it comes to pictures, showcasing my stuff, or deal-hunting.

oops

I wish I'd gotten a roll of this THINK tape with the computer. I could have put it to such good use.

Oops

A first glimpse at what lies inside

oops

Laptop, free of its plastic fetters

Note the pencil-eraser pointing stick that nobody else uses anymore.

Note the pencil-eraser pointing stick that nobody else uses anymore.

You will notice that the layout for the keyboard does not contain any stupid-shaped enter keys or half-shift buttons. Sadly lacking in a proper layout for Ins, Del, Home, End, Pg Up, and Pg Dn, though.

You will notice that the layout for the keyboard does not contain any stupid-shaped enter keys or half-shift buttons. Sadly lacking in a proper layout for Ins, Del, Home, End, Pg Up, and Pg Dn, though.

Switch to our mobile site