bigredswitch

Push it. You know you want to.

Folding

As editors have added code folding, I’ve generally yawned and ignored it, even when my editor, the best editor in the world, VIM, added it.  I’ve never really reasoned with myself why; it was just an immediate dislike of it. Of course, someone, Jeff Atwood, eventually posted that they hate it too and why. And I thought, yep, I knew that all along.

But, interestingly enough, Atwood was responsible for changing my mind on it. In his and Joel’s podcast (Stack Overflow #15), he said one of those sentences that light up a bulb in your head: something about comparing folding with partial classes (which I’ve never heard of before).  Immediately, I thought about something that bugs me — that’s boilerplate code which clutters up your classes.  For example, javabean methods.  Everytime I have to scroll across a page or two or three of these, it chafes me.  What made the connection with me was that in a previous bout of bitterness, I tried to use inheritence and other tricks to get rid of these methods.  It doesn’t work.  And I’m pretty stubborn and tried some pretty weird things including using a script to stitch classes together.  Yep, partial classes.

So, the short of it is that I use folding now to get rid of javabean methods; and it works well:


  SomeType beanA;
  SomeType beanB;
  SomeType beanC;
  SomeType beanD;
  SomeType beanE;
  SomeType beanF;
  SomeType beanG;
+-- 51 lines: javabean methods -----------------------------------------

  public void someRealMethod()
  {
    // do something real
  }

But, my rules for folding are pretty strict though: that it hides no information and that I would never ever want to edit these methods. Javabean methods fit this definition nicely, so do injection methods; imports do not.

svndiff

A request from dev: In CVS, there was a command ‘cvs -q up’ that showed you which files were going to be updated without actually updating.  How do we do this in subversion?

From the Redbean Book, you can see that we use ’svn status -u’; items with an asterisk shows that a newer revision of it exists on the server.

Just to go a little further, there’s a nice script here that shows how to get a diff of all items that have changed.  I wrote a Perl version of it so we can actually do this on Windows (install Perl of course):

#!/usr/bin/perl
$arg=$ARGV[0]||'.';
$out=`svn status -u $arg`;
system("svn diff -r$1:HEAD $2")
  while($out=~/^\s+\*\s+(\d+)\s+(.+)$/mg);

The Difference?

A lot of people ask me how our application is different from Yelp, or setting up a Facebook or Ning page for their business.

I would say that those activities fall under the “promotion” umbrella - prospects are drawn in to your network, and provide reviews or other artifacts that serve to maintain your business profile.

Our application is fundamentally different; it provides a set of tools for business owners that offer intrinsic value regardless of network - coupons, events, and email. And, by the way, there is a “business card” page that populates a directory listing of businesses, but this is a corollary rather than primary purpose.

We work alongside existing networks by providing widgets that are input and output bridges from our app to your network. And, of course, we have ambitious plans for mobile - who doesn’t?  But ours are different ;)

Stay tuned!

Musical Interviews

I like interviews and some of the most interesting interviews are with musicians (actors as a group are not nearly so interesting). The good ones I’ve heard lately:

Bobby Womack (Fresh Air)
Sharon Jones (Fresh Air)
Swamp Dogg
(Sound of Young America) [MP3]

There were some interesting white musicians as well but they had accents; e.g. 2 Nicks:

Nick Cave (Fresh Air)
Nick Lowe (Fresh Air)

Synchronizing Collections

Threads

A rundown on some good Java synchronization links I’ve run across recently:

Vector vs. Collections.synchronizedList Discusses using a Vector versus wrapping a List (usually ArrayList, but other Lists as well) with Collections.synchronizedList. The rule of thumb that’s bandied about is to use Vector when you need a synchronized list and a plain List (ArrayList) otherwise. But this bothers me because then what’s Collections.synchronizedList for? Well, this article argues that Vector should be deprecated and you should always use Collections.synchronizedList which I wholly agree with.

Synchronization discussion on JavaPosse Explains ConcurrentModificationException in context of HashMap and HashTable (look for Reiner’s comments). This exception is widely misunderstood and many people misunderstand it as in this discussion. Again, it is stated to use Collections.synchronizedMap over HashTable and that HashTable (as Vector) should be deprecated.

Do Java6 Threading Optimizations Actually Work, and Part 2 Excellent overview of Java6 threading optimizations and if they actually work with measurements. Any article that discusses performance without hard numbers should be tossed straight away.

First of all, what is a micro business?

Great question, one that I get asked more often than expected. I mean, it seems fairly apparent - businesses that are run by moonlight, early stage mom and pop stores, and the like. Everyone from the part time Etsy seller, to the eBay superstar, to the 30 employee yoga studio in a downtown metropolis.

Now, I’ve done a bit of marketing and sales in everything from micro, small, to enterprise big box, and everyone’s interested in the same things:

  • Acquisition
  • Retention
  • Upsell

The BRS feature set seeks to distill these three activities down for micro and small business owners, wrap it up in a nifty-and-easy-to-use product, and deliver it in a software-as-a-service package.

Moving the blog forward!

I’m sure many of you have noticed the look and feel upgrades around here. There’s a few items to go, but in the grand scheme of things - the cake has been frosted. Time to go in and add the piping, roses, and those little chocolate dots. This is where the metaphor ends, because there’s no cake metaphor for continuous update and maintenance … or is there? Let me know.

Blog-enabling has been fun, but I’m looking forward to actually writing more relevant content. One-post-a-day! I can do it! GO ME!

Exception Library

A Java library that I’d like to see that I can’t seem to find is an exception library. Now, your first reaction might be something like, that’s silly because an exception doesn’t make sense outside of the context it’s used in. But, what got me thinking about this assumption was the general thoughtlessness and messiness you see in exception hierarchies of applications. I think this is generally because exceptions have minimal dependencies. This makes them easy to add and individually low impact so programmers add them willy-nilly with little thought. But like grains of sand in an engine, they can add up and becomes become a major irritant. My first clue that this is not the way it has to be is from the Spring framework’s database exception hierarchy. Spring’s exceptions actually get a lot of treatment and it’s obvious that they actually thought this one out! Also, in Joshual Bloch’s Effective Java Item 42 states “Favor use of standard exceptions”. So putting these together, you get: exceptions should be actually designed (rather than added ad-hoc) and they should be general.

This of course leads to the idea of using an exception library. The JDK has a few general exceptions that are quite useful but they do not cover that many cases. Spring has a good general database hierarchy but not any for other areas. Unfortunately, in my search, the exception library aisle (going back to shopping) is empty. Maybe I’m not looking hard enough?

Gone Shopping

With all the open source projects out there, it can be difficult to evaluate all the libraries for any given task, especially for smaller areas where there is no established patterns. This process feels a lot like shopping: first, make a list of available products, and then evaluate each one. The evaluation process can be excruciating depending on your personality. So I’ve been trying to take the advice of my 7-year old who tells me, “why do you always do you always think about things so much, just choose”. The last time I had to shop for a library was in evaluating Java JSON libraries last week. Each of the 17 libraries on the JSON.org site seemed just as good as the other. So I quickly flipped through each one and two stood out to me: JSON Simple and Jackson. If you look at the two links, I think you’ll get an idea of what appeals to me: simplicity and an academic approach. In the end, I chose Jackson because the guy who wrote it (Tatu Saloranta) seems like one of those clever C guys with the emphasis on efficiency and the old school interface. In an uncertain environment, I’ll take one of these guys over the new-fangled interface with 5 external jar dependencies any day.

The Good and the Bad

I think that one statement demonstrates what’s good and bad about Java (the language):

int x = ...
if (x) ...

Of course this doesn’t compile in Java because the variable x does not evaluate to a boolean.

Supporters will state something like, duh — only booleans can be used as conditions; this is
consistent and explicit, and this type of implicit casting leads to errors.

My thought is: yeah, you guys are right; managers love this and it’s easier to teach students; but … sigh … nevermind.

« Previous Entries