End of Vacation 2016

It’s Sunday, the first of May, and I’m wrapping up my week-long vacation from work. It was nice to be out of the office for a few days, but with the amount of work I got caught up on for school, I still feel like I need a vacation.

The positive side of this work-cation is that I no longer feel like I’m drowning in work, as I’m pretty much caught up with everything I need to do. The negative side is that I’m still exhausted. Between my day job as a programmer and my other day job as a PhD student, I’m starting to feel like a candle burning from both ends.

At least now because I’m caught up, my head is above water, I can take some time to implement some life changes to hopefully stay ahead of the wheel. One change I’d like to make is to start getting up earlier. If I can shift my wake-up time back a half hour, I’ll be able to work on school-related projects for a bit before work. If I can do a little bit each day, perhaps my weekends won’t feel so exhausting.

Another change I’d like to make is to give myself one day a week to relax. I’m thinking of declaring Sunday to be “no work day” going forward. This does not include doing chores around the house, of course. But no work means no email, no programming, no reading documentation, nothing.

C++ Friends, Templates, and Friends of Templates

This post is mostly to keep my own memory fresh. It’s been a while since I’ve written any hard-core C++ code, especially code that uses the language to its fullest potential.

Let’s assume for some strange reason that you have a class template within another class template. In other words, consider the following code:

template <typename T> class outer {
    int x = 0;
    template <typename U> struct inner {
        void foo(outer<U> const& o) const
	    { cout << o.x << endl; }

with the following main function to drive it:

int main()
   outer<char> o;
   outer<int>::inner<char> i;

If you compile this code as-is, you will get an error about the variable x being private to outer<char>. This makes total sense, since each instantiation of the class template outer is a distinct class object, and thus the class template inner will only be friends with versions of outer that have the same template parameters. In other words, if we change the declaration of i to read

outer<char>::inner<char> i;

everything will be a-okay.

Luckily C++ gives us a mechanism for working around this without breaking encapsulation: the friend declaration. So the question becomes, what is the correct friend declaration for ensuring that for all T, every inner for each U will be a friend of it? I’ll save you the guess work. If we add the statement

template <typename V>
template <typename W> friend class outer<V>::inner;

to the class template outer, just after the definition of the class template inner, everything will work as we want it to.

I was thinking about this the other day, and it took me longer than I’d like to admit (being practically a human C++ compiler, I should have nailed this within seconds), hence the blog post – it’s here now for all eternity. So to wrap up, changing the class template definition to

template <typename T> class outer {
    int x = 0;
    template <typename U> struct inner {
        void foo(outer<U> const& o) const
	    { cout << o.x << endl; }

    template <typename V>
    template <typename W> friend class outer<V>::inner;

will allow that pathological block of code in main to compile.

I both love and fear C++ some times.


The world keeps turning

And programs need to be built.

Somebody save me.

Beta Reduce? What? Why? A Brief History


You might be wondering why I’ve decided to name my personal website (blog, what-have-you) what I did. The reason is, and this is probably not too surprising, because I’m a huge freaking nerd. This blog post is both a quick overview of my history as a geek, and a justification for why I named my personal website after an operation for manipulating expressions in something called lambda calculus.

The Early Days

When I was a kid in grade school I loved math. Up until about grade 5 or so I would actually do exercises out of my assigned math books just for fun. I nearly lost my mind when I learned my first “theorem”, and I was the only kid in my class who knew more than two significant digits of pi. However due to a combination of laziness and not really giving a shit, I was never picked out for special placement or anything like that. Also, I probably just wasn’t bright enough. Anyhow, aside from doing the occasional algebraic simplification just for fun, I was also somewhat interested in encryption. Not enough to go off and teach myself boodles of number theory (that would come later), but I did toss together the occasional Caesar cypher. Lastly I was also interested in technology - pretty much all of it. I didn’t have an interest in computers specifically until I was in my. teens, but when I was younger I used to tinker around with gears and pulleys and stuff, and also dick around with electricity. I loved batteries.

All this is just to add some weight when I say: I was a dweeb. Never anti-social, but I had a keen interest in science and technology. One time I asked my grade 7 teacher, jokingly, where I could find some plutonium (I had just read a book on nuclear energy). If this were today, I’d have been kicked out of school.

Securing A Future Through One-up-manship, and Buring My Eyes Out

In high-school I began to take in interest in computing. I was connected to the Internet for the first time, and many late nights of Starcraft and MSN were had. I never really used the computer for anything other than a consumption device, until I met some jerk in the grade above me. This jerk had just taken a computer programming class and was boasting about how awesome he was because he could create scrolling messages in HTML. I wasn’t impressed, but it gave me some kind of uncontrollable urge to become better than him in every way at programming. Probably because a) he was a jerk, and b) he was so proud of his crappy little website. By the time I was able to take the class I had taught myself all of the material and then some. The course covered basic web design, which I destroyed him at, and also an introduction to DOS programming with QBASIC. My final project was a Pac-Man clone with decent-ish enemy AI. I barely knew what a sub-routine was. Flash forward through a course the year later that covered Visual Basic and a self-administered course on C, C++, PHP and Perl, and I thought I was hot shit. With nothing else to fall back on (here’s that laziness again) I applied for Computer Science at my local university. I was rejected. So I went back, drank a lot of coffee, raised my calculus grade from barely a 50 to a 95, and applied again. This time I was met with success.

I went through my first year without incident, and by this time programming was my life. I programmed for school, I programmed for fun, I programmed for money. Then came the eye surgery. Part of being a dweeb is wearing glasses. I wore glasses. By the end of my second year of university my eyes were stable enough to make me a candidate for laser eye surgery. Of course I did it. However the aftermath was that for pretty much the rest of the year my eyes were so dry that I couldn’t stand to even look at a computer screen for longer than 15 minutes. Suddenly that theory course I had just taken started to look a lot more interesting. If my programming days were limited, maybe I could be a bad-ass theoretician! From my discovery of programming until about now I never really cared about math. Why bother anymore? I had a new fun thing to do! But deep down inside I still enjoyed mathematics, and it ended up saving me in the long run. With my new set of dry-ass eyes and a rekindled love of symbol manipulation, I dove deep and heavy into the theoretical underpinnings of computing and computation.


During this dive I came across something that completely blew me away. I was reading up on the theory of computation and came across a little thing called the Lambda Calculus. It’s a formal system for representing mathematical calculations in an entirely unambiguous way, and it’s also expressive enough to encode any calculation that a real computer can do. In essence, it’s the worlds simplest, purest programming language - one that you can do with a pen and paper! I was in love. In the span of an afternoon I was able to combine together my love of computers and programming with my previous love of mathematics. Also my eyes weren’t as dry anymore, so I could program again! Things were really coming up daises.

Lambda calculus is a very simple system (it uses “calculus” in the real sense, that it it’s a system for performing calculations, so don’t think rates of change, or finance): Expressions are either simple variables, like x; lambda expressions such as (lambda (x) t), where t is just another expression; or applications, such as (t a), that is, evaluate the expression t with variable a. I’m obviously glossing over a lot of details, but imagine we have an expression that looks something like

(lambda (x) (+ x 1))

where the expression (+ x 1) just adds 1 to whatever value we bind to x. We then apply it to other expressions like so

((lambda (x) (+ x 1)) 4)

The result of the above computation is the number 5. Things can get even crazier when you start binding lambda expressions to variables of other lambda expressions and so on

(lambda (f) ((lambda (x) (f (x x))) (lambda (f) (lambda (x) (f (x x))))))

The whole idea of reducing an expression by one step is called Beta-reduction in the literature. And that’s where this blog gets its name. By the way, the above equations are actually programs written in a language called scheme. It is a member of the Lisp family, and it is beautiful.

… Okay

It was a long story, but the short of it is: everyday geek grows up, trades his love of math and science for computing (probably due to being a lazy git), only to rediscover it (and bridge the two) in an unexpected way. Nowadays I’m a PhD student working in the area of knowledge representation and reasoning, and I get my fill of math and programming every day.

Stay in school kids.

Hugo: Only Show Content Under a Given Section

One thing I initially found strange of Hugo was that it listed every piece of content on the front page - as if they were all blog posts. Luckily Hugo is flexible enough to change that behaviour without having to do any hacking. This blog post is mostly so that I remember how to do this in the future.

To limit your front page to show only content from a certain sub-directory, say, “post”, edit your index.html file (in your theme’s layout). If you see a certain line like

{{ range .Data.Pages }}

simply change it to

{{ range where .Data.Pages "Section" "post" }}

and rebuild your site. Neat! I’m not the kind of person who would shy away from hacking on some code (even go-lang) but easy fixes like this one are much appreciated.

New Site

Every once in a while I like to shake things up a bit around here. I’ve owned this domain since around 2005 or so, and over the years it has changed quite drastically. From my humble web development beginnings, exploring the in’s and out’s of HTML, PHP, etc; to the Wordpress years; to now. Since 2013 I’ve opted to rely on static site generators such as Jekyll, Hakyll, and now Hugo.

Why change? No reason, really. Hakyll is a really nice tool and my website got a lot of mileage out of it, but I just wanted to play with something new. So here it is, the new site. What, were you expecting something more?

2015 Wrapup

2015 is gone now, so I think this is a good time to look back and reflect on some things.

First and foremost, 2015 was my very first full calendar year of being married, and also of owning a house. There were challenges to overcome and projects to complete, but overall I think Chelsey and I did pretty good for our first real year. I’m certain that there will be more challenges ahead, but Chel and I have a way of respectful argumentation that allows us to resolve issues very efficiently - we’re a good team!

Secondly, work was, and continues to be, a spring well of interesting projects to work on. While there’s still a ton of legacy computer software to keep limping along, there are some new projects just on the horizon. 2016 may be the first year that I can actually use the Haskell programming language in a production setting.

Thirdly, while I technically only started my PhD in September, I’ve more-or-less been working on it all year. The sleep project is coming along, and 2016 will hopefully bring some big results. Stay tuned! On the same topic, after much inner searching (pun) I’ve come full-circle back to one of my first loves in computer science/AI: knowledge representation. How we go about representing, storing, and searching through knowledge to come to decisions has always fascinated me. Now it seems as though my doctoral work will be able to touch on that directly.

Finally, the tail end of December 2015 was when I finally started to have a little bit of inner peace. Ever since my Master’s work I’ve been finding myself more and more stressed - for no real reason! If I can guess, I would attribute it to a combination of the regular stresses of work, plus my whacked out sleep schedule. I’m trying to sleep better now, and I’m also trying (again) to incorporate meditation into my daily routine. I’ve always spoken highly of programming languages that can inspect their own structure, and now I’m applying the same kind of meta-cognitive inspection to my own mind. While this sounds pretty airy-fairy, don’t worry: I haven’t gone off the deep end! While I would definitely hesitate to call myself a Taoist in the religious sense, I believe that eastern philosophy has a lot to offer a person in terms of personal growth. I’ll probably write a little about that in later posts, so I’ll stop here.

In retrospect, 2015 was a year of interesting challenges and lots of personal growth. Here’s hoping that the new year will bring more!

Why Emacs?

Why do I still use the emacs text editor after all these years? I could try explaining it to you, but I think I’ll defer this one to science fiction author Neal Stephenson:

I use emacs, which might be thought of as a thermonuclear word processor. It was created by Richard Stallman; enough said. It is written in Lisp, which is the only computer language that is beautiful. It is colossal, and yet it only edits straight ASCII text files, which is to say, no fonts, no boldface, no underlining. In other words, the engineer-hours that, in the case of Microsoft Word, were devoted to features like mail merge, and the ability to embed feature-length motion pictures in corporate memoranda, were, in the case of emacs, focused with maniacal intensity on the deceptively simple-seeming problem of editing text. If you are a professional writer—i.e., if someone else is getting paid to worry about how your words are formatted and printed—emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish.

In short, I use emacs because every other editor I’ve tried only offers a different subset of the features I get from this old editor. Until something better comes along, I’ll be happily M-x editing programs away.

Programming Outdoors

As a software professional, I spend a lot of time indoors. It’s really not so bad: I have a nice comfy chair, ample desk space, and the office is always nice and air conditioned :-) But the past few days have been so beautiful here in Windsor that I’ve been taking my coffee and laptop outside to read the morning news and catch up on email. It makes me remember the good old days when I was working to pay for my undergraduate.

Back when I was in school, I took a programming job for the Odette school of business at the university of Windsor. This programming job had me writing high-performance simulation software to test new optimiztion algorithms for dynamic warehouse management. One of the perks of this job was that I had no fixed office - I worked from home, from the lab, anywhere I wanted. Most days that summer I actually worked from the park by the river! I’d grab my laptop and head out to the water, and work away under the shade of a nice big tree, every once in a while stepping into a McDonald’s or Tim Horton’s restaurant to connect to their free wifi. There I would upload my programs to the compute server I was using for the experiments, and sync my email (this was around the time that I developed my offline-email setup, which I blogged about previously.)

The job was amazing. I was getting paid more than a typical student should have, and I was getting more sun and fresh air, which is always a good thing.

I feel like every programmer should be able to work outside when the weather is nice. Not always, of course. Physical presence in the office is important. But when I was outside working, the happiness I felt feeling the breeze in my hair and hearing the birds chirp and watching the boats go by counteracted the stresses of deadlines, debugging, etc. I love my current job, but I would love it even more if I could take off to the river for a few hours to program outdoors.

Life is Good

I’m sitting out here in my back yard, sipping a cup of freshly brewed coffee. The sun is shining and I can hear birds chirping away in the trees. This is what it’s all about: Not the hustle and bustle of work, nor the never-ending list of things to do with the house. Just me, my coffee, and a beautiful Sunday morning.

This is the life.

And it is good.

Playing Around With Racket

Lately I’ve been playing around with the racket dialect of lisp. Racket is a language of the scheme family, and so far I’ve found it simple enough to pick up through the provided tutorials. Things I like about it are

  1. Simple syntax. It is a lisp, after all, so there are plenty of parentheses. One thing racket does, however, is treat all brackets: (, [, and {, the same. As long as they are balanced by the appropriate closing bracket, they are interchangeable. This allows you to write programs that have a bit more variety than common lisp. e.g.
(let ([x 5] [y 6])
    (+ x y))
  1. It’s very extensible. Racket provides many ways to modify the surface syntax and add new language features. Some examples of how this feature has been put to use are: Racket ships with a strongly typed version of the language, called typed racket, and it can also be extended to support prolog-like clause definitions. The ability to mold the language into anything at all is very appealing to me, as domain-specific language development is a bit of a specialty of mine.

  2. It comes with batteries included. The base install has tons of useful libraries. In fact, one of the first tutorials I went through guided me in constructing a working HTTP server with very little effort.

So far I haven’t played with it enough to pick out any glaring flaws, but since all languages have them, I’m sure I’ll encounter them in due time. So far I’ve especially been blown away by typed racket: the fact that you can mold the language into a strongly typed dialect is beyond my comprehension. Coming from Haskell, the type system isn’t as robust, but it definitely a selling point: all the flexibility of a lisp, with strong typing.

Playing With Bootstrap

You may have noticed that the appearance of my website has changed, starting yesterday. This is because I wanted to find an excuse to mess around with bootstrap, an excellent package of javascript and css for making front-end website design easy. For the time being I’m sticking with one of the sample layouts, but I plan to play around with it in the future, so expect to see some changes!

A Basic Monte-Carlo Simulation in Common Lisp

Monte-Carlo simulations are algorithms that approximate numerical results by repeatedly sampling some space. Generally, the more samples you collect, the higher the accuracy of the result. In this blog post I am going to demonstrate how to use such a technique to approximate the value of the mathematical constant pi.

The high level idea is as follows. We know the area of a circle can be found using the formula A = pi * r ^ 2, where r is the radius of the circle. By using a unit circle (a circle whose radius is 1) the above equation simplifies itself to A = pi. Therefore if we can come up with a simple method for approximating the area of a unit circle, we have a method for approximating pi.

The technique we will use is the following: Start with a 1x1 square, and draw a quarter-circle inside of it - starting from the top-left corner down to the bottom-right corner. If we want to approximate the area of the quarter-circle, we can sprinkle some sand onto the square. The approximate area is thus the number of grains of sand that lie within the quarter-circle divided by the total number of grains dropped. Therefore, to approximate the area of a unit circle, it suffices to approximate the area of this quarter-circle, and then multiply the result by 4.

In order to simulate this process on a computer, we first need a way of generating random grains of sand. The following procedure will generate two points (one for x, the other for y) between 0 and 1:

(defun random-point ()
  "Generate a random point in the range [0, 1)."
  (cons (random 1.0)
	(random 1.0)))

Running this a few times, you will see values such as

(0.9045708 . 0.368289)
(0.42225754 . 0.63779473)
(0.15361631 . 0.61039114)

and so on.

We next need a routine to tell us whether a given random placement of a grain of sand lies within the quarter-circle. We will use the standard euclidean distance formula to determine the distance from the point to the origin (0, 0). If this distance is less than the radius (1) of the circle, then we proclaim that that particular point lies within the boundary:

(defun in-circle (point)
  "Return true if the given point is within the circle boundary."
  (let ((x (car point))
	(y (cdr point)))
    (< (sqrt (+ (* x x) (* y y))) 1)))

And finally, in order to generate a good approximation, we need to run this test many times with many samples. The following function will run the test for a given number of times, counting the number of times the random points lie within the quarter-circle. Once done, it multiplies the ratio by 4, giving us our approximation of pi.

(defun run-sim (iterations)
  "Run the simulation for so many iterations."
  (declare (optimize (speed 3) (debug 0)))
  (let ((good-ones 0))
    (dotimes (i iterations)
	(when (in-circle (random-point))
	  (incf good-ones)))
    (* 4.0 (/ good-ones iterations))))

Running this with larger and larger numbers, you can see our approximation get closer and closer to the true value of pi:

(run-sim 1000)
(run-sim 10000)
(run-sim 100000)
(run-sim 1000000)
(run-sim 10000000)
(run-sim 100000000)

And there you have it.


I’m on vacation this week, and I’ve really needed it. Work is great, but everyone needs a break to recharge after a while. I’ve personally felt my battery draining closer and closer to empty for a few weeks now.

So while on my stay-cation (I jokingly tell people I’m going to puerta my-yarda) I’m hoping to accomplish the following:

  1. Finish installing my hardwood floor. Only the stairs remain.
  2. Fix up my Haskell Weather package. I need to flesh out the remaining API features and generally clean things up.
  3. Fix up my wife’s garden.

Wish me luck, and I’ll see you in a week!

An example anaphoric macro in Common Lisp

Anaphoric macros are macros that capture symbols intentionally, only to refer to them by a different name (an apaphor is an expression referring to another.) A popular example in Common Lisp is the loop macro, which uses the symbol “it” to refer to certain things in different contexts. Here’s an example from wikipedia:

 (loop for element in '(nil 1 nil 2 nil nil 3 4 6)
       when element sum it)

As another example, here we will introduce a special version of the built-in “lambda” special form, that introduces a symbol “self” that refers to the lambda being defined. This allows one to write recursive lambdas with relative ease. First, the code:

(defmacro ref-lambda (params &body body)
  `(lambda ,params
     (labels ((self ,params ,@body))
       (self ,@params))))

In the lisp being returned, notice that we internally define a local function “self” via the “labels” construct. We splice in the parameter list and the body to execute. Lastly, we execute the the new local function “self” with the argument list spliced in. All this is wrapped in a lambda function, so we can still embed code using this directly into the call-site with no indication of any foul play.

As an example, here’s a totally anonymous recursive fibonacci calculation:

(funcall (ref-lambda (x)
           (cond ((= x 0) 1)
	         ((= x 1) 1)
		 (t (+ (self (- x 1))
		       (self (- x 2))))))

which gives us back 8.

FreeSlack: A "free as in freedom" Slackware OS

If you are an avid slackware linux user like myself and want to run a free as in freedom linux distribution, check out the FreeSlack project. They’ve essentially documented all non-free packages that ship with a default Slackware installation and give instructions on how to remove them. They also provide free repositories for use with the slackpkg updating tool.

On Electronic Voting

There was a recent letter to the editor in the online edition of the Windsor Star that criticized the decision to use electronic voting machines in several local communities. I wrote up a comment to the piece, and thought I’d reproduce it here.

I’m a Computer Scientist by training, and a software engineer by profession, and I agree with the gist of what is being said here.

There’s too much that can happen from when you press the button to when the vote gets tallied, and the entire process is near-invisible for the majority of the population. With pencil-and-paper voting, the process is simple and transparent: the papers get put into a box and counted. With electronic systems (especially closed ones - systems where the “source code” for the program is unavailable for scrutiny) the window for tampering is huge! Just off the top of my head: if the company developing the software has a certain political bias, they can easily rig the software to intentionally miscount or misassign votes. Since we can’t see the actual code that does the tallying, how can we ever be sure our votes are being accurately accounted for?

If we are headed toward a future where all voting is done electronically, we must take certain steps in order to maintain the integrity of the process. First, any software developed for the purpose of voting should be freely available for interested parties to read. Nothing is as transparent as a physical paper trail, but if we can’t even see what instructions the computer program is executing, we’ll have no chance in hell understanding the process. Secondly, all voting hardware and software should be developed in Canada. I highly doubt a municipal election would be a candidate for outside tampering, but again, if we’re putting our blind trust in computer programs that we cannot understand, that window stays open. I’m not implying that every voting member of society should be versed enough in technology to understand the inner workings of these systems, but by making them transparent it allows any interested person to perform their own 3rd-party audit of the system. The more eyes we have looking at a piece of hardware/software, the more glitches (whether accidental or intentional) will be found. Keeping the process closed is indeed an assault on our democratic process.

All in all I am willing to entertain the concept of electronic voting, but until the system is as transparent as our current pencil-and-paper method, I will stand firmly against it.

I am definitely not what you would call a technophobe (my research interests are in artificial intelligence) but I feel that any technology used in the public sector - especially technology used for something so fundamental to the well-being of our democracy, such as voting - needs to be open and transparent. By using closed, black-box systems - systems that cannot be audited and inspected by the general populace - to handle such basic democratic responsibilities we forfeit our right to a representative government, as ultimately the electoral results will come down to the honesty of the company who supplies the machines.

Website Updates

It’s been quite some time since I’ve updated my blog, and since a lot has happened this year, I figured it was time for a new post.

To start things off, I got married this past Summer to the love of my life. We had an outdoor ceremony on the hottest day of July surrounded by our friends and family, followed by a beautiful reception at the Serbian Centre in Windsor. Thank you to everyone who came out to celebrate with us! After our wedding and honeymoon, I went into thesis-writing-mode and was miraculuously able to successfully defend in September. Final edits were made, and I am now just waiting for my diploma to arive so I can call myself a Master of Science! Lastly, to really live life in hard-more, while writing and editing and then defending my thesis, I also bought a house. What a year!

So now you’re all caught up. Hopefully I’ll have more time to keep this site up to date now that the dust has settled.

How I Read My Email

When the weather is nice I enjoy working outdoors when I can; since my current data plan on my phone is abysmal, and I prefer working on my full-sized laptop, my email setup is a bit different than normal peoples’. I don’t rely on simply connecting to a remote server because I like being able to read, sort, and reference my email while offline, so this post is a simple description of how I “do email”.

Fetching my email is easy: every 5 minutes my laptop runs the program `offlineimap’ as a cron-job to try and fetch my email from a remote IMAP server. If it fails, it’s no big deal, it will try again later. Once my email has been fetched and stored in a local Maildir, I can use any program that I want for actually reading and responding to email. For this I use Gnus, an email reader that is built into emacs.

For sending mail, I use two programs. First, I use msmtp to send emails off of my machine. Msmtp simply forwards my email to a real smtp server that does all of the heavy lifting. And since I work without a connection and would still like to reply to mail, I use a script called msmtp-enqueue.sh, which saves my outgoing emails in a queue, and a cron-job tries to empty the queue every 5 minutes.

This setup is a little bit strange, and it’s not for everyone, but it gives me the maximal amount of freedom to read and write emails without having always have a constant connection to the internet.

New Year's Resolutions (I might actually keep)

Every year I, like many people, set a bunch of resolutions for the new year and then never actually follow through on them. Well this year I’m intentionally keeping my list of goals very short, so that when I don’t get around to them, my disappointment ratio will be a bit better. So here’s my short list of resolutions that I might actually keep.

  1. Really learn a language from the Lisp family. I have familiarity with some lisps, and I’ve been fascinated with symbolic programming since my undergraduate days, but I’ve never actually built anything useful with a Lisp. I intend to learn a lisp well enough to be able to build something non-trivial in it.

  2. Get to the frickin gym more. I’m a decently healthy guy - I train in martial arts several times a week, and I eat halfway-decently - but I need to be doing more on my off-days. Right now it’s tough because I’m working full time while trying to wrap up a Master’s degree, but I really should be hitting the gym more often, even if it’s just a few times a week.

  3. Improve my touch typing ability. Yes, it’s a shame I know. I spend countless hours programming but honestly I’m not a very strong typist. It’s definitely something that I would like to work on in the new year.

So there’s my list. Will I nail down all 3? Probably not. But I’m going to give it my best try. Happy new year everyone!

Getting Thunderbird to auto-expunge emails

Mozilla Thunderbird is a great email client, however there is one issue that it has by default that drives me nuts. I run an IMAP server for my @bryanstamour.com email addresses. The IMAP server has a Roundcube web front-end for when I want to access my email from a machine that isn’t mine. When working in Thunderbird, when I move an email from my INBOX to a folder (or from any folder to any other folder), Thunderbird doesn’t expunge the emails from their source folders on the IMAP server; it’s only when you close down Thunderbird that the folders get “compacted” and the change is seen on the server. What Thunderbird does do is simply mark the email as deleted and make a copy of it in the destination folder. This is fine behaviour, but if I have Thunderbird running at home (which I do all the time) and access my mail through Roundcube, I still see all of the deleted mails.

However there is a way to get Thunderbird to automatically expunge when mails are moved, and here’s how I got it to work. Open up the configuration editor by clicking on Edit > Preferences > Advanced > General > Config Editor, and set the following values:

  1. Set mail.imap.expunge_option to 1
  2. Set mail.imap.expunge_after_delete to True

Close the editor and restart Thunderbird (just to be on the safe side) and now moving mail from folder to folder happens on the server instantaneously.

New Slackware Disks

My Slackware 14.1 DVD arrived in the mail today. I know what I’m doing this weekend… I’ve been a subscriber for the past few releases now (I enjoy giving something back to Patrick for all of his hard work, even though I can download the ISO’s for free) and every time there’s a new release I wait patiently by my mailbox. It’s like Christmas for my servers.

Why Slackware? I used to bounce around between Linux distros a whole lot. I started out with Ubuntu 6.10 Edgy, and after a few releases tried Fedora, then PCLinuxOS, then OpenSUSE, then… you get it. I found my way to Arch Linux after a while and stayed there for a few years, but I got sick and tired of having to fix something or other every time I ran an update. I tried out Slackware because I had heard good things about it, and I’ve never looked back. Slackware is feature-rich out of the box, and very stable. It now runs my web server, my print server, and both my desktop and laptop. The only machine under my control that doesn’t run Slackware is my mail server (which runs Debian Stable), but down the road when I move that out of a VPS and into my house, it too will be running Slackware.

Thanks, Pat, for another awesome release!

What the heck is C/C++?

I see this all the time in programming forums, websites, etc. My one question is:

What the heck language is C\/C++?

C and C++ are distinct languages that have a similar looking syntax (the same goes for Java, C#, JavaScript, Perl, etc.) And just like the languages I\’ve mentioned in parenthesis, C and C++ also have many syntactic differences. So if they don\’t have the same syntax, there must be another reason why people conjoin the two languages…

Do they support the same language features?

There is a misconception that every C program is also a C++ program, or that C is a proper subset of C++. This is false. C++ has had a stronger type system than C\’s, and a concequence of that is certain valid C programs are not valid C++ programs. Case in point:

int *ptr = malloc(sizeof (int) * N);

is valid C, and is quite common, since void pointers can be freely cast to and from other pointer types in C. It would be line noise to write the explicit (int) cast in front of it. However C++ clamps down on this restriction and forbids the implicit casting of void pointers to other pointer types. You need an explicit static_cast to make the code valid C++.

C also supports the ability to allocate arrays on the stack. These were introduced in C99 and have yet to be adopted by the C++ language. (NOTE: There is some work going into bringing a concept similar to C-style stack-allocated arrays to C++, but they will behave differently in order to preserve the semantics of sizeof).

But they’re used in the same way, right?

So they don’t have the same syntax, and they’re not subsets/supersets of one another, what about best practices?

Since C++ supports RAII through constructors and destructors, it has greatly simplified resource handling to the following formula:

  1. Aquire your resource in a constructor
  2. Release your resource in a destructor

The above, combined with allocating your objects on the stack, unless you really need to, results in clean, deterministic resource management. How could we do this in C? The best I can come up with is the following:

  1. Aquire your resource through a function call (passing a pointer to your resource, so that you can indicate failure through the return value.
  2. If the return value is bad, goto cleanup
  3. Use your resource, repeating steps 1 and 2 for any other resources you need.
  4. Clean up your resources at the bottom of the function, lest you leak memory, files, etc.

I’m not criticizing the C style, I’m just showcasing the difference between the two languages. Both styles have benefits, but they sure don’t look the same.

Anything else?

I could iterate through several other examples of how C and C++ differ, both at the language level and also with regards to best practices, but I think I\’ve made my point fairly clear. There is no language called C\/C++. If anything C and C++ are sibblings, with the parent being K&R C. Both C and C++ have evolved from their common ancestor, and they do occasionally share features, but they are in no way the same language, and should not be grouped together. It makes as much sense to start referring to Java\/Ruby since they both inherit features from Smalltalk.

Hello world!

I’ve been itching to play around with something new recently, so I decided to move my blog over to one based on Hakyll (think Jekyll, but written in Haskell.) I hope to blog more as this site evolves, and maybe this time I’ll be able to keep my web presence a little more active. I look forward to writing posts about my explorations into various topics in programming, computer science, and other things that I’m passionate about.