If you missed Stack Overflow DevDays, there is some audio from it available on Stack Overflow Podcast #71. I wish there was a longer version of this. It’s only about 1/2 hour of outtakes from the conference, but it is still interesting to hear. These snippets are followed by a long discussion with some of the speakers. The conversation rambles and the audio quality is poor so feel free to stop listening after the conference outtakes.
Monday, November 23, 2009
Thursday, November 19, 2009
A comment left on my answer to a question over on Stack Overflow has me a little worked up. I've seen this meme come out of programmers more and more and it just doesn't seem accurate. The statement goes something like this, "Design Patterns were only useful because C++ (or Java) was so broken." The implication is thus that design patterns belong in the dustbin of history now that we have moved on to more enlightened languages like Python or Ruby. In this particular instance the commentor was talking about the strategy pattern. His (?) assertion was that the need for the strategy pattern is not present in a language with first class functions. My response is three-fold. First off, this argument is historically ignorant. The design patterns came as much from Smalltalk as from C++. Second, it is not strictly true. First class functions alone don't obviate the need for the strategy pattern. Finally, providing an alternative implementation does not make the first implementation bad.
The argument that design patterns generally are due to flaws in C++/Java are historically innaccurate. Design patterns (like much of modern programming) originated in the Smalltalk community. Smalltalk is dynamic. It has first-class functions. Most of the flaws pointed to in C++ which "modern" languages solve did not exist in Smalltalk. The patterns, then, have value independent of that flaws and the accused language. For instance, the Strategy pattern is covered not just in the Gang of Four (where it happens to have a C++ example), but also in the Design Patterns Smalltalk Companion which points out that it is used in Smalltalk in the MVC framework at the heart of Smalltalk's GUI. The controller is a strategy pattern. It is also used ImageRenderer and a few other examples.
First class functions do not, by themselves, obviate the need for a strategy pattern. This is more a nit than a real argument, but it remains true nonetheless. To say a language has first class functions means merely that functions can be passed as data types. It does not necessitate that the language implements closures. Closures are a way of capturing the context of the function. They can be used to retain state between calls to a particular function instance. Without closures, there is no state. Without state, many of the strategy pattern uses fail. Consider for a moment using a strategy pattern to encapsulate encryption algorithms. Without closures (or objects), you would have to pass the encryption key to the function every time it was used. This is possible, but not terribly elegant.
The existence of an alternate implementation does not make the original implementation any less useful. The fact that I can get much of the power of OO out of first class functions and closures does not mean OO is now of no value. There are advantages to both techniques. Empirically there does appear to be power in OO that is not captured (easily) by purely functional languages. Most successful functional (or psuedo-functional) languages have adopted OO features eventually. See Python, Ruby, Common Lisp, Scala, etc. All added or have object-oriented features. Let us return to the example of the strategy pattern. Is its utility obviated by the use of first class functions plus closures? In many cases it is. Certainly it could be in the encryption example. On the other hand, strategies are often more complex than mere functions can express. The controller in MVC is a strategy. In anything but a toy application, the controller will consist of multiple functions. Sure, one could create these functions with the same closure and thus share state, but is that really a superior model? I would argue that it is not. In this case it would seem a less clear mechanism because the fact that the functions are tied together is less discoverable. OO languages and functional languages each do things differently. Things that are easy in one are more difficult in the other. Neither is superior in all respects.
It should be noted that when I say "design patterns" above I am referring to it in the common sense of the object-oriented programming design patterns made popular by the Gang of Four book. In a more general sense, each language has its own set of patterns and these can also be thought of as design patterns. Some of the OO patterns are specific to OO languages and the need doesn't translate to functional languages. Others are more "in the large" and likely translate well to all languages trying to solve big problems. It is my claim, however, that most of the GoF patterns will be useful in any OO language. They are not artifacts of particular implementations such as C++ or Java.
Wednesday, November 18, 2009
Lossless codecs are all the rage amongst those who aspire to be audiophiles. Whether it is ripping CDs in a format like FLAC or WMA Lossless or listening the TrueHD track on Bluray movies, there are those who swear by it. Most audio formats like MP3, AAC, and WMA are lossy formats. They compress the audio by throwing away parts that humans theoretically cannot hear. This is called “perceptual coding.” Lossless codecs don’t throw away any information but instead compress more like Zip. Lossless formats require a lot more space to store and a lot more bandwidth to transmit. Are they worth it? Can people really hear the difference?
TrustedReviews says no. They go so far as to suggest than anything over 192kpbs MP3 is virtually impossible to differentiate. “[A] few people in the last six months or so - people who take their audio gear seriously and have spent thousands of pounds on Hi-Fi equipment - have admitted privately to us that 256kbps MP3 is easily good enough for serious listening, and that they struggle to hear much difference over 192kbps MP3 in many situations.” They conducted some A/B listening tests to see if ordinary people could perceive a difference. The results did not support the extra expense and size of lossless formats. In fact, most people couldn’t even differentiate between the 192kbps MP3s and a FLAC encoded version of the same songs. The test wasn’t scientific, but there’s a pretty good chance it matches what those reading this blog will experience.
Considering that most people listen to their music in noisy environments, on suboptimal speakers, or on tiny headphones from an MP3 player like the Zune, the chances they will ever be able to perceive the differences in audio are quickly diminishing.
The short of it: don’t waste the space ripping everything to lossless unless you plan to do a lot of transcoding in the future. Don’t go out of your way to get a TrueHD movie setup. AC3 is going to be just fine.
Friday, November 13, 2009
Six months ago I purchased a Kindle 2. I originally bought the Kindle to make travelling easier. I tend to carry a lot of books with me when I take a trip and those books get heavy. With the Kindle, I could carry just this one device instead of 5 books. The Kindle didn’t disappoint. It weighs less than the typical paperback book. It fits nicely in my Scottevest jacket. I typically have about 80 books on mine at any given time giving me plenty of potential reading material. If that isn’t enough, there is the Kindle store with some 360,000 books.
The Kindle satisfied the purpose I bought it for, but has exceeded my expectations. Not only do I use the Kindle when travelling, but it has become my preferred reading device. The screen is a delight to read on. The contrast may not be quite what it is on a real book, but it is plenty good. The screen on the Kindle is much more comfortable to read on than the screen on a phone or a laptop. There is no refresh rate and no backlighting. This results in a significant reduction in eye fatigue. I can read on the Kindle as easily and as long as I can read a paper book.
In addition to being a great place to read, there are several features of the Kindle that make it my preferred reading tool. The first is the built-in dictionary and the second is the ease of taking notes. When reading a dead tree book, if I come across a word that I don’t know, I will usually guess at the meaning from the context and move along. With the Kindle, I can just move the cursor over the word in question and get a definition at the bottom of the screen. In this way I am able to understand the nuances of the text and expand my vocabulary. The Kindle is also a great place to take notes. Want to add a note? Just start typing using the integrated keyboard. Want to highlight some text? Move the cursor to the start, press down, move to the end, press down again. The notes and highlighted areas are collected in a text file that you can upload to your computer. They are also available on http://kindle.amazon.com/. The notes will follow the book to other devices (like the new Windows software).
So what isn’t to like? The Kindle is an excellent book-reading platform. It is a single-task device. It is great at what it does and not good at anything else. It has a built-in web browser, but it is the sort of thing you would only want to use in case of emergencies. It does not render pages well, is difficult to navigate, and is very slow. For instance, when composing an e-mail via either hotmail or gmail, it writes the letter, deletes it, then writes it again. It is very easy to get well ahead of the cursor even on the limited keyboard.
The Kindle supports MP3 playback, but not in any useful fashion. You cannot see the songs. You cannot select the songs. You can skip to the next song, but that is all. There is no shuffle. Playback happens in the order the songs were put on the Kindle. To say this feature is limited is an understatement.
The Kindle only reads its own formats. It can read variations of the mobipocket format but cannot read pdf, epub (the standard ebook format for everyone else), or even the encrypted mobipocket format found for free at many libraries. This choice perplexes me.
The note-taking is simple and works well, but it is capped. If you highlight too much of a book, the highlights will continue, but the material will not end up in the notes file. This wouldn’t be quite so bad if you were warned but you aren’t. Instead you find out later when you go to the notes file and see a warning instead of the highlighted text.
Perhaps the most disappointing part is the lack of software innovation going on. As someone accustomed to the rate of innovation on other devices, it is disappointing to see no new firmware or features being pushed. The hardware platform is stable, but why not improve the mp3 playback? Why not add new formats? Why not add support for tags or folders?
A few questions and answers:
How is the battery life? It is amazing. With the wireless left on, it will last several days. With the wireless off (and there is no reason to leave it on), it will last weeks.
Is it economical? No. If you buy a Kindle, don’t buy it to save money on books. Sure, they are a little cheaper than the hardcover, but maybe 10%. At $259 for a Kindle 2, it is going to take a long time to make up the difference. If you watch, there are many free books available which can help, but it is not a cheap device.
Are most books available? That depends what sort of books you like to read. I have found that a large percentage of what I read is available. I still run into many books I want that are not available, but I’m not running out of books on it either.
How does it compare to the Nook? I don’t know. I haven’t used the Nook. It appears to have superior hardware in most respects, but the book pricing is much worse. If I were making the choice today, I would still choose the Kindle. The Nook does appear to be giving it a run for its money though. Strong competition is probably what the Kindle needed.
Do you recommend the Kindle? Yes. Highly. If you like to read, get one.