Thursday, 31 July 2008

Qt/Lisp: more progress

I've replaced the unsightly (make-instance 'qstring :ch "Foo") with a reader macro: #q"Foo". Ideally we'd use cl:string and qstring interchangeably but right now its too much of a PITA to make that work.

I've also made it possible to use closures for slots (see example below.) Frickin sweet.

Anyway, I started getting into the Dock Widgets example but lost interest after seeing all the code. Here is the code so far. Not very concise yet but will get there. Once I get into make-it-less-ugly mode, I will probably copy what Paul did with EQL as he calls it now.

Also the :foreign-pointer thingy will go away when I get around to adding cffi type translations.

Monday, 28 July 2008

svn-bisect

Well it was only a matter of time... svn-bisect.py lives!

Greg Noel of SCons fame (is that really fame?) has committed a modification of a script I created whose purpose was to binary search the introduction of a bug in a SVN repository.

Example usage of the script is here.

Enjoy.

Why complaining works..

My email to an online store:


Hey guys, I ordered product XYZ from your site yesterday. According to your shipping estimates, it should be here in 2-4 days. However, I see that it is not shipped yet. I have had one bad experience with your service before and would not like it to repeat. Please see that this is so.

Literally 5 minutes later:

Your order has been shipped.

Now if I can only get them to do it before I complain.

Tuesday, 22 July 2008

Simple CFFI - Qt4 integration attempt

Update: Paul has sent me his code. He calls it "EQL" for ECL and Qt. Or something like that anyway! I have put it up here.

The author of the Simple CFFI - Qt4 integration attempt has contacted me to let me know that a modification of the above linked software is in commercial use. I have prodded him to release his modified version. He says he'll do it Real Soon Now (TM).

I don't know if he is reading this blog but maybe a little pressure will help. Just kidding!

What I like most about his method is the use of the introspection capabilities of Qt. Compared to the duct tape and glue I used, his is a lot more elegant. Currently, you cannot extend Qt in Lisp (via inheritance) but all the other goodies are still there. Indeed he tells me that for his application, he extended Qt from within C++ and used these extensions from his Lisp.

I look forward to the update and to using the library.

Friday, 18 July 2008

Qt/Lisp: looking for feedback

Update: You can download the generated code from here.

The tubes were down this morning, so I managed to get up to tutorial 6 in my Qt/Lisp API. It covers about 95% of the API by design so most of the non-extension tutorials/examples should work.



I would like to hear your complaints, suggestions, feedback if you have any.

Note that this API is a first draft and I thought it better to have something out there than wait until everything is perfect.

To start with, my current complaints:

  • (in-package :qt) -> Nothing is actually exported from the package yet :-)

  • (make-instance 'qstring ...) -> A really verbose way to pass a string! Should convert lisp strings to qstrings automagically.

  • Naming: instead of qpush-button, q:push-button

  • No way to extend Qt from within Lisp yet (tutorial 7 won't work)

  • No way to attach arbitrary functions as slots

  • Not Lispy enough.



I expect to address most of these at some point though the "Not Lispy enough" complaint is a bit subjective.

Wednesday, 9 July 2008

Sohail, it doesn't work anymore

Everyone has a story about when they were younger. For example, Joel Spolsky talks about his time in an army bakery (or something like that.) Sometimes, the stories are quite pathetic like Al Bundy and his high school football team. I am neither as exciting as Spolsky, nor as pathetic as Al Bundy (though I'm sure the latter is up for debate.)

This story is about something that happened to me when I was younger that made me who I am today.

I started programming quite late by geek standards. I was either 11 or 14 depending on whether you count batch files as programming. But I loved it. And when I got tired of programming, I'd program some more in FastTracker 2!

For a while, I had a job as a pharmacist's assistant. This particular pharmacy had the option for delivery of prescriptions and other general items. The deliveries were done in the evening and were done by two very friendly guys named Krish and Sam.

Part of my job here (besides preparing the methadone!) was to add up all the deliveries that these two guys did within some period of time and summarize for the boss. It used to take me hours in a busy month as it required use of some large Excel spreadsheet. So I resolved to solve that problem with my programming chops. I got the owner to agree to pay me hourly (wow, $10/hour!) and he told me not to spend "too much time" on it. So I guesstimated 40 hours until I would be able to deploy the application. He was fine with that.

I was mostly right but near the end of it, while I was testing with the users (me), it turned out some other data collection was necessary. After discussing with the boss, he said it was important but not to spend "too much time" on it. By then, I had come to realize that "too much time" means "don't charge me more than I want to pay you." So I added it quickly, and it was done.

I deployed the application in December of that year to rave reviews from the boss. I'm not sure if the other employees cared that much but I know that it made my life easier and the count of deliveries more accurate so I was happy.

Due to other responsibilities (I think it was school?), I had to reduce my hours at the pharmacy. That was around June. I had trained the other people to use the application and it was becoming quite necessary for them to use if they wanted to retain their sanity.

Fast-forward to November. I get a call. "Sohail, it's not working anymore." "Crap", I thought. What did I miss? I went into the pharmacy and fudged around in the flat files to see what could be wrong.

It turns out that one of the data files was being named incorrectly. Can you guess which data file? Yes, it was the one I had added last just before I completed the project.

I think I spent about 10 unpaid hours debugging the problem at home while studying for exams/finishing projects. It came down to this (in C++, I don't really recall the language):


// data1.cpp
const char * months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};


// data2.cpp
const char * months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov ","Dec"};

Can you see the problem? In the second instance, I added a space after "Nov". So while data2.cpp was saving "Data2Nov Year.file", data1.cpp was saving "Data1NovYear.file" and the code that summarized the data was trying to open "Data<N>NovYear.file".

Oops.

I fixed this bug and apologized to the owner. I explained why it happened and that I fixed the code duplication. The boss said that he thought I should get an award for this software (a big ego boost!) and wondered if he could sell it to other people. Apparently he had been raving about it to his other pharmacist buddies. I don't remember what I said to him about that (something about me not having enough time to modify it to be generic enough as Sam and Krish were hardcoded!) but I really learned something that month.

Fortunately, in this case, things turned out alright. So I swore to avoid similar problems in the future in case future clients were not as forgiving. How did I do this? Quite simply:

  • Thorough testing

  • No copy-and-waste


My business cards have always had some variation of this. The current incarnation has something like "Do it once, do it right." Corny, but conveys my philosophy quite well. I will work very hard to reduce code duplication now. I try my best to write a test for each function/class that I write. Yes it is hard work. Yes it takes time. Quite frankly, software is hard. But in the end, I get very few calls saying "Sohail, it doesn't work anymore."

And no, you are not allowed to put a comment on this post saying "Sohail, it doesn't work anymore" :-)