Thursday, February 7, 2008

Tuesday, January 22, 2008

I HATE filling out those custom CV forms on job sites

My ideal job is anywhere where I can:

1. Learn and improve myself as a technician and human
2. Improve the world around me through my skills as an engineer and leader
3. Enjoy the passion and comradery of a truly unique group of people

In more concrete terms I find that the kind of workplaces that foster such an environment tend to be those in R&D, academic, or Free Software companies. I think what I consider to be an ideal company, right down to the details, is already well known and commonly held among serious professional programmers, the kind of people my ideal company staffs itself with.

I want to be exposed to a large breadth and depth of technologies, and given a chance to challenge myself. I want to work together as a team to accomplish things I could have never done alone.

I consider life to be a marathon race until death, not a sprint until twenty or thirty years old.
I want to die a great man in the judgment of the people who are closest to me.
And I realize that the only path to where I want to go is one with daily dedication to learning and growing just a little bit more than yesterday -- from this moment, until the time when the world passes me by.

Its in this way that I take my work, my life, seriously; but no more serious than I take the rising sun, or my daughter's smile. As it should be.

My idea workplace would be one where people understand, and agree, and walk with me down this road.

I have a dream

I'm not big into politics, especially American politics, but I think it is the perfect timing for rare moment when someone brings a message that brings out the very best in our human nature.

Saturday, January 19, 2008

(Haskell) Monads for Imperative Peeps

Warning, since I am still learning Monads, it's quite possible the following is partially or even entirely wrong.

Why Monads


Functional programming languages have the constraint that their functions cannot have any side-effects. A function cannot do anything except produce a return value which is strictly dependent on its input values.

This is done for many good reasons. One such reason is to allow allowing some pretty mean performance optimizations: specifically allowing each individual "pure" function to run on their own processor core, since by definition each function is dependent on its input only, and can run efficiently this way.

However this constraint effectively eliminates entire sub-sets of useful and essential operations. Most notably IO operations such as printing or reading from the console.

A monad is a abstract idea that allows functional languages to stay theoretically coherent by encapsulating side-effect producing operations within themselves. Monadic functions can then be separated from the remaining pure functions when optimizing.

Monads are also extremely useful for encapsulating entire classes of behavior by type. For example a monad for functions that print or read from an OS provided data source is called IO. For functions that print or read strings from the console, the embedded type for IO would be String, and thus their type would be String -> IO String.

What are Monads


In programming languages, monads are meta-types that embed other types.

A monad has 3 parts:
1. A type construction, which defines how to embed a type in the monad
2. A unit function, which explains how to place a value of a type into a value of the monad, "as is"
3. A binding operation, which explains how pull out a value of a type from the monad, apply a pure function to it, and return the result to the monad

As an example we will construct a monad called Maybe that defines a type who's values are either invalid, or from a valid range:

1. data Maybe t = Just t | Nothing

Which says that the monadic type Maybe with parameter type t is a type who's values are of type "Just t" or "Nothing". Nothing is the type of invalid values.

2. return x = Just x

Which defines a function that wraps any value in the identity type Just, and thus embeds it the monad Maybe by our definition in 1.

3. (Just x) >>= f = f x
Nothing >>= f = Nothing

Which says that any function f can be applied to the type Just x as a normal, every-day function call; but any value of the Nothing type always yields Nothing. This means that whenever an invalid value is encountered, all functions from that point on are also invalid.

Tuesday, January 15, 2008

It's Ironic

They flee from me that sometime did me seek
With naked foot, stalking in my chamber.
I have seen them gentle, tame, and meek,
That now are wild and do not remember
That sometime they put themself in danger
To take bread at my hand; and now they range,
Busily seeking with a continual change.

Thanked be fortune it hath been otherwise
Twenty times better; but once in special,
In thin array after a pleasant guise,
When her loose gown from her shoulders did fall,
And she me caught in her arms long and small;
Therewithall sweetly did me kiss
And softly said, "dear heart, how like you this?"

It was no dream: I lay broad waking.
But all is turned thorough my gentleness
Into a strange fashion of forsaking;
And I have leave to go of her goodness,
And she also, to use newfangleness.
But since that I so kindly am served
I would fain know what she hath deserved.

--

Friday, January 11, 2008

Always Plotting Something...

An amazing source for a tool I always found hard to figure out: gnuplot.

Saturday, January 5, 2008

So sweet it'll make you sick





Friday, January 4, 2008

Thinking in git

"git" is a distributed source code management tool that is gaining a lot of interest from many corners of the international software development community due to its incredible flexibility and power. I like to compare it to powerful text editors like Vim or Emacs: it has a steep learning curve, but once you pick it up it will increase your productivity immensely, and if you are a professional programmer who takes himself seriously, you owe it to yourself to learn it fully.

However, using this new power-tool, like all specialized tools, requires readjusting you way of thinking about how you work before you can take advantage of the benefits.


1. Your local clone is also a repository in its own right



A repository is a .git directory. Every functional instance of a .git directory represents a full-featured repository, regardless how you came to possess it.

Its a deceptively simple but profound change in perspective. Ponder the implications fully.


2. All repositories are created equal



There is no inherent security policy in git (you have to piggy-back on SSH or Apache for that), and there is no sense of hierarchy among repositories that you do not define yourself through external policy.

Once you clone a branch from a remote repository, the originating branch is technically no more authoritative than yours is. The only technical constraint on branching and merging across repositories is that all branches must have a coherent history.

If two branches across repositories grow apart over time, and it is desired to reunite them into a common public branch, anyone attempting merge the two must reconcile the histories is such a way that other repositories are able to recognize the history as either a common ancestor of a local branch, or reachable future given their current state.


3. Branch everything



Branching and merging is the bread and butter of a SCM, so it hopefully goes without saying that branches are trivial, and merges are as smart as possible for a machine, so use them.

Branch to test out a idea. Branch to test out a merge. Branch to impress your friends at cocktail parties.


4. Git is a low-level tool



Git, from the beginning, was designed to be a low-level storage format for a Distributed SCM, and its only recently that git has included within itself some high-level commands for the kind of basic operations that programmers care most about. If you take the time to understand the basic representation that git uses, you will find it harder to get confused about why the high-level commands do things you didn't expect them to do.

Git assumes very little about a programmer's workflow, and converts your commands to into rather simplistic and literal manipulations upon the basic data structures within the .git directory, so it pays to take a look inside the internal representation once and a while to verify your assumptions.


5. You can break your own repository, and others'



Since git makes almost no assumptions about your work flow, contains no inherent security policy, and has no concept of repository hierarchy, it is very easy to do something that can seriously ruin anyone's repository.

Git tries hard to be non-destructive when making changes, but it will always do exactly what you ask of it. And while an experienced git user can likely recover from a whole host of mistakes, there is no guarantee that you can.

While learning git, always back up your working source and .git directory regularly. Always make new branches to test out your actions before you proceed on important branches. And finally, take care when pushing/pulling changes to/from someone else's repository.


6. Every commit is a change, uniquely identified by a SHA-1 hash number



The basic currency of git is a set of changes to the .git data structure represented by a commit, and every commit is uniquely identified by a SHA-1 number.


7. A repository is a directed acyclic graph of commits, with named branches



As commits succeed commits, a linear history is built within the .git directory. When a branch is made it is given a name, and when a commit follows, the history becomes a tree and thus non-linear. When a merge happens, the two histories are joined together under one of the named branches.

Since history only proceeds in one direction, the graph is acyclic.


8. Commits and branches exist in your .git directory, not your working directory



Git stores the above DAG compressed in data structures in your .git directory. The files that appear in your working copy is only a decompressed representation of those structures, after they have been processed by your git commands.

If files appear to be out of place or missing, consult the git command line tools to inspect the .git repository first.

Culture Clash

I often find myself complaining internally about all the things I find broken about Japanese culture, and why it needs to change before it can join the ranks of modern societies. However instead of being so negative, I thought I'd turn things around and talk about how Japanese handle certain kinds of problems and how their backwardness is wisdom in disguise -- something they have discovered that the rest of the world, especially Americans, really need to figure out before they can be called civilized:

While ignoring a problem will never make it go away, many times turning a blind eye to a problem really is simply the best choice among worse alternatives: Attempting to fight against a tide that is not ready to change will only make things worse, and the best option you have available is to just ride it out.

Its tempting to look at Japanese who are ignoring a glaring problem by putting their head in the sand as childish and irresponsible, and take the position that our western tendency to leap on problems as obstacles to be overcome through a vigorous response, is clearly the progressive and adult way to handle our difficulties.

However if we take the position that we must clearly examine the real-world results of both active and passive responses, we will find that the reality is that our desire to interfere in things we cannot actually control often only makes things worse. And the so the "foolish" course of ignoring problems allows conditions beyond our control to work themselves out in time; without requiring our personal intervention, and thus actually turns out to be the only method of reaching a positive outcome.

So often our ethnocentrism is just not justified in practice. And with a change of perspective we find ourselves viewing our actions not as being proactive and adult-like, rather childishly self centered, impulsive, and obstinate (-- as Japanese view them).

Tuesday, December 18, 2007

Job Update

I promised many people that at some point I would write a post to help clarify what my job situation has been, where it is now, and where it looks to be going. However, due to the fluid nature of situation -- depending many things that hadn't been entirely concluded, I was reluctant to set thought to words until now.

At my previous company I was working with rather industrious Chinese immigrant, now with Japanese citizenship, whom we will call J.

J. was introduced to a system called "Second Life" at some point in his travels, which is a particular implementation of what could generally be called Virtual Worlds. VWs are essentially about using the Internet and immersive technologies (specifically modern 3D graphics), to help advance our online experience to something that helps fulfill our needs better than current, essentially 2D ones. So, for example, instead of using a 2D website for social networking, or a 2D chat agent to chat with your buddies, you would create a 3D avatar, go into a realistic 3D space, and chat and socialize there. Moreover, instead of creating your own text-and-image-based 2D website content on your own site or blog, you could own virtual land, and create fully-scripted (and therefore active and orchestrated) 3D objects on your land.

When considered in the context of the current Internet, it becomes obvious that VWs are simply a single convergence point for newer technologies that exist on everyone's modern desktop PC, and the same needs that drove the creation of the 2D Internet before it.

So J., having become infatuated with Second Life and wanting to take advantage of what appeared to be an emerging market -- but not really knowing how to, my co-worker decided to set about networking with whomever would listen, and see what would drop into his lap. J. approached me and appeared to be interested in cultivating a friendship with me; and then later with recruiting me to his yet very embryonic enterprise.

Having just met him, I has assumed that all his attention towards me was genuine, and that is interest must stem from possibility that when he learned more about my personality, he saw the potential in me that I know has always existed, and being such a sharp judge of character he was trying to leap on a "diamond in the rough" in recruiting me.

Later I was to learn that that was simply an operating mode of his: where he meets new people, calls them "friend", and bids them to join whatever his current cause is; then promptly moves on until needed again -- a user's mentality. That sad reality was born out in several instances where true friend would have stood by me and supported me, but instead he let me down and did whatever he wanted to at that moment.

It was also another operating mode of his was to take people out for dinners to "talk business", where in reality the talk was always of a superficial and vague nature; where items previously concluded, or questions asked, always came up again as if no discussion had happened previously.

This I believe comes from a desire to "look the part" of a big free-wheeling executive-type -- enjoying the superficialities, without having to get down to the dirty work of deciding things and taking responsibility for your decisions. Sadly this cultivation of "executive aire" over these path months has worked: people treat him seriously even if they see his words don't make sense. Its interesting to watch a person simply assume authority that exists only in the assumptions of others.

So eventually, over a period of months, in addition to the above mentioned problems which I discerned, what also came to light was that he had seen nothing special in me; rather he had just been asking every person he knew to join him, and I happened to be a person who knew him. In fact, he would demonstrate that he really knew nothing at all about what motivates me -- and it would be the cause of many conflicts between us.

When he asked me to quit my job at the time in order to join him, there was a decent amount of risk involved. And the more I questioned him about the basic operating principles of what he planned to do, the less satisfactorily he was able to explain himself.

At first I just assumed it was a language barrier issue, but eventually I had to conclude it was because he really didn't know what he was doing. At that point I made my participation in the adventure contingent on his ability to sell me on his business. I said "consider me your first customer", and set it aside as a bit of a foolish enterprise, bound for no good due to lack of competent foresight.

Later he was to also hand me a couple of bald lies, which at that time I lead me to decide there was no purpose in maintaining a friendship with a liar, and I stopped associating with him.

However, the conditions at the job I was employed at were increasingly getting worse. The field was interesting: R&D/Custom development in 3D rendering and haptic control. But the people running it were nice but utterly incompetent, a pattern I have come to believe is endemic in Japanese IT. The sheer ridiculousness of the organization at every level, and the way in which the incompetence was starting to drag on me professionally and personally, started to affect my job performance. And my personal relationship with my superiors deteriorated to the point where I was actively looking for a new job.

I knew they couldn't get rid of me because I was the only one who knew the system that I had written from scratch for them, which they hoped of one day selling, so I felt I could bide my time. However they caught me by surprise, by preemptively announcing to my contracting boss that they would not renew my contract in September, which I felt was a bit of a dick-move that left me further unimpressed. I resigned after two weeks notice. At the end of July.

J., having finally quit that company to start his own, but still having contacts there, found out about my situation, and smartly contacted me to let me know what had become of him, and ask if I would finally join him. It turns out a major venture capital/incubation firm in Tokyo had bought his company out and made him CTO of the new company. He still could not explain to me what he would be doing with this company, however what was different now from when he asked before, was that he was offering me a guaranteed salary at a healthy 40% raise. I was also told the company would be a global, English-speaking workplace, modeled after Google (free drinks, scheduling freedom, including 20% spare project time, etc), and so on. So after many interviews with financial companies, and one cell-phone software maker, I decided that it was a risk I could now accept given the potential for reward.

From the very beginning J. was fully of complements for me, when I first met him and when I first joined the company. He wanted me to be a leader within the new company -- starting with me taking the position of Head of the section of the company dedicated to the VW 3D client viewer. There was also some not-entirely-joking talk of me becoming CTO in his place (and I assume he would move up somewhere higher). Foolishly I bought into it because I thought again that it was my natural potential shining through. (Notice a pattern?)

To start with there just weren't nearly enough people to do everything that needed to be done. We didn't even have a secretary, so simple bookings were getting forgotten because the CTO or CEO were the only people who could do it, and they would just forget. Whats worse, is that J., having not the faintest idea how to start a company, was going about creating his dream company in what would seem like an arbitrary fashion.

In my way of thinking, you need to hire religiously for your first core group of people, because later on these are the people you have to trust implicitly to help you run your business. However it turns out that under J.'s recruiting method, the few people we had were essentially the just first people who said "yes" to him. Their skill-set was either flat-out sub-par or ill-fitting to what was required.

That assessment includes me: I have potential, but there is _no_ way I was or even am a seasoned project manager + leader + business man + C++ guru + any of the other hats I was asked, or felt required to wear. In effect I was thrown into the deep-end; which, if done with a capable mentor would have been survivable, or even healthy -- but considering I was thrown not for the purpose of teaching me the ropes, but rather so that J., who having no more ability than I -- and I would dare say less, didn't have to do that job himself!

At first I thrashed about, doing my best; but when it became clear I was sinking, I looked to J. He looked away or just criticized my work -- which was pretty galling considering that it was really his work in the first place. I blamed myself to start with, but increasingly I put the blame at the source, and we got into conflict. And by "conflict" I mean he would embarrass or insult me, and I would verbally berate him while he silently ignored what I was saying. A very functional relationship.

Given my rising stress levels and falling stock within the "leadership" of the company, the only choice was clear: explicitly decline all the implied responsibility that I had been given, and return to my core professional competency: programming.

I dove deeper into developing the 3D client viewer, however I couldn't really call myself a leader of anything since J. had neglected to realize before creating a group with a titular Head, that in fact, very little work was available on the viewer. The viewer is a dumb-client. And a professional dead-end within the company. Thanks.

Whats even worse is that J. neglected to notice that the code-base they had chosen for their server part was legally incompatible with the client viewer, and therefore anyone who worked on the viewer, as I had, was incapable of ever working on the server -- where 99% of the work needed to be done! Oops.

Unlike our in-house leadership, the leadership of the server part company was sensitive to my situation, and took steps to discuss a legal means of allowing me to work again: after a period of time it would be considered that the legal "taint" had washed off, and I could resume work. Thanks unrelated outside CEO!!

All the while, development was proceeding at a glacial pace, since the people in charge of it were literally just the first who agreed to join the company, and had no idea what they were doing. Mistakes that should be obvious to a first-year Computer Scientist or Software Engineer were a daily occurrence. And since all the decision making was done in Japanese only, arguing those mistakes was an exercise in masochism. The other English language employee and I spent all our time just guessing what was going on.

We desperately needed more people, but J. refused to do any recruiting outside his networking+"Hey you. Come join my company!" shtick. I decided it was necessary for the company's survival to go out myself, find a recruiter, and start doing interviews. Those interviews resulted in our current chief architect and two other lead programmers. No thanks ever came by voice nor mail.

So I reached a point where my dissatisfaction had grown to the point where if J. didn't go, there would be no future in the company, and therefore I had to go. I wrote a scathing email to the CEO of the parent company. This email was so unflattering that in a western company I could _guarantee_ you it would cost *someone* their job. To his credit, the parent CEO reacted somewhat swiftly, calling me to his office and assuring me he would make changes. I thought he meant deposing J. and setting me up in leadership (since there just wasn't anyone else to choose from), and I was giddly like a school-girl.

Well it turns out even in western-ish Japanese companies, things still proceed along the same essential lines as they do in regular Japanese companies: J. was mildly rebuked, a new project manager was brought in to a role that was hitherto desperately needed but totally unfilled -- but almost everything else remained as it was. How he dodged that bullet is still beyond me. Teflon briefs?

G., the new PM, was surprisingly like me. The way we thought and acted was strikingly similar. Even though he is Japanese, he went to school in Edmonton and even plays hockey, which makes him more Canadian than me.

I really feel sorry for him, because he essentially stepped into the same nightmare that I had hitherto been existing in. He came in with a clear mandate to clean things up, as I asked by the parent CEO -- but as he did so, he got push-back from J., and eventually J. won out. Now he is in the position of knowing what needs to be done, but being powerless to resist J.'s incessant interfering. How on earth do people so consistently prove themselves to be useless, yet retain so much political power?

G. came in an set about reorganizing the programmers into something that would resemble a minimally functional software development house, and spent a lot of time interviewing programmers, considering business needs, and creating a new organization. In that organization, I was to be the leader for essentially all the major software development, which was the core VW stuff, and some add-in tools. This plan was entirely and almost summarily rejected by J.

Well all the politicking has come to an end, and the dust is settling, and what it looks like is that J. remains CTO -- even though he is only a salesman and constantly interferes with technical matters he is not competent in, G. is our PM -- who's unenviable job is to endure the interference so us programmers don't have to, and me -- working as a lead programmer along with our architect doing core development (when my taint wears off). Its hardly the executive position that could have been in the cards, but I purposely chose to decline that direction because I knew the price I would have to pay to get it.

The position is where my competency is, so I no longer have to be a fish out of water with no help; and the work is still interesting with plenty to learn, so I haven't a real reason to quit yet. I expect the programming should continue be fun, rewarding and good for the resume, so I can say I enjoy my job again.

What I can't say is that I think my company will be successful in the mid to long term, as it is burdened with incompetent management that just won't go away. I am keeping an eye out for better opportunities, but I am currently thinking that none will be available that will provide a significant enough improvement on the current situation without leaving Japan; something M. is reluctant to do.

Still I can say that it was worth the risk to join the company, since even if the price has been rather steep, I have learned a lot about how run a company, and even more about how not to. That kind of education is worth the time spent. Its the wise man however, that knows when he has learned enough and is ready to move on.