Writing Software – Part 1

Ever since I started programming for Linux I’ve been thinking about writing about the differences between writing software for Windows and writing software for Linux. In the process of thinking about it many other programming-related thoughts started coming up and I couldn’t quite categorize them into sections (like Windows, Object Oriented Programming, etc…). This is why I decided to write this series, in which I will share some of my thoughts about and experiences with aspects of writing software.

Let me tell you about my first experience with programming, as a kid. When I was about 6 or 7 years old, my older brother got an Apple compatible computer. These kind of computers only existed for a little while, as Apple sued compatible Apple computers manufacturers and the rest of the story is well known (IBM compatibles outsell Apple’s computers to the point of near extinction).

The programming language available for me back then was the BASIC programming language and so my first program was:

10 PRINT "amit"
20 GOTO 10

Then, the uber-hacker version of this piece of code replaced the first line with:

10 ? "amit"

Looking back at this I wonder why it was decided that “?” can be used instead of “PRINT”. It doesn’t make too much sense from the write-clear-code point of view. I mean, they could have gone all the way, like Brainf*ck (or Linguine) did.

Ah, the good old, misunderstood and now forbidden GOTO. Where have you gone to? Today merely mentioning goto in a job interview is sure to get you another one of those we’re-sorry-but-you’re-over-qualified letters. GOTO is such a nasty word that, in the beginning of an introductory C course in the Technion, the teacher said that he will not teach us what goto is and a student who will use it in a homework assignment will automatically get a zero grade for that assignment. And by the way, if the interview is already going bad, make sure you say something like “when goto isn’t enough, I simply use longjmp()“.

In Java, goto is a reserved word, but it is not implemented. That’s the zombie land of language keywords. The reason for the deprecation of goto started with the famous article “Go To Statement Considered Harmful” by Edsger W. Dijkstra. The misuse of this statement was just too much to bear. The thing is that goto was still useful, for example in the case where you wanted to do some cleanup at the end of the function, or maybe some common error handling code. Many uses of goto use can be found in libraries (A.K.A the place where you can do stuff that is generally not allowed as long as it works) which is an indication that it is still useful. Actually, there’s a thumb rule I learned once that prevents the spaghetti code which usually results from using goto: always “go to” in one direction. It’s a simple and effective rule, which means that if you use goto in a function, always make sure that the goto target is, for example, below the current line.

Alas, goto is already doomed. Modern languages offer “structured” ways for doing cleanup. In Java and in C# (I will use C# as the representative for .NET languages) you can use the try-finally combo, which is part of exception-handling. And if we’re already on the subject of exception handling, let me tell you about my “real world” experience with C++ and exceptions.

Exceptions in “real world” C++ are rarely used. Most of the reasons I heard were the usual FUD – exceptions are unexpectable, exception handling is slow, exceptions are too complicated. This is true for three out of three C++-using companies I worked for. Ultimately this means that the code has the call-check-trace-return pattern, which is something like this:

STATUS FunctionA()
{
  STATUS ret = STATUS_ERROR;
  ret = FunctionB();
  if (STATUS_OK != ret)
  {
    TRACE_ERROR(ret, "I called FunctionB and it failed. Boo hoo");
    return ret;
  }
  
  ... // repeated for evey call inside FunctionA
  
  return STATUS_OK;
}

Those of you who use exceptions can see the irony. Naturally, it means that constructors are not allowed to do any work (so there’s always a Construct() function for a class, immediately following the constructor), which apparently is one of the five habits of “highly profitable developers”. In an environement that embraces that kind of attitude there’s no room even for mentioning RAII, pimpl, Loki or even boost. Sometimes I wonder if the C++ I read in books will ever come useful to me at a workplace.

Mentioning Loki and boost brings me to the subject of templates, which is very similar to exceptions, but I’ll talk about that some other time. Oh, and I have to continue the story about how I started programming.

Ace plays with the water tap

Some of you already know that I have a 5 months old cat. Now it’s time to show her to you, while also testing what it’s like to put a video in the blog. So here it is: Ace plays with the water tap.

Description: After noticing Ace’s interest in the sink, I put her up on it and let the water run just a little to see how she would react.

Guruza – yet another UQAN implementation

Following Illumio, another implementation of my own UQAN idea has surfaced lately. This time – Guruza – where you ask a question and state how much you’re willing to pay for a good answer. Then you enter a chat and when you’re satisfied with the answer, you pay the “expert” who answered it. Seems to work with a kind of honour system… I hope it’ll work.

Illumio – they implemented my UQAN idea

Here’s another old idea of mine that gets implemented by someone else: Illumio (NY Times story) is the implementation of my UQAN idea for distributing questions over a network of users to get answers from apparent experts. Here’s Illumio’s website although there’s not much to do there.

I have mixed feelings about this. Although I never thought I’d actually get to implementing UQAN, and I want to see how Illumio turns out, I still feel like I should have done it myself. Oh well.

New Job

Yesterday, after an extremely enjoyable and relaxing 2-week vacation with my girlfriend Katz, I started my new job at Diligent. The place is nice, people are great and I’m expecting to enjoy my work here. Unfortunately this means I have less time to update my blog, although I will make efforts to put stuff up here whenever I can.

מזל טוב, נסיכה

היי חמודה שלי,

סתם זרקתי פה מזל טוב מהיר, שתהיה לך הפתעה נעימה אם במקרה תיכנסי היום לבלוג.

אני.

חמשת הקוראים של הבלוג יכולים להשאיר את הברכות בתגובות. לא לשכוח להגיב רק באנגלית. תודה.

New workout schedule starting next week

Starting next week I’ll move to a 4 days/week workout schedule after following a 6 days/week schedule for almost a year and a half. The change comes because of quite a few reasons, but basically my workouts include 2 Pilates and 2 Yoga lessons which are nice to have but I don’t feel they’re such a necessity. I’m going to focus on aerobic and muscle training.

Writing this post down and noticing all the days in which I wrote “Rest” (see below) kind of scares me. I know that I’m still going to be just as fit as I am today, as I haven’t given up aerobics nor muscle workouts, but it’s still a big change.

Here’s the complete schedule:
Sunday: HIIT on an elliptical + 20 minute run at 85% MHR; Muscles: shoulders, biceps, upper-back.
Monday: HIIT on an elliptical + 20 minute run at 85% MHR; Muscles: chest, legs, triceps.
Tuesday: Rest.
Wednesday: HIIT on an elliptical + 20 minute run at 85% MHR; Muscles: shoulders, biceps, upper-back.
Thursday: HIIT on an elliptical + 20 minutes run at 85% MHR; Muscles: chest, legs, triceps.
Friday: Rest.
Saturday: Rest.

My HIIT workout is:
3 minutes warm-up
1 minute at 60% effort
1 minute at 70% effort
1 minute at 80% effort
1 minute at 90% effort
1 minute at 60% effort
1 minute at 70% effort
1 minute at 80% effort
1 minute at 90% effort
1 minute at 60% effort
1 minute at 70% effort
1 minute at 80% effort
1 minute at 90% effort
1 minute at 60% effort
1 minute at 70% effort
1 minute at 80% effort
1 minute at 90% effort
1 minute at 60% effort
1 minute at 70% effort
1 minute at 80% effort
1 minute at 100% effort
2 minutes cooldown
(total of 25 minutes)

I quit my job. Long live my new job

Today I quit my job as a software engineer for Motorola and signed a contract for a software engineer position at Diligent. From the website:

Diligent is a world-class innovator in enterprise-class disk-based storage solutions. Focused on meeting the challenges of storing, protecting and managing the ever-explosive growth of backup data and the continued inefficiencies inherent in traditional methods, Diligent has pioneered a solution that will forever change the economics of implementing disk based backup and restore in data centers.

In other words: Diligent do storage :)

I’m very excited about working for Diligent. All the people I met there were extremely nice and the job is supposed to be both challenging and interesting. I’m moving from Windows programming, which I’ve been doing for the past few years, to Linux/Unix real-time programming so that itself is a challenge.

I will start working in a month and a half. Wish me luck.

What is this blog about, anyway?

Lately, the issue of the subject of this blog came up a lot. I guess the blog isn’t so interesting to everyone as it used to be when it came out. So I would like to answer that question as best as I can:

I set up this weblog so I could write both about myself and about things that interest me. It’s a platform for me to share thoughts, ideas and just about anything that manages to catch my eye. I realize that having a blog without a specific subject goes against the “have a subject for your blog” rule for having a popular blog, but I really don’t care if this blog is popular or not. I do wish people would read it from time to time and I’m pretty sure it’ll find its niche.

Additionally, there is a big limitation to having a weblog with your name on it – you can’t post stuff about other people, as it completely exposes them. I realized this the moment I started blogging. It’s very limiting, as most of the good stories include interactions with other people. Sometimes I think about opening an additional, anonymous blog but that won’t be happening anytime soon.

A friend asked me today: “so where is Amit in all the links and articles?” The answer is that I’m the sum of all that’s been posted. It’s hard for me to explain what this means, but if I post something categorized as “Funny” then it means that I laughed when I saw it. There’s a little bit of me there, as well.

Hit-a-Hint, “KeyboardAccess For Firefox”, by Pekka Sillanpaa

It’s a sad day for me – I found out that someone (whose name is Pekka Sillanpaa) implemented something that I wanted to do myself. Pekka implemented what I would call “KeyboardAccess For Firefox”. The funny thing is that he thought of the idea himself the same way I did. He didn’t know about my own Internet Explorer plugin, KeyboardAccess For IE.

His Firefox extension is called Hit-a-Hint and I must admit that it works considerably better than my plugin for Internet Explorer. I wrote him an email and he kindly offered me to contribute to his project.