Inspiration for the masses

Getting closer to my work term I also look for inspiration to motivate me and peak my enthusiasm so that I can bring into the workplace. Browsing TED (something I’ve missed doing in a while), I immediately came across Steve Job’s Stanford Commencement speech.

Stay Hungry, Stay Foolish

I got an eerie chill listening to his story and how pieces to his puzzle of life only seemed to fit after reflecting upon them; for instance like his calligraphy lessons. The point of the talk was aimed at don’t accept anything but true love and passion for a job and constantly be on the lookout and search for that passion. I am hoping that in this new job, my search is over.

Seth Godin

I really like Seth Godin. He gives riveting talks that are funny while still driving home a message. He is a wealth of stories, of which I could sit for hours probably just listening to. Although everything i’ve heard him say ( I plan to read a few of his books) is accurate and logical he seems to be always reinventing his own wheel between each talk, but at the end of the day it’s still a wheel? Confused by what I said? I know I am.
Essentially what I get from each of his talks is that :

  1. mass marketing is dead.
  2. viral marketing is the future/present
  3. marketing now for the extremes rather than the average

These are the staples of most talks he give, and he will bundle them up in a brand new metaphor or idea differently between all he talks I’ve seen. It’s not the problem that he is reiterating the message continuously, but rather that he it seems as if he is attempting through rewording the message to create a new one?

Regardless great talks.

Take care of my thoughts, won’t you?

Final Thoughts on 3B – Mainly Concurrency not Concurrently

So I have just finished my 3B term with courses: Algorithms, SciFi, Concurrency, Software Engineering Requirements and Specification, Databases, Upper Year Design Project. From all the courses this semester, my favourite by far was Concurrency (CS343).

As I’ve covered in a previous post, the bulk all of concurrency was devoted to learning UW’s open source C++ extension uC++. My last blog covered up to only coroutines, however uC++ increased in complexity tenfolds by the end the of term. uC++ offers _Task, _Monitor, _CoMonitor constructs which are essentially native mechanisms for implementing a concurrent application. I can not go into too much detail (as it would take 4 months) but I believe the implementation of uC++ was exceptionally straightforward and allowed for daily concurrent problems to be solved easily, versus thread libraries such as those included in Java. The environment was even nice enough to inform you when a deadlock had occurred (useful for a learning environment).

Back to Work

Me in a wet suit.
This wetsuit is too tight.

So I have successfully completed my 3B Software Engineering term, surpassingly with strong marks. I was shocked to discover with enough caffeine, I had successfully managed to keep on track with gym, weight loss, hockey, studies and a generous helping of partying.

I will begin my new internship at Digital Extremes developing an upcoming Ps3 title. I am excited to try out a job I’ve dreamed about and I am hoping it does not ruin the magic, similar to learning a magician’s lies secrets. I am looking forward to the myriad of new developer related trials and information I will absorb and store here, instead of my overstuffed cranium.

Things to write

If I don’t write my thoughts out now I will forget. This upcomming 4 months will be hectic and here is why:

  • Software Engineering Project: Tournica – Insights onto developing a Ruby on Rails application.
  • Keeping track of weight loss, weight exercises and general nutritional tips to myself (mainly involving recipes I’ve found effective).
  • Digital Extremes Problems – Problems faced and hopefully solutions discovered
  • I will be attempting to repass through a large quantity of games this semester, hopefully analyzing them now with a deeper knowledge of game development.

Science Fiction

On a completely different topic, I’ve finally finished Paul of Dune , leaving me the next volume to read. I’ve recently just taken a SciFi course where the professor was overly critical of Dune. Most of his points involved the fact that it is too “Black & White”. For example, the antagonist the Baron Harokonnen is a fat, sadistic, cruel , gay and sodomizing bastard. Although most of his points I agreed with, I only did so for the original novel. I’ve actually enjoyed the extended storyline by Frank Herbert’s son and believe that he has really shown in the prequels and other novels a nice examples of conflicting heroes and anti-heroes.

Quotes I liked

The greatest personality change in a young man’s maturity occurs when he discovers that his own father is mortal, human, and fallible. [Paul of Dune, p.43]

I want no allies but myself. Friends can be as dangerous as enemies. [Paul of Dune, p.406]

A sharp edge does not automatically make a sword a good weapon. Only the wielder can do that. [Paul of Dune, p.385]

Weapons come in an infinite variety of shapes and designs. Some look exactly like people. [Paul of Dune, p.334]

Course Work

I’m considering beginning to save all my course work on my blog such as my concurrency assignments (which I am very proud of), and my work reports as well as solutions to assignments. I will think about it… I am so proud of my concurrency work; concurrency problems never failed to be easy to me.

EDIT: I have updated the projects page (look above) with some coursework and relevant documents. More to come.

uC++ and Shooting Yourself in the foot

Almost at midterms….
One of the most enjoyable courses this term have been my concurrency course CS343. In the class we are using uC++ (mico C++); which is an extension by the University of Waterloo to add high-level concurrency in an object oriented language. So far what we have covered is the ability for “Coroutines” to maintain a separate stack through execution. Using this feature we have been able to solve some interesting problems in novel ways.

Here is an example of some uC++ code. Every coroutine must have a main method which is executing upon calling the inherited Resume() function of every couroutine on the this object. Once inside main(), you can suspend() the coroutine and execution will then unwind back to the original caller. Further resumes() cause the coroutine to start from the same location where the suspend() had occurred (“partial coroutines”).

I am curious to see where the course leads us to in use of uC++. Would be perhaps even neater to learn some GPGPU “ultimate concurrency” in my opinion.

Shooting myself in the foot

Interviews have begun and I made the mistake of applying to 54 jobs. The result is that I now have tons of interviews. Sounds like a good thing? In theory perhaps; although I am finding myself short on time to complete assignments and my extra curricular activities. I will try and get a photo up soon of all the interviews I’ve had once they are complete.

Crossing my fingers

Return to Campus

The North American engineering tradition of dying yourself purple.
The North American engineering tradition of dying yourself purple.
Orientation week is now over and I am begining to return to my normal skin colour as opposed to the beatiful colour purple I was sporting as week. It’s been a while since my last post but hopefully once I am back on track with school work they will come a bit more steadily.

Well where to start…. School has finally started up and I’m excited scared to be entering 3B in Software Engineering. I’m not going to lie and will admit what excites me is that this year is that we are the most senior Software class looking for internships during the winter term which means we have no competition (hardly none) from schools in the US. Hopefully my hard work and awesome program will pay off and my excellent stream of co-op jobs continues.

I want to take a unusual diatribe in something non-Software related, specifically Science Fiction. Today marked the first day of my Science Fiction class; something which I have been looking forward too. I must admit that within the first lecture I am already noticing that by the end of the class I will have undergone a few paradigm shifts.

The professor has already posed some challenging questions that have caused me to begin to rethink my ideals. One such question posed was “What defines a novel to be classified under Science Fiction?”. The challenge was distinguishing Science Fiction from Fantasy; something which turns out to be rather difficult in some situations. A great example was Star Wars. Essentially the original three novels introduces the reader to the novel idea of “The Force” without any explanation. The lack of explanation is something representative of Fantasy, however in Episode I it is explained that the Force is the cause of Midi-chlorians. At this point the genre begins to tread towards being more classicly Science Fiction. Clearly the line between the two can easily be fudged and ultimately the sad answer was that the publishers will simply attach the label Science Fiction if they feel it will cause the book to sell copies.

One of the most interesting & simple questions also posed was:

“Know thy toaster, know thy self”

The professor had began the lecture asking the class for what they believed this sentence meant. Essentially there was no proper answer, but listening to the different meanings people extracted from the sentence was intriguing. Essentially the discussion revolved mainly around points involving technology and its impact on society. If anyone has any interesting takes on the quote please post them, I find it very interesting.

Elegance and Gripes

Much of the programming I have done at the University of Waterloo has laregely been solo endevours. Even in the few cases where the projects supposed to be group efforts; I would end performing the majority of the leg work and keep a meticulous eye on the others. It is not an issue where I believe myself to be a dictator in group scenarios rather that:

Many people are terrible at collaboration and lack elegance to their programming.

What do I mean by elegance?

Most programmers given a task can complete it. The distinction lies to me is in the programmer who can solve the task elegantly. Writing “elegant” (I will continue to use the word for lack of a better one) can be most of the time somewhat straightforward if you are the only person working on the task. It becomes difficult once it is in a group setting. It is bad enough to avoid toe tripping on a large project without having to spend obscene amounts of time to understand a simple function.

An example of certain hair-pulling wtf moments is something similar to what I saw today;

Instead of returning true/false if the function succeeded, enabling panic mode in fact returns the state it is in…

Pulls hair…

My list of things that have given me grief:

  1. Hungarian Notation
  2. What is Hungarian Notation?
    Hungarian Notation essentially boils down to the use of prefix for the purpose of giving a hint to the purpose of a variable.
    There are plenty of issues I found I have disliked with regards to Hungarian Notation, most of them stem from the fact that it is no longer needed, especially in C#.

    bBusy: boolean
    m_wheels : member of a structure/class

    My gripe with Hungarian Notation is that everyone follows a slightly different version of it, resulting in code that is less readable. For instance I prefer to begin all my member variables simply with a _ (underscore) whereas others prefer m_.

    Half the reason of using a constant notation is so that the auto completion (intellisense) can quickly provide the full list of member variables. Using two different notations defeats this purpose.
    Assigning prefixes to denote what the variable represents is becoming less important as well now with the ability for qiuck introspection provided by the IDE.

  3. Needlessly throwing exceptions
  4. There is a time and place when throwing exceptions is the better course of action. My frustration is when developers (specifically one who is working on the same project as I am) simply decides to embed every function call with a try and catch (not the main issue) and then write code prone to many exceptions (the main issue). One simple improvement I had made in the application we are developping was simply that the application was throwing constant DivideByZero exceptions. A simple debugging of the program shows that it is a result of mis-ordered initialization, which was a 1-2 line fix.Instead of investigating the fix initially, what was instead implemetned was a series of try&catches everywhere the divides took place.

  5. Compiler Candy
  6. This one may not be a big deal however I find it a nice bonus. One of the nicest features of using a language still in constant development is to take advantage of the new features that arise. C# is great with providing tons of candy with each new release (looking forward to 4.0). A quick list of features I wish were used more frequently which I really won’t go into detail but will just like to write down:

    1. Automatic Properties:
    2. It helps readability and refactoring. I </3 the mix&match of assigning variables within the class through the Property and directly through the member variable itself.

    3. Lambda Expressions:
    4. If all the function does is compute A+B and isn’t resused save me from navigating to a different project and file just to see the method and use Lambda Expressions.

Next post I’ll probably talk to myself about how I an learning to use the Visual Studio Profiling Tool.
It is a pretty impressive tool, one which I had a book on rather than the simple tutorials online.

Simulateous Learning

I can never seem to focus on learning one particular thing at a time. I have written previously about how I’m investigating IronPython; which probably to most people would be their main focus. I however cannot settle to learn one thing at a time.

I recently picked up a book on iPhone development and decided to spend the next week or so learning the SDK and perhaps creating a few simple applications.

I have a small serious problem of beginning projects and not completing them because I try to create something too large initially. To hopefully fight this urge, I have been restraining myself towards more simple projects with multiple iterations, something which I experiemented (and found success) with when attempting to develop a ridiculously simple image application. I plan to follow a similar approach for an iPhone application.


I am currently learning (or rather re-learning ) old as well as some new design patterns in Python. Existing GOF design patterns can be tweaked slightly in Python to take advantage of dynamic programming, as well as some additional dynamic programming exclusive patterns.

So far my largest gripe currently with learning Python/IronPython is the lack of auto-completion.

There are attempts to provide auto completion for IronPython however once you have tasted Intellisense…

It’s tough to go back.

Much of my learning originally of the .NET framework through C# I can attribute almost soley to the autocompletion. A typical case of experimenting with a new Control object might follow something like:

Create object -> browse autocompletion -> find something sounding like what I am looking for -> Visit MSDN

Not to mention that a lot of the code written for WinForms is handled by the visual editor; I am not acustomed to setting many of the “default values” that VS hides nicely from me. I found it useful to howveer keep VS running along side writing any IronPython code and copy/paste much of the code in the designer.

Python making things easier; will IronPython do the same?

A little more IronPython

Working my way very slowly through IronPython in Action, and so far it is pretty neat. Probably the craziest thing is building a GUI application using the interactive console. However in order to get the most of out that joy, the interactive console must be placed on a separate thread. Normally it is on the same thread as the GUI thread causing it to lock up since the Form is in a continous loop.

The IronPython distribution provides a sample script Winforms specifically places the console on a separate thread to play around with the GUI interactively. With winforms imported, you can display the form by calling form.Show () rather than Application.Run (form).

Making changes to the GUI during runtime makes me smile


I find an important IDE crucial in learning/using a language. Most people I speak to try to persuade me otherwise telling me it is more of a crutch and that I should perhaps stick to basic text editors (ex. VIM). For example; it was a joy to use VS2008 in learning C# (especially the visual editor). I cannot imagine doing most of the work I did without the visual editor and Intellisense. Therefore I set on a search for an IDE to learn IronPython as it is currently not supported in VS (hopefully 2010).

A somewhat quick long browse through the web resulted in me experiementing/investigating the following options:

  1. IronPython studio

    Initially I was excited to see a build of Visual Studio (using the VS SDK) that includes IronPython support. However I quickly discovered that it doesn’t work with IronPython 2.6.

  2. Eclipse

    Rule #1 I learned is to always check Eclipse for a plugin for a lanaguage I’m learning and most of the time there is great support for it. This was true with respect to IronPython and Eclipse does have a plugin for IronPython support. Best of all they included auto completion for most of the .NET libraries which I’ve been reading is somewhat difficult to do given that most of the type checking is done during runtime. The two drawbacks I noticed is that :

    • No Debug support
    • Takes a while to launch script
  3. I looked into some more lightweight options which mainly focused on a simple good text editor.

  4. Notepad++

    I’m a fan of Notepad++. I install it on every machine I use, since I find it to be a very great lightweight but highly extensible editor. Although it has no native support for IronPython, the Python language support was enough to make it useable.

  5. Davy’s IronPython Editor

    This one caught my attention because it is an editor written in IronPython and it is very lightweight. It is still in development so some features seem to be incomplete although it gets the job done nicely.

In the end I decided to go with a more lightweight approach since I am sticking to smaller scripts. The IronPython tutorial (included with the distribution) includes help for setting up on using VS to debug IronPython or using the CLR debugger.

Time to pick up the pace…

IronPython, C# 4.0 & Me

IronPython In Action

This week I had picked up a copy of IronPython in Action.
Lately I have been writing or mentioning at least how I am pretty impressed about the .NET framework/Visual Studio/C#. I found things to be extremely fluid, logical and pretty much straight forward using C# (with the nice room to get complicated if you’d like).

Python though has remained outside my scope of knowledge for quite a while. I have friends who swear by it and I’ve been always been meaning to learn properly a scripting language. I had briefly touched Python in one my CS courses, however it was using Jython which is an implementation of Python written in Java. To be honest, at the time of learning Jython (pretty much Python) scared me a little.

Dynamic programming languages scare me a little
The ability to cast on the fly scares me.
The ability to create member variables on the fly scares me.

Data attributes correspond to “instance variables” in Smalltalk, and to “data members” in C++. Data attributes need not be declared; like local variables, they spring into existence when they are first assigned to. For example, if x is the instance of MyClass created above, the following piece of code will print the value 16, without leaving a trace

I can see the benfit of being able to do it and the marvels that it can accomplish; but it seems it might cause a nightmare for debugging someone else’s code. Although I’ve never tried so hopefully I’m wrong.
I think buying this book is a good start. It seems as if Dynamic programming requires rethinking problems in a different way; similar to trying to solve a problem parellelly rather than sequentially.

The real reasons what attracted me to try and learn IronPython is the development cycle to create a sample WinForms application looks to be much shorter and much of it can afterwards be easily ported to straight C#. Finally a good CS professor once told the class that:

All programmers should know at least one scripting language

C# 4.0

Seems as if learning Dynamic programming design pattern and principiles could be useful especially with the upcomming release of C# 4.0 I was recently going over the WhitePaper for C#4.0 and they are heavily entering the forray of dynamic programming it seems especially.

C# 4.0 introduces a new static type called dynamic. When you have an object of type dynamic you can “do things to it” that are resolved only at runtime:

The C# compiler allows you to call a method with any name and any arguments on d because it is of type dynamic. At runtime the actual object that d refers to will be examined to determine what it means to “call M with an int” on it.
Other things which will allow for code refactoring seem to be introduced in C# 4.0 as well such as optional and named arguments. I can finally stop from creating so may overloaded methods.

Anyways in the mean time I will be playing with IronPython. There is something sexy about interacting with a GUI through an interactive interpreter.

I have failed.

Although I love C# and how it does a good job in hiding a lot of the intricasies of pointers that C++ enjoys exposing. I prefer to have things hidden from me only when I know I understand what is going on. Today was a rude wakeup.
I hadn’t thought it had been that long in which I had written any C++; I guess I was mistaken.

Today I had the pleasure of completely implementing a simple linked list in C++ completely wrong.

In my defense, I really only faulted on aspect; however this aspect I guess now seems very silly to have gotten wrong and I am actually not even sure how I become misinformed when the right answer is so obvious.

Passing pointers by reference

For some delusional reason, I was under the impression that the only difference of passing a pointer and passing a value by reference is that the compiler would hide all the *’s and -> for code readibility.
Turns out (like always) apparently there is more at work than I understood.

Passing a pointer is pretty much passing a value and a local copy is made onto the method’s call stack. Where I err’d is in attempting to re-assign pointer values within the method.

What I should have done was clearly too either pass in a pointer to the pointer or in my case I chose to do:

Now to be fair. I decided to implement LinkedLists in such a way so that the head never needs to be reassigned once declared. This is obviously a stupid way of doing it; with the logical solution to always just return the pointer to the new head.

Anyways, at least I can say that I ended up learning the right semantics.

What did you do with my resources?

add_action(‘wp_head’, ‘mypage_head’);

I spent a good chunk of my day today really trying to learn about .NET Garbage Collection because as I had found I was under a lot of misconceptions/misunderstandings of how it works.


I was mistaking this for something similar to a destructor which in C# is the finalize method. This method is defined for any class that inherits from the IDisposable Interface. Implementing the interface allows you to also declare the object with the “using” keyword.
The purpose of this method is to provide the programmer a chance to “clean up” the object properly before they are released especially if they have references to unmanaged code (Window handles etc..)

The part where I was thrown off and took a long time reading to understand and learn is that in most cases (pretty much all if done correctly) you still don’t need to call Dispose on the object.

For instance, say you have a managed object with an unmanaged member variable. If the Dispose design method is implemented properly there should be a Finalize method that is declared which calls Dispose () anyways.

But remember, C# doesn’t support destructors. Don’t let the identical syntax fool you.

The problems begin to creep up in doing this in a efficient way. Thankfully .NET provides all the functionality needed to properly do this. When a class implements a finalize method, the way in which it gets garbage collected is differently than other items (Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework).In short, it gets put on a different queue which can result in a large performance cost.

The following example from MSDN shows how to properly implement the Dispose pattern:

You can see how using this proper dispose pattern, if Dispose() was called by the programmer the finalize method is suppressed removing the need to call it again which would essential attempt to clean up the resource twice and we reattain the lost performance.

So I am in the woods on when someone would have to or would actually want to call Dispose on an object considering the GC will eventually call it for me anyways and the following:

What doesn’t happen when you call Dispose():

  1. Calling Dispose does not prioritize the object for garbage collection. It simply unloads the object’s (unmanaged) resources from memory.
  2. Calling Dispose does not deallocate the object from memory. Only the GC does that when it performs a collection of the generation in which the object resides.
  3. The CLR does not insert or run any code not in Dispose. The behaviour of Dispose is defined by the developer.
  4. Dispose must be called explicitly by the application. It is never called by the runtime. The only exceptions are when using C#’s using statement (see ShawnFa’s article for a good explanation of what exactly goes on), and the foreach keyword in C# will result in Dispose being called on the Enumerator
  5. Dispose is NOT threadsafe. This means two threads can call Dispose on the same object at the same time. Like for any other synchronization-sensitive method, take steps to make sure this doesn’t happen. I’ll give an example of when this might happen in the next section.

The oddest aspect as well is that the object is still alive after a call to Dispose (can very well be alive for a long while if the GC is in fact not needed to be called) and can be continued to be used unless the class checks in every method isDisposed which they never do.

Who knew being a garbage could be so fascinating…