Posts tagged: PROGRAMMING

Software, meet hardware

My friend Matt recently got a microcontroller kit as a present. It’s pretty geek-tastic – you wire up circuits on a little breadboard, write code on your PC, download the compiled code to the microcontroller, and run. At which point, depending on your skill and ambition, your LED blinks, your piezo buzzes, or your robot limbs and sensors do their thing. And your cat runs into the other room.

All very cool, but the language – a BASIC dialect called PBASIC – overwhelmed my delicate sensibilities. For example, take this bit of code (found on the web)…

It's Haskell

In my programming resolutions post last week, I mentioned a short list of languages I was considering learning (or attempting to learn, anyway) in 2007.

I’ve decided on Haskell. Some of my reasons:

  • It’s different. My “home language” is Python, which is great. But for a growth exercise, different is good. Blog posts bemoaning the weirdness and difficulty of Haskell only goad me on. Ruby is different from Python, but not as different as Haskell. Its declarative aspects remind me of Prolog, which I found strangely satisfying when I played with it in college.
  • It’s a functional language. The functional style has always appealed to me, something I was reminded of when playing with Scheme last year.
  • It feels like it’s growing. I wouldn’t say Lisp and Scheme are dying (if anything, they seem to be in a renaissance), but Haskell is popping up everywhere I look. Maybe I look in weird places. (I note that while the Pragmatics’ “Language of the Year” page doesn’t seem to have been updated since 2002, their 2002 pick was… Haskell.)
  • The community seems good. One of the things I did when “researching” (I use that term loosely) languages was stick my head into their respective IRC channels. I found #haskell to be very friendly and active; that’s very appealing when you’re a solo developer trying to sort out confusing new concepts. The Haskell Sequence is a great resource, busy and wide-ranging but not overwhelming.

On the down side, let’s see… well, the logo is pretty ugly.

Advice on sequencing items in web interfaces?

A small but common task in web interfaces, especially “admin” (back-end, content manager) interfaces, is sequencing items. Any time you have a collection of objects that requires arbitrary, user-defined ordering (i.e. ordering that can’t be derived from the objects’ values) you are faced with this problem. Navigation is a common example. If people can add items to a dynamically built navigation menu or tree, how do we let them specify the ordering so that “Contact” can appear below “About Us” or vice-versa?

On Rewriting Software

Kevin Barnes has an interesting post about software rewrites. Here are some of the questions he thinks you should be able to answer “yes” to in order to proceed with a high chance of success:

  • Do you honestly believe that if you rewrote it without adding any features the resulting code would be 33% smaller than the current code?
  • Do you have a very senior sponsor who understands and believes in the project?
  • Can you get enough resources (even on a temporary basis) to support development on the old code base while the new code is written?
  • Is the project critically important to the company’s future?
  • Can the company go without a major release of the product for half the planned coding duration?
  • Do you have anyone on the team who has successfully rewritten a major piece of software before?

I find his list thought provoking for two reasons. First, like (all|most) programmers, of course I have applications in use that I would like to rewrite.

New Year's programming resolutions

It’s that time of year. In no particular order, here’s a quick list of goals for Paul-as-developer in 2007.

  • Convert my remaining legacy PHP code (side projects and regular work both) to Django.
  • Write a useful PyObjC application.
  • Make some kind of contribution to Python itself, if possible.
  • Continue to add revision control and deployment automation to existing projects, as well as using it on new projects.
  • Continue to add unit tests to existing projects, as well as using them on new projects.
  • Learn a new language well enough to write a useful (small) application. Current candidates (all of which I’ve done at least enough reading on to have specific reasons for my interest, and some of which I’ve written toy programs in) are Haskell, Common Lisp, Io, Objective-C, and Ruby.

So, what about you? What are your coding goals for 2007?

99-byte Python quicksort

Update: Browsing through my Python Cookbook this evening I discovered entry 5.11, “Showing off quicksort in Three Lines”, which includes some code very much like mine below. The entry does a good job of emphasizing that these bits of code are perhaps to be savored but not to be actually used. It also includes an insanely (impressively?) convoluted version that uses three lambdas in a single line and weighs in at 105 bytes. I thought this might be the best possible in Python 2.4 and earlier, but in fact a simpler version can be constructed using the old short-circuit logic trick, and at 94 bytes it’s even smaller than my original. Here it is: q=lambda s:len(s)and q([x for x in s[1:]if x<s[0]])+[s[0]]+q([x for x in s[1:]if x>=s[0]])or s

Enticed by the lovely Haskell quicksort example, and sullied by the code-crunching ways of Codegolf, I decided to see how small a Python quicksort function I could write. I stopped at 99 bytes.