Last call to change feeds

This is the last call to change feeds. Please redirect your feedreader to

http://feeds.feedburner.com/bytebaker

I’ll be shutting down other feeds for this blog in a few hours. If you find yourself not getting new posts for a few days, that probably means you’re still subscribed to the old feeds. Once again. sorry for the inconvenience.

Advertisements

Variables are not boxes

One of the common metaphors taught in intro computer science courses is that a variable is a similar to a box. Just as you can use a box to store something, you can use a variable to store a value. This metaphor is useful for introducing the concept of variables, but it is a very flawed metaphor. What makes it particularly bad is that holding onto this metaphor can be limiting when a student starts to go even slightly beyond the beginner stage.

In the good old days of down-to-the-hardware procedural programming, a variable really was a box: it was in essence a memory location. The fact is, those days are mostly beyond us, unless you use C/C++ or Assembler as your main programming language.  In fact, it is much more likely that you are using some sort of object-oriented language as your main language. With object orientation, the box metaphor doesn’t work. Why? Because of references.

With an object-oriented language, a variable is actually a reference. The object that you seem to be storing in a variable doesn’t actually get put into your variable box. The variable just ‘refers’ to the object. You can get to it through the variable, but it isn’t stored there. Consider the following (in Python):

foo = SomeClass()
bar = foo

Thinking of variables as boxes leads to confusion: how do you put one thing into two different boxes? Or does it just get magically duplicated? Add to that the fact that you’ll see that whatever you do to foo also gets done to bar.

A far more appropriate metaphor in this case is to think of foo and bar as names for the new SomeClass object. The new object is created and you choose to use it by the name foo. But then you decide also want to call it bar. How do you that? Well the only way to get it is through the name foo. Thus ‘bar = foo’ says ‘find whatever object has the name foo and then give it the name bar as well’. After that, giving either bar or foo another value, means that something else has the name foo or bar.

Though this metaphor does seem like a better one, it’s important to realize that the metaphor is deeply involved with the concepts of object orientation and doesn’t work perfectly. Consider the following:

foo = 1
bar = foo
bar += 1

The box metaphor fails because even though integers in Python are objects, bar and foo won’t refer to the same object. When dealing with simple integers like this, it’s actually the box metaphor that works. bar = foo copies whatever was in box foo and puts it in box bar.

So the question is what are variables? I would argue that the correct metaphor is context-sensitive. If you’re in a object-oriented environment, thinking of them as just names for independent objects will make your life much easier (and help prevent bugs arising from incorrect use of reference properties). But when you’re doing simple number crunching, the box does the job. But before you pick the metaphor you use, invest some time in learning about your language/framework and what metaphor suits is best.

Metaphors in computer science

Thanks to Slashdot I came across the transcription of a very interesting lecture given by Edsgar Dijkstra, one of the most important computer scientists before the age of the personal computer. The lecture is interesting and a worthwhile read for anyone into computers, especially computer science education. Though there are some parts that I don’t quite agree with, one thing that struck be as being every important is the Dijkstra’s realization that computer science comes with a vast array of metaphors to help beginners and experts alike think about what it is that they are doing. Dijkstra claims that these metaphors are misguided and are very damaging to the profession.

That may very well be the case, certainly some metaphors are questionable at best. But what’s of greater concern in my opinion is that most programmers I know don’t bother to really understand the metaphors and dig under the surface of the explanations that instructors present them with. It’s fine to use a metaphor to help you think (even if that metaphor is inaccurate) as long as you know what the metaphor means, where it comes from, and how things work without the metaphor to give a simplifying abstraction.

Metaphors are just that: abstractions. They let you think about things at a higher level without being bogged down by what the actual details are. However metaphors can be problematic because they describe something unfamiliar in terms of something familiar that may actually be very different. Problems start to spring up when you expect the unfamiliar object to behave like the familiar one. Abstractions in computer science (functions, objects, interfaces etc) can be safe because you can define precisely what the abstraction’s properties are. But unless a metaphor is very carefully crafted it can easily become a leaky abstraction: one where the boundaries are undefined and weird things can happen as you approach the edges.

Take for example the desktop metaphor. It’s useful because the way windows are placed on a screen can be thought of as similar to placing papers on a desk. Files and folders also fall in rather conveniently with this idea. But what about applications? What is an application icon supposed to mean? How do you explain dragging a file onto an application’s icon to open it? This isn’t to say the desktop metaphor is bad, it’s just that it can be confusing if you interpret it literally. Some other common metaphors are:

  • A variable is a box
  • Porsche is a class and your car is an object
  • A compiler is a translator

Each of these has it’s pros and cons and some are better than others. I’ll be looking at some of these metaphors in future posts and seeing if there are ways in which they can be improved.

How to consolidate your online presence

In the last post I looked at what an online presence and why it’s important. Your online presence is a two-way street, it’s what others see of you and how you interact on the web. Here are some tips to get your online presence under control.

Google Scrubbing

Google is quickly becoming the world’s homepage. If anyone who doesn’t know you wants to look for you, then chances are the first thing they will do is type your name into Google’s search box. So the question is, what are they going to see? Hopefully you’ve been smart enough not to leak your personal life onto the internet. But even if everything that a Google search reveals are things you wouldn’t mind people seeing, they might be very random and chances are they won’t give the full picture about you. So it’s up to you to make sure that Google does present the real you. How do you go about it? Well, that’s what the next section is about

Get a domain name

Domain names can be had for under $10 a year and there are lots of free hosting options. Having a domain name lets you carve out a part of the Internet and brand it with your own signature style. Trying to get a meaningful domain name that you can keep around for a long time and which you won’t mind telling lots of other people about.

Once you have a domain name, put it to use by building a good website around it. Put up normal things like a resume, but also put up PDFs of articles or papers you’ve written and link to your other work online. If you write blogs (one or many) consider turning them into subdomains of your website. This way there is a central location for your work on the web. Unless of course, you specifically want your blogging life to remain separate.

Consolidate your email

Another great reason to get a domain name is so that you can have email addresses attached to it. Having an email address attached to a domain name means that you don’t have to change it whenever you change jobs or schools and it looks more professional than a free email address. I would recommend having multiple email addresses for each domainL one for business, one for friends and family, one for mailing lists, one for free subscriptions etc. This way if you start getting spammed you can find out where it’s coming from and take measures.

Of course having a separate inbox for each email address would be very unproductive. I strongly recommend using the free Google Apps for your Domain and then using the Gmail app to alias multiple addresses to the same inbox. Then you set up filters to appropriately label, hide or delete emails sent to the various emails. Look at the first chapter of Upgrade Your Life for more useful email tricks.

Get your nicknames under control

Chances are you have multiple nicknames for different forums, IRC and IM. It might be a good idea to stick to a uniform set of nicknames so that people can find you. However, depending on whether or not you want to actually want to be known or if the nicknames are available, this might not be an option.

If you have any advice on how to get your online life under control, please drop me a note in the comments.

Why your online presence is important

This November marks 7 years of active Internet usage for me. Considering that the Internet arose in the 1980’s I’ll admit I was a good few years late on the spot. That being said, I’m happy to note that I was just in time to see the internet rise to the status of core infrastructure in our society that it has now. That, combined with the Web 2.0 movement makes the internet a very interesting place to be. In recent years the Internet has become an increasingly democratic medium, with anyone with a stable Internet having the capability to become not just the consumer, but also the creator of a variety of information.

It has only been over the past year or two that I’ve really started to take advantage of this inherently two-way aspect of the Internet. Having a online presence can be very useful nowadays and I would argue that it won’t be too long before having a website (or an ePortfolio) becomes as useful as a resume (and for some professions, even more useful). Being a computer scientist/engineer and part time web-designer, having an online presence is something I feel to be very important.

What is an online presence?

So what exactly is this online presence I talk about? Everything that you put out on the Internet is a part of your online presence. Email, IMs, IRC conversations, blog posts and comments, social network activity, all of it taken together goes to defining the unique ‘you’ online. For some people, like my parents, this presence is tiny, limited mostly to email and some IM conversations. But for most younger people (including myself) there’s going to be a whole slew of important and often unrelated information out there that represents your online identity. It’s important to know where your personal information is and what it represents. Much of the web is searchable and as the years go by even more different forms of information are being indexed and made available at a moment’s notice to anyone who wants them. Just as you wouldn’t leave your wallet or personal banking information lying out on the street, it’s a good idea to keep track of where and why you’re sending your information.

Here’s a little experiment: Type your full name into Google and see what the results are. If you have a relatively common name, then chances are that many of the results may not be about you. However the ones that are about you are worth looking into. Do they represent things you’re proud of, or at least things that you wouldn’t mind others seeing? If not, you should try your best to have them removed. In some circumstances you can’t (mailing list emails), but in some you can (forum posts). While I’ve always been an advocate of disclosure and I can’t stand hypocrisy, it’s also your right to rectify past mistakes. And while you are rectifying past mistakes, remember not to make future ones.

Your window on the world

It’s important to realize that your online presence is not just what the world sees of you, but what you see of the world. Having multiple email addresses with multiple providers (perhaps with not-too-discrete names) might confuse people you’re in contact with, but it will also make life harder for you. No matter what field you’re in, email probably takes up a considerable part of your time and you can make things easier by consolidating your email into a single place. At the other end of the spectrum, you could also have one gigantic inbox with everything mixed together. Learning to use filters and folders to separate out email will save you the mental and time costs of having to manage things on your own.

Whenever you see duplication in your life (multiple emails, multiple blogs, multiple websites), there might very well be an easy way to cut them down, whether it’s by using a client (or Gmail) to pull together multiple mailboxes or having multiple subdomains instead of multiple websites.

Your online presence is two-way street. In some ways it’s like your home: you live there and spend a lot of your time there, but you also have friends, family and other guests over. Taking care of your image on the web is just as important as keeping your house clean.