Feb 14

I Miss Emacs

I miss Emacs1. Emacs was awe­some and fun and every­thing that I ever need­ed in an editor–at least that is what I thought.

For those who don’t know, Emacs is an edi­tor that is writ­ten in a form of Lisp called eLisp (it’s close enough to just con­sid­er it Lisp) which has been enhanced to include text manip­u­la­tion prim­i­tives. There is a Lisp engine that is writ­ten in C, but except for the text prim­i­tives every­thing else is writ­ten in Lisp. And I mean every­thing. This makes it extreme­ly easy to con­fig­ure and mod­i­fy to make it real­ly yours.

I spent years using Emacs and devel­oped a large body of cus­tomiza­tion and pack­ages to sup­port my work. I once worked for a guy who lit­er­al­ly did not need code to be for­mat­ted to read it so he would cram as much as he could onto the screen with­out any con­sid­er­a­tion for mod­ern ideas of read­abil­i­ty. I on the oth­er hand could not read this jum­ble of char­ac­ters. It was so bad that the code for­mat­ters that exist­ed could not han­dle his code, so I wrote a com­plex Emacs macro that would parse the file (this was C code) and refor­mat it to some­thing that the for­mat­ters could han­dle. To make him hap­py I also wrote the con­verse which would mash the code back into its com­pressed form (hey he was the boss).

There is no way I could do this with most of today’s edi­tors. On the oth­er hand, Emacs has not been able to keep up with the progress of most IDEs. Large scale refac­tor­ing is not real­ly pos­si­ble with Emacs. There are pack­ages to do some sim­ple refac­tor­ing but they are lim­it­ed. So gave up some years ago and moved to and IDE (at the time it was Eclipse but I’ve moved on to IntelliJ IDEA and friends). With all of the code com­pre­hen­sion tools built in to it I just can­not be as pro­duc­tive while using Emacs (or any straight edi­tor) any more.

But I still miss being able to look at a prob­lem and say “I can write a macro for that.” There is some­thing mag­i­cal about know­ing that you can bend the tool to your will rather that hav­ing to bend to its design. And you haven’t lived until you work with an edi­tor that some­one said “you know, this is Turing com­plete so I think I’ll add a new mode that sup­ports Vi inside of Emacs2.” One edi­tor inside of anoth­er just using the macro language–that is pow­er.

I still fire it up some­time when I need to work on a few files from the com­mand line and Vi/​Vim is not enough and I feel a bit of nos­tal­gia when my fin­gers auto­mat­i­cal­ly fall into famil­iar pat­ters: Ctrl‑S (incre­men­tal search), C‑X,C‑S (file save), Ctrl‑K (kill), Ctrl‑Y (yank), and all of the oth­er eso­teric key­strokes. Even after all of these years they are ingrained in my mus­cle memory–unfortunately, the mod­i­fi­er keys have moved around which slows me down. Why do we need a gigan­tic Caps lock but­ton in one of the prime loca­tions on the key­board? Seriously, do peo­ple real­ly need the Caps lock key?

I love IntelliJ and will have a hard time chang­ing if some­thing bet­ter man­ages to be cre­at­ed but it’s just not as fun as Emacs. Need to do a sequence of steps mul­ti­ple times? Just record it as a tem­po­rary macro and exe­cute it as often as nec­es­sary. Need to keep it? Just save it. Need to make it more robust, con­vert it to a code macro and edit it. And do this mul­ti­ple times a day because it is so easy.

I will always have a spe­cial place in my heart for Emacs.

Jan 28

Java Needs Properties

OK, this is get­ting ridicu­lous. It’s been, what, 25 years since Java start­ed and we still haven’t fixed one of the sin­gle biggest pain-​points for the language—properties. I mean, just look at this mess:

The amount of boil­er­plate is huge and that’s with­out con­sid­er­ing oth­er boil­er­plate meth­ods like equals():

Ugh, I hate typ­ing all of that. If the object is a bean/​POJO then we can use gen­er­a­tors to help write some of the code at the expense of some weird code: strange inher­i­tance, abstract objects, anno­ta­tions, etc.

Now with prop­er­ties and some com­pil­er mag­ic we could have the same behav­ior that looks more like this:

And this would inter­nal­ly gen­er­ate the sec­ond exam­ple above. If you don’t like adding new key­words we could do it almost as ele­gant­ly with anno­ta­tions:

This could eas­i­ly be extend­ed to sup­port read-​only prop­er­ties as well as over­rid­ing the getter/​setter. Overriding the set­ter is need­ed to val­i­date the val­ue.

This would inter­nal­ly gen­er­ate the equiv­a­lent of this:

Note the assert in the con­struc­tor in the gen­er­at­ed ver­sion. This was added by the @NotNull anno­ta­tion. If the code gen­er­a­tor can guar­an­tee that name is set before the end of the con­struc­tor the it can elide the assert().

Anyway, there is a lot more that can be done. A prop­er­ty could be marked as part of the objec­t’s order­ing and then it would be added to a gen­er­at­ed compareTo() method. The basic idea is to remove the boil­er­plate and to force con­sis­ten­cy in code between pro­gram­mers.

Jul 08

PHP Reflections

In my (rel­a­tive­ly) new job we use PHP for the back­end. This is the first time that I’ve used PHP for doing any real work and now that I’m using it for real I have found it to be an inter­est­ing lan­guage. I am still on the fence about whether I actu­al­ly like it or not but is does have some nice fea­tures. Given that I’ve only been using is seri­ous­ly for 3 months now I can’t claim to be an expert and I know that I’m just scratch­ing the sur­face at this point.

One of its best fea­tures is that dynam­i­cal­ly com­piled which real­ly short­ens the edit-​compile-​test cycle. I like being able to make small changes and see the (near­ly) imme­di­ate result with­out hav­ing to go through a build phase. It’s also nice that there is a large library of func­tion­al­i­ty avail­able as well as a large com­mu­ni­ty of third-​party solu­tions. I’m just now start­ing to look at some of the frame­works built on PHP and many look real­ly good. I do real­ly like the asso­cia­tive arrays, espe­cial­ly the abil­i­ty to eas­i­ly nest them, how­ev­er, I don’t like the way that PHP merges them with indexed arrays. I know that oth­er lan­guages do this as well, but I don’t like it.

I think my biggest prob­lem with PHP is just how easy it is to com­bine the out­put (view) with the log­ic (con­troller) and even mix in some data (mod­el) into one file. This is the same prob­lem that JSP had. This basi­cal­ly neces­si­tates a frame­work of some kind in any large project. The syn­tax is also prob­lem­at­ic for me. I find it messy and full of unnec­es­sary items like dol­lar signs ($) which I believe come from the Perl past. Perl had a rea­son for using a dol­lar sign for vari­ables: it indi­cates a “sim­ple” val­ue that is not an array (@) nor a hash (%). Given that PHP merges all of these into one pre­fix ($) it would be nice to get rid of it entire­ly.

Basically I think that PHP does a bet­ter job of fill­ing the “dynam­ic, script­ing lan­guage for gen­er­at­ing web pages” than JSP does, but I feel that it could be cleaned up a bit and a lit­tle more struc­ture added to make it eas­i­er to work with.

Jun 14

Time Waits for no One

Joda Time is a library that improves the func­tion­al­i­ty and usabil­i­ty of dates and times in the Java envi­ron­ment. The built-​in Java class­es are hard to use, miss­ing com­mon func­tion­al­i­ty, and do the wrong thing in many cas­es. Thus was born Joda Time. It has been so suc­cess­ful that it was made the basis of JSR-​310, a pro­pos­al for adding the Joda Time func­tion­al­i­ty to the base Java libraries. This post is not about Joda Time. At least not direct­ly.

In November of last year (2009) I joined with Jon Skeet and oth­ers in start­ing the Noda Time Open Source project. The goal of this project is to port the Joda Time library from Java to .NET. The built-​in class­es in the .NET run­time are woe­ful­ly incom­plete, inad­e­quate, and inel­e­gant. The orig­i­nal plan was to do a straight port with as lit­tle changed as pos­si­ble to make it work with .NET but as time went on (about 2 days) we real­ized that the Joda Time way was just too Java-​centric and would look too out-​of-​place in a .NET sys­tem. So after much wail­ing and gnash­ing of teeth we decid­ed to diverge.

As my first set of posts in this blog’s reboot I thought it would be fun to cov­er this process and along the way maybe talk a lit­tle about the issues that came up—both in inter­fac­ing with .NET and with time itself.

May 14

The Story Begins

In which our intre­pid (or is that tepid?) Hero finds him­self on the shores of the Sharp Sea look­ing through the Windows to the Presentation of the Foundation of all things.

Last time I men­tioned that I was work­ing on a project to sim­pli­fy con­fig­ur­ing our main prod­uct and that I decid­ed to make it a reg­u­lar Windows appli­ca­tion instead of a (shud­der) VBA appli­ca­tion.

I like learn­ing com­put­er lan­guages and so I thought that this would be a good time to learn C#. I had dab­bled with it over the years and had writ­ten some small pro­grams in it, but noth­ing serious–nothing that required learn­ing the details or the dark recess­es of a lan­guage. And with 3.0 out I fig­ured I could learn about all the cool new fea­tures. That and I just can’t bring myself to use Visual Basic. It is a pow­er­ful lan­guage with some neat fea­tures but it just brings up too many old, painful mem­o­ries.1

So I fired up Visual Studio and told it to cre­ate a new Windows Forms Application.

Hey, what’s that WPF Application tem­plate?

Oh, that is Microsoft’s lat­est attempt to make a good UI library. It’s just anoth­er rework­ing of their old stuff. Don’t wor­ry about it.

Shouldn’t we at least look at it and see if it’s any bet­ter? I mean learn­ing some­thing new is fun and it’s one of the rea­sons were doing this on the side.

No, we know some­thing about how Forms work and we don’t have the time to learn a com­plete­ly new sys­tem if we want to show some­thing soon to con­vince peo­ple not go the VBA route. Don’t wor­ry it will all be fine.

OK, if you say so…

Talking to my inner self can be annoy­ing. Where was I? Oh yeah, the appli­ca­tion solu­tion was cre­at­ed. Add a few sup­port projects, steal code from oth­er projects, rename a few things, and com­pile. Yay it runs!

Time pass­es…

Microsoft annoys me.

You talk­ing to me?

Yeah. They’re real­ly big, have very tal­ent­ed peo­ple and they still cre­ate com­plex, hard-​to-​use stuff like this. It’s a real pain to get things on the win­dow, look­ing nice, and be func­tion­al. You have to write so much code. Ugh.

You know, there is the thing I heard about once…I’m think it was called WPF. Someone once said we should look at it. I can’t remem­ber who…

OK, OK. I get the mes­sage. Just to make you hap­py I’ll take a quick look, you’ll see that it’s just the same old stuff repack­age like always and we can get back to mak­ing this work.

Thanks, this will be fun…

Fire up a new solu­tion, this time a WPF Application. Looks pret­ty much the same, an emp­ty win­dow. OK, the tool on the left look pret­ty much the same, maybe one or two new things. Nothing sur­pris­ing there. I guess it time to read up on this. I’ll give it an hour or so.

Time pass­es…

OMG, this is even more com­pli­cat­ed than Forms! Look at all the options and set­tings!

Time pass­es…

Wait, bind­ing? Like Adobe Flex? We liked bind­ing in Flex.

Time pass­es…

Item tem­plates? Data tem­plates? What?

Time pass­es…

I’ve got it! I get it! Wait! Microsoft made this? This is…good. This is…right!

I told you we should look at it.

But it was just anoth­er “Microsoft threw too many peo­ple at the prob­lem” thing. How could I have known?

You should lis­ten to me more you know. This half the brain has good ideas too you know.

The Recap

For those try­ing to keep track, I, like many oth­ers, do not have the most favor­able opin­ion of Microsoft prod­ucts. I do have a lot of respect for the peo­ple who work for Microsoft. Some of the bright­est stars of my field (soft­ware devel­op­ment) work for them. But in my opin­ion, the com­pa­ny some­how man­ages to infect them and caus­es them to pro­duce things that are, shall we say, not so good. I think that it may have some­thing to do with bureau­cra­cy and iner­tia, but what­ev­er the rea­son, I am not a fan of most of the prod­ucts that have come out of Microsoft for the last few years (many years in fact).

But WPF changes all of that. Now mind you, it is not per­fect. There are some things I would change but over­all this is how a win­dow sys­tem should be. The sep­a­ra­tion of con­cerns, the sim­plic­i­ty of exe­cu­tion (once you get over the “how does it work” hump), and the abil­i­ty to change just about every­thing is fan­tas­tic. As time goes on and I learn about new fea­tures in the sys­tem I go “wow that’s great. I wish I had known about that before.”

And the great thing about this is that it works as a Windows appli­ca­tion and a brows­er appli­ca­tion. And with Silverlight using the same basic tech­nol­o­gy I see great pos­si­bil­i­ties ahead.


  1. The new Visual Studio 2010 is going to include F# as a stan­dard lan­guage. Finally a func­tion­al lan­guage may become main­stream. I miss Scheme.