kerneljack’s diary

some thoughts and comments on my day to day experiences

Archive for the 'coding' Category


Such an insightful essay …

28th August 2007

Paul Graham has impressed me time and again with his stunning insight. Whenever I read his writings, it’s as if he plucked his ideas out from my own head and then put pen to paper. His latest, Holding a Program in One’s Head, contains several gems that I personally have experienced several times at work.

The danger of a distraction depends not on how long it is, but on how much it scrambles your brain. A programmer can leave the office and go and get a sandwich without losing the code in his head. But the wrong kind of interruption can wipe your brain in 30 seconds.

This is spot-on, and I notice this a lot during my lunch break. Sometimes I can’t get a program or problem out of my head and occasionally I even come up with a solution not 10 minutes into my lunch break and then I can’t wait to get back and finish it. Other times however, especially if I have lunch with my colleagues the whole ‘problem space’ I’ve built up in my head simply vanishes. Due to the amount of work it usually takes (maybe a half-hour to an hour) to re-load my brain with the problem I was working on, a lot of post-lunch time is wasted and sometimes I can never recreate the problem fully again because I tend to be sharper in the mornings than in the lazy afternoons.

Since there’s a fixed cost each time you start working on a program, it’s more efficient to work in a few long sessions than many short ones.

I have often wanted to do this, but it’s almost impossible to do. There is always lunch, some other interruption, going home, eating dinner or something similar. On the weekends, however, I sometimes manage to stay up late and can work uninterrupted for quite a while.

Rewriting a program often yields a cleaner design.

True sometimes, but I agree with him that even the process of rewriting a program can lead to significant insights; even if the rewritten program is not a huge improvement.

Instead of summarizing the whole essay here, I highly recommend that all programmers and their managers go read it. Even non-IT staff, such mathematicians, whose work involves long-stretches of thinking, and constructing problem spaces in their heads will benefit from the advice in this essay.

I haven’t been paying attention to my RSS feeds recently and I forgot just how good some people are at writing and expressing their insights :-) Paul Graham and Joel On Software are two blogs (journals?) that I really enjoy reading.

Technorati Tags:

Posted in coding, programming, software, writing | No Comments »

Links for June 3, 2007

3rd June 2007

Fedora 7 is released!: I really liked the last Fedora release, but I believe it was slightly plagued by problems with some of it’s package management utilities. I have already installed this release and am quite impressed. Wireless now works with WPA out of the box and their new re-spinning feature is something I will try out someday.

XML Parser benchmarks: I have always had my own suspicions of which XML parser model would be faster (Sax or StaX), but I’m glad to see this benchmark done by the O’Reilly folks.

Fear and loathing at Cupertino: Jeremy Allison’s terrible experience while trying to prepare a talk for his Apple WWDC presentation. Jeremy works on Samba, along with Tridge, who they all call “the smartest man in Australia” :-) Jeremy works at Google now. Smart man.

Posted in apple, coding, computers, linux, mac, news, operating systems, osx, programming, software | No Comments »

Some web links for today

17th May 2007

I’m going to occasionally post links here that I find particularly insightful, interesting or geeky.

Three things that caught my interest today:

PowerTOP: Released by Intel, this utility builds on work done by kernel developers to make the Linux kernel power-efficient. PowerTOP gives you a snapshot of what apps are consuming the most power. Turn off these apps or modify their behavior, and you’ll notice an instant increase in the battery life.

The Linux SLAB Allocator: Traditional heap memory managers suffer from fragmentation, among other issues. The SLAB Allocator in Linux, inspired by a similar implementation for Solaris and various embedded systems, allocates memory as fixed sized objects and uses caches to reduce fragmentation. It also has options to enable hardware cache alignment which allows objects in different caches to share the same cache lines, thus improving performance.

Advanced Linux Programming: After many years of coding mostly Java, I’ve been meaning to brush up on my C, Assembly and general Unix programming skills. I found this excellent book freely available online and it seems to be getting a lot of praise from reviewers on Amazon so I downloaded it. It has a lot of topics that I’m very interested in, like IPC and threads, and it even has a few assembly oriented chapters. I will definitely be reading this one :-)

Posted in coding, linux, operating systems, programming, software | No Comments »

LinuxWorld 2006

26th October 2006

LinuxWorld started yesterday here in rainy London and I had a great time! It was the first time ever that I wasn’t a visitor, but was helping out at the Jokosher stand. I did several demos of the app to tons of people and we managed to distribute more than 130 Jokosher flyers to interested people.

I was quite surprised at the level of interest in the app, and we managed to solicit a great many feature requests from people, some of which will hopefully end up in Jokosher someday, making it rock even harder! I will definitely try to help out at more of these events in the future :-)
You can find the photos I took with my camera phone at my flickr photo page.

Posted in coding, computers, linux, podcasting, programming, python | No Comments »

Wierd Java error on my Mac

16th October 2006

I turned my computer on today to get some work done, started Eclipse and started coding. When I tried to use the command-line though, I got this strange error:


Error: no known VMs. (check for corrupt jvm.cfg file)

I couldn’t run 'java' or 'javac' from the command-line at all! I immediately went to /System/Library/Frameworks/JavaVM.framework and looked for 'jvm.cfg'. I have 3 VMs installed on this machine, 1.3.1, 1.4.2, and 1.5.0. 1.3.1 and 1.4.2 had a proper jvm.cfg file installed but for some reason 1.5.0’s jvm.cfg was a zero-length file. Googling didn’t turn up anything useful except this tip, which wouldn’t work because in my case all my permissions were correct. Fixing permissions using Disk Utility didn’t show any permissions problems at all.

In the end, all I did was copy the 1.4.2 version over to the 1.5.0 directory and all was well. The tip above mentions that Eclipse might have had something to do with this, and there might be some truth to that, as I did update my Eclipse to 3.2 recently, but I have been using it for a week without any problems …

Posted in apple, coding, computers, mac, operating systems, osx, programming, software | No Comments »

Doing quick tasks in Python

31st March 2006

A lot of the time at work I have to come up with quick solutions to various programming problems, and I mean *real* quick. There is usually very little time for finding the right library or open source toolkit that has already solved the problem or some part of it and then to figure out how to integrate that into our own workflow. It is usually much quicker to simply write a few scripts that get the job done.

In such situations I increasingly find myself solving these problems using the Python programming language. I’ve usually whipped up scripts using bash scripts and even Perl but I often find that I have to “re-learn” Perl again and again, or at least the part that I’m temporarily using to solve some problem. Python just seems (and looks) so much natural and cleaner. I’ve been fascinated by Ruby recently after my brush with Ruby on Rails and I am seriously trying to find a project to use it in all the time!

Anyway I wanted to give some examples of Pythons’ ability to solve quick problems. I’ve used it to make remote backups, check if certain services are running remotely and to fetch and delete mail off a remote server. For example, the following snippet of code can be used to send mail:

import smtplib

mailServer = smtplib.SMTP(serverURL)
mailServer.sendmail(sender, to, message)
mailServer.quit()

Really sweet and simple. I’m sure you can do this in only 1 line or even half a line in Perl (or even Python!) but this is really clear and concise. When I needed to write a script to send mail, I simply googled for it and dug this up in literally 20 secs! That’s one other reason I like writing scripts in Python: you can always google for snippets of code to do stuff.

Similarly, the following can be used to check if SSH is running and accepting connections on a remote server:

IDENT_STRING = "SSH"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, int(PORT)))
data = s.recv(1024)
s.close()

if data.find(IDENT_STRING) == -1:
sys.exit (1)
# if everything OK, exit normally
sys.exit(0)

If you put this in a script and run it, you can use the exit code (echo #?) to determine if SSH was running or not. Very useful if you’re writing a script to make backups to a remote server; you need to make sure that the service is up and running on the server and that it is accepting connections from the local machine.

I will try to see if Ruby makes any of these tasks even easier to do or perhaps easier to write and comprehend. I might even give Groovy a try since Java is my day job and Groovy is described as a scripting language for Java programmers.

Posted in coding, computers, programming, python, scripting | No Comments »

Ruby on Rails

7th March 2006

“Rails is the most well thought-out web development framework I’ve ever used. And that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” -James Duncan Davidson, Creator of Tomcat and Ant

I tried out the Ruby on Rails (RoR) framework this weekend and I’m quite impressed. I used Apple’s new tutorial for developers which explains how to install and quickly get up and running with a simple Accounts/Expenses webapp. I did encounter one minor glitch while following the install instructions because I was installing on my Debian Linux webserver, instead of an Apple machine. It seems the default ruby install no longer comes with the ruby-zlib library, but that was quickly fixed by following these instructions.

Rails applications all have a consistent directory structure, so you always start by running a command to generate the directory structure for you. This creates directories like app, config, doc, test, etc. The names are very familiar and easy to remember and they reinforce the purpose of the directory, i.e. the test directory is used to hold unit tests and functional tests for our application.

Automatic test creation makes testing an obvious and integral part of the development process, not an afterthought. It encourages you to think of a testing strategy upfront. This is perhaps the single most appreciated aspect of Rails development for me. You are supposed to test your code in other environments, but programmers often write code and if time permits, write tests. Rails tries to make it easy and painless (as much as possible) to test your code.

The next thing I learned about was the fact that Rails, like the Struts framework, tries to explicitly embed the notion of Models, Controllers, and Views within the development workflow. The concept of Actions, which are sent to Controllers in Rails is familiar to Struts. It is very easy to take a Rails URL (as shown in the example) and figure out how the server is going to parse and execute it.

Validation came next and I was suitably impressed. You simply need to add a few lines to the model, describing what each field should validate as, sort of like describing a type for a variable. Simply restart your server and voila, type rubbish in a field and Rails will highlight the field in red and ask you to re-enter it.

After all that, the tutorial shows you how to create a relationship between two models, much like in a relational database. The relation is that ‘one account can have many expenses’. This is accomplished in Rails by adding a ‘belongs to’ field in the Expense model (an expense belongs to an Account) and a ‘has many’ field to the Account model (an Account has many expenses). Simple as that.

Other things covered in the tutorial were:

  • adding business logic to total up the expenses for the account
  • using helpers to change the view slightly and show the total in red if we are over budget
  • writing simple unit tests and running them

Overall an excellent introductory tutorial which has left me wanting more. I will definitely go through the Rails website and find out more about RoR and what it can do.

I know this is a small toy example and I want to know how RoR handles in a real mission critical business app as those are the only kinds of apps developers write these days :-) RoR is easy to code for, but is it easy to maintain? After we get past the simplicity of the example app, how hard is it to write huge apps in it, and how long does it take a new developer to become familiar with and productive with a new codebase? These are all questions that I need answers to and I have the feeling that RoR won’t disappoint.

Posted in coding, computers, software | No Comments »

Microsoft at the PDC

23rd September 2005

A lot of cool stuff has been coming out of Microsoft recently at the PDC. You can watch the webcast of the event here.

Here is a short summary of some of the announcements, linking to a Channel 9 video of each (if possible):

Sparkle - separating visual components and design of an application from the data representation.

Start.com / Gadgets - nice, clean start/home page which can be extended using “gadgets”. and these gadgets can be re-used through inheritance. The windows vista sidebar will also sport gadgets which help people get to commonly used or needed data or tasks.

Microsoft Max - a kind of a cross between iPhoto and iMovie. allows you to create rich interactive photo albums with slick effects and to export these albums so that almost anybody can view them.

LINQ - a really cool idea of trying to remove the impedance mismatch between object and relational databases. From what I have seen, manipulating XML should be easier. It’s all done in C#. Creating and populating objects after using SQL joins should be easier.

WCF or Windows Communication Founcation (formerly Indigo) - Much more than just another web-services framework, it implements a lot of the plumbing that a lot of developers usually have to manage all the way from SOAP to P2P to some other method of app-to-app or pc-to-pc integration. So if you want 2 machines to talk to one another somehow you don’t have to worry too much about the plumbing going on behind all that communication. At least that’s the easiest way I see to summarize it

One the of absolutely coolest things that Jim Allchin showed off was the ability to increase the available memory of a PC running Vista by simply plugging a USB key in. It’s ingenious and I haven’t heard of anyone doing anything like it unless I am mistaken.

WPF/E or Windows Presentation Foundation / Everywhere. WPF was formerly Avalon, a new way to build rich interactive web / client apps using XML. They showed a very cool Netflix (video rental online) demo that they ran on 4 different machines and it scaled, etc flawlessly: a desktop machine, Media Center PC, Tablet PC and a PDA. Everything being vector based makes this a lot easier. Another cool North Face demo here

A lot more stuff than this has been announced of course but it is good to see at least a few cool things and possibly 1 innovation come out of Microsoft so far! They are pretty gung-ho on security nowadays and let’s hope that Vista finally gets security right (by right I mean a lot better than XP by default). Note that I’m usually *not* very pro-Microsoft, but I do believe in competition, and I hope Apple, Google, Linux et al give Microsoft all they’ve got because it makes things a lot more interesting for the consumer and gives us more choice. That is always a good thing.

Posted in coding, computers, news, operating systems | No Comments »

WebOS and the future of the Web

25th August 2005

[Jason Kottke](http://www.kottke.org) has an interesting write-up about how he envisions the future of the OS and the Web. The gist of his post can be summed up in the following points:

1. The OS can be made irrelevant by people writing for another OS, let’s call it WebOS.
2. People now only need to code for one platform (Java, anyone?)
3. A local web server on the client machine will mean that an app can continue on working even if it’s offline (think local app for Gmail, etc).
4. When users are back online, the app will synchronize itself with its online counterpart. Think adding Flickr pictures locally, and then uploading them.

The OS is still there whichever one it is, but it is no longer going to lock-in developers to only developing for that OS. One of the things Jason is saying is that people will no longer need to write for 3 OSes but for just one OS. This sounds just like “people will no longer have to write for 3 OSes but for just one platform: Java”.

Jason has already outlined some of the problems he envisions with this approach, such as web apps accessing local content on your hard drive. Java applets have solved this problem for a long time by using a sandbox model. The only problem is that these applets have to be downloaded and run locally for them to work. A WebOS app, however, will run both locally and remotely, it will live on your local hard drive and perhaps a sandbox model will help there as well. Are vulnerabilities detected in these local apps any more dangerous than vulnerabilities for remote apps? Perhaps there isn’t much different because at the end of the day, a security hole is the same thing whatever app it affects. However, I suppose a local security hole can do a *lot* more damage than a remote one.

Some other suggestions like: “Read newsfeeds from bloglines locally” sound no different to NetNewsWire, FeedDemon or SharpReader, etc. These are all locally accessible feed readers which, when online, update your subscriptions, etc, otherwise they work fine when offline.

I think, as [Paul Graham](http://paulgraham.com/) said, a WebOS will allow totally new kinds of applications to exist and we don’t know what they will look like at all. So this is definitely an interesting space to watch.
Some great examples of new ways of using the web are: [Backpack](http://www.backpackit.com), [Basecamp](http://www.basecamphq.com/), [Gmail](http://www.gmail.com) and [Google Maps](http://maps.google.com). Another up-and-coming app is [Hula](http://hula-project.org/Hula_Server) which has been open-sourced by Novell and is being actively worked on by many GNOME hackers. If you want to see a demo of how the future of web-calendaring might look like, take a look at [this](http://www.nat.org/2005/august/#Hula-Web-Interface) amazing demo on [Nat's](http://www.nat.org) blog.

In other news, I would love to get my hands on one of [these](http://joi.ito.com/archives/2005/08/25/wearing_firefox.html) [Firefox](http://www.getfirefox.com) T-shirts that [Joi](http://joi.ito.com) managed to pick up from the [Mozilla](http://www.mozilla.org) offices. I have ordered quite a few T-shirts from [ThinkGeek.com](http://www.thinkgeek.com) in the past, and I will order one of these if they stock them someday.

Posted in coding, computers, news, operating systems | No Comments »

J2EE/EJB Persistence Frameworks

2nd April 2005

I need to start investigating alternative persistence frameworks whenever I get some free time. I’ve tried looking at Hibernate in the past but just couldn’t find the time to implement a small project properly in it and understand the benefits.

A great write-up about another alternative, iBATIS SQL Maps which seem to have found the sweet spot between full O/R and hand-written JDBC can be found here.

As others have found out entity beans can be overkill in situations and that’s basically why I’m looking for some persistence alternatives. I’ve got to buy this book on J2EE Without EJB as well at some point, I’m sure it’s a great book as I have another one by the same author.

On the Swing/AWT front, SWT seems to be emerging as a good alternative for cases where you need a simpler interface which doesn’t need to have all the customization benefits that Swing gives you. Some evidence of people who like this approach is here and here is Bruce Eckel’s take on what Gosling has to say about SWT. Basically Gosling prefers the flexibility of Swing and the complete emulation and hence customizability it gives you while Eckel and some Smalltalkers think Swing takes it too far and suggest that using the interface objects underlying the platform and wrapping them to give a Java interface is a much better idea and yields better, more lightweight and faster code.

I have to agree on the faster and lightweight issues, even though the only SWT app I use is Eclipse. I know Eclipse is huge but it feels a lot snappier than a pure Swing implementation of it would have been. It has *never* crashed on me and much simpler Swing apps have crashed for me in the past. It is also proof that SWT is indeed suitable for huge projects.

Posted in coding, computers | No Comments »