Archive for the 'Programming' Category
Static vs. Dynamic Typing
Friday, January 25th, 2008
Every good programmer probably has to write about their opinion on this subject once in their lifetime, so here’s my take
As part of my consulting gig I work on “Enterprise Java” code. I just had to write this line after receiving two separate exceptions on the matter (types obfuscated to protect the guilty (and they are oh so guilty… I won’t get into that)):
String somenumber = (String) ((TypeAttribute) TypeCache.getTypeFromCache("Thingie") .getAttribute("someNumber")).getValue((Thingie) object);
You’re a freaking computer! Figure it out for me!
Also, xkcd, as always, says it the best.
It’s revealing to be a Java programmer every 2 weeks, and a Ruby and Flex developer the next 2 weeks, with PHP and JavaScript by night. I understand everything about why static typing is good and proper, but today, when computers (and compilers especially) are powerful and intelligent, I think the computer should do what a computer is great for, namely figuring out extremely complex yet orderly relationships between types of things, leaving the programmer to focus on much more important stuff.
When I’m coding in Java, it takes me 50 lines of rudimentary logic and typecasting muck in a new inline comparator class to do something as simple as sorting custom objects.
In Ruby it’s a one-liner. I don’t care how much less efficient that is for the computer (and it’s not), that is worth its weight in gold in programmer time and code elegance.
I enjoy dynamically typed languages, and any good programmer knows that it’s programmers having fun that makes good software, not programmers spending 50% of their time dealing with code that gets in their way. What kills me most is that computers are really good at automatically doing the stuff that’s not fun—that is in fact what they’re designed to do—and there are people who have fun making that stuff fast, so why don’t we just let them?
Javascript selectedIndex NS_ERROR_FAILURE in Firefox
Tuesday, April 24th, 2007
I was amazed that the top hit in Google for this was the Mozilla source code (which was helpful, but not very user-friendly) so I’m writing up a bit on this confusing error message.
This is a Mozilla (Firefox, Seamonkey, Ephiphany, etc.) exception that gets thrown when you try to set the selectedIndex of a select element out of bounds of its options. The error message (from Firebug) looks like:
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLSelectElement.selectedIndex]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://www.example.com/test.html :: testSelect :: line 8" data: no]
This is not your standard JavaScript error. It’s not informative, useful, user-friendly, and barely gives you a line number to work with. Read the rest of this entry »
My Aversion to Java Explained
Tuesday, March 27th, 2007
I work on Java software for my day job, and now for my night job as well (don’t worry, that’s not Zenphoto). I learned Java in college, I’ve used it for years, I know it well, but I’ve never really liked it as a general rule; as in, I’ve never ever thought “Wow, Java would be really great for this project!” with any enthusiasm. Java has been the choice because of other reasons in every case—on one project, my team chose it because it was the one common language we all knew, so there was no learning curve. At work, I’m stuck with it because that’s what the “enterprise” software I customize is written in. Now in a new project I’m getting into, we’ve decided on it for scalability and a new web application framework called JSF, and it’s actually looking pretty good so far. But as I sit here learning JSF and the component framework I’m going to be working in, I came to a clear realization:
Nothing in Java is simple.
That’s the bad taste in my mouth. That’s the main thing that makes me dread opening NetBeans or Eclipse. The reason is stupid: I am a designer at heart, not a programmer. Programming is more visual for me; I try to see organization and elegance in the end user interface as well as in the code behind it, and Java pretty much obscures that notion of beautiful code entirely. It’s just not simple enough to be called that.
So what programming languages do I like? Well I’m a PHP programmer by preference, because very little gets in the way between me and the HTML. It’s inherently simple, because it gives you pretty much nothing to start with. Next on the list is JavaScript, which I like a lot, for many reasons. And after that, ironically, I guess it’s Java.
So I have a love-hate relationship with Java. On the one hand, it helps you do stuff you couldn’t ever do in a simpler language, it’s automatically cross-platform, it’s generally fast these days, and it’s easy to work with in the right IDE. On the other hand, it’s complex. So what? I can live with complex. It just annoys the heck out of me sometimes that I have to jump through so many hoops just to build an interface component. Sigh… in the long run, though, it’ll work better for it.
But one thing you can be darned sure of: Zenphoto will never be a Java application.
Zenphoto dynamic theme concept
Friday, March 16th, 2007
I started working on a Zenphoto theme to sort of mimic the performance of Google’s Picasa Web Albums service (which is very nice, and was recently upgraded to 1 GB of free storage, see my public albums there for a good example).
Picasa-Web made huge strides in the usability of online photo viewing, in my opinion. The main advantage was the quick loading of previous and next images when browsing an album in the one-image view (where most browsing takes place, or at least, where the user cares most about speed). It was all done in JavaScript and AJAX, of course, and images were even loaded in low-res (pixelated) first so you at least saw something if you were too fast for your connection.
The other real speed improvement came unexpected—simply using the ‘onMouseDown’ event instead of ‘onClick’ to trigger the image switch. It’s incredible how much faster the first feels. It’s like the transition happens before you even thought about it, as if it’s somehow reading your mind. I guess that just shows how ingrained it is that actions happen when we lift the mouse button. That probably makes sense for most actions, but for browsing a photo gallery I can see why instant action is preferred—it feels fast, very fast.
So without further ado, I give you an image page with dynamic image loading and navigation. Please, browse, take a look, and tell me what you think.
Things that still aren’t complete include:
- Comments, loading and submitting for each image.
- Navigating to a specific image (currently always goes to the first)
- Browser history/back/forward preservation
- Full-sized or larger-sized image view, with Light/thick/slimbox etc. perhaps
- Better theme design—should be a good one.
so don’t complain about them just yet.
It’s a proof-of-concept, to prove that it’s possible (and quite easy) to make dynamic and fun themes with Zenphoto. All the framework for processing images, iterating over objects, and page handling is done by Zenphoto, leaving the theme developer to focus on the javascript design, which is the fun part of course
Zenphoto also makes it easy to “fall back” to non-javascript behavior very easily (though this theme doesn’t show that).
I’ll work to complete this theme in the coming months, hopefully releasing it sometime soon in a more complete version. The code for the dynamic image navigation may also become a part of the Zenphoto core, at option to be turned on or off by the user. Themes wouldn’t even need to be changed to take advantage of it. Please, leave a comment, tell me what you think! Thanks.
JavaScript2
Thursday, March 1st, 2007
I ran across this gigantic post on what Steve Yegge calls the “Next Big Language” and I’m saving it here partly for my own reference, partly to comment on what it is exactly.
He tries to keep it a secret, but it’s obviously JavaScript 2, or ECMAScript 4, whatever you want to call it. “JS2” will stick better. I’ve always thought JavaScript was quite an elegant language, if only because functions are first-class. Add optional static typing, and all the other features he lists, and it looks like it won’t suck. I can only hope it keeps some of the simplicity and flexibility of JavaScript in its current state…
If you’re interested, click through this slideshow on JavaScript 2 and the Future of the Web, or look at Mozilla’s Tamarin Project. It really looks like a complete and useful language, and it makes sense that if the web is the “next big thing” then the next big language will be the one and only language that runs on it.
Until it gets there, I’ll keep up with my JS1 skillz and get some Ajax going in the zenphoto backend…
1.0.8 in a few minutes.







