Tuesday, November 30, 2010

Programming when speed counts

A clever fellow at my work posted a link to Numbers everyone should know. When speed matters, you need to know what is cheap and what is dear.

Dear Oscar Wilde said "What is a cynic? A man who knows the price of everything and the value of nothing." But Alan Perlis countered, "LISP programmers know the value of everything and the cost of nothing."

Learn your costs, the value you get for them, and the price you pay.

Saturday, November 27, 2010

Getting started with Ruby on Windows from Felix Raab

Felix Raab posts Ruby Development on Windows, a practical getting started guide. I've seen similar instructions elsewhere. This one is a little different in that he walks you through setting up Microsoft ConsolePowerShell instead of Cygwin. I want to give this a try.

Take that, Mike

This post is gentle ribbing at the best developer I work with at JPMorgan: Mike Doberenz. He is a big Eclipse fan, I am an IntelliJ fan. It's a little like the Emacs-v-vi flame war except that there is an actual argument in favor of Eclipse.

Martin Mikkelborg writes a helpful post on preferring IntelliJ to Eclipse for Android development.

As Mike and I often observe, folks like me feel IntelliJ is better than Eclipse. But I also believe the development model of Eclipse is likely to win out in the long run (units arbitrary):

However, JetBrains has done brilliant work lately in bringing out a free, community edition and keeping their API accessible to plugin authors. It will be interesting to watch the contest of editors over the next few years.

Here is JetBrains explaining how they succeed in an interview with Michael Hunger.

Saturday, November 20, 2010

Looking forward to IntelliJ IDEA X

I'm looking forward to IntelliJ IDEA X (10), due real soon now. Typical of the incremental improvements every release has is How to Run a Single Inspection in IDEA X?.

I've been running the preview releases for a while now, and have noticed to my delight that version X is generally faster and lighter-weight than 9 or 8. Faster, better — what's not to like?

Find broken symlinks

Helpful sysadmin tip from Jason White (jasonjgw), philosopher cum Linux expert, on finding broken symlinks.

Thursday, November 18, 2010

Great agile advice from Improving Enterprises

Devlin Liles of Improving Enterprises writes of his type at Tyson: Lessons Learned: A Developer Retrospective. My favorite piece of advice is the first one: Always Say Yes:

If the user wants you to write a program that will send unmanned spaceships to hundreds of planets and safely get them back. Say yes. The time, money, effort, and return on investment should be the determining factors for a request, not the developers opinion.

I'd love to build that project.

Thursday, November 11, 2010

Monday, November 08, 2010

Great management example: origins of Java

I found a real gem in this e-mail exchange featuring Patrick Naughton. This part jumped out at me (written by Sean Luke):

As I remember my Java history Patrick Naughton the gentleman who got the ball rolling was about to quit Sun and join up with NeXT. He happened to be on the same intermural hockey team as Scott McNealy. Scott told him to hold off, write what he thought was wrong with Sun before he left. Patrick didn't leave and was one of the original Oak people.

This is amazing! McNealy was the right kind of manager. Naughton discussed his interests in leaving Sun with McNealy, McNealy asked for feedback and helped Naughton start a new project.

The Internet is filled with tales of the other kind of boss.

Also, I should join my boss' team.

Saturday, November 06, 2010

Project inception

A great post from Jonathan Rasmusson (author of The Agile Samurai) on successful project inception. I wish I had his slide deck.

Thursday, October 28, 2010

Sunday, October 17, 2010

More on more uses for Iterables

RĂºnar Bjarnason writes Scalaz Tutorial: Enumeration-Based I/O with Iteratees, an all-singing, all-dancing approach to composable iterators for I/O in Scala. This is a much fuller treatment of I/O iterators than my post, More uses for Iterables.

Wednesday, October 13, 2010

Java ain't got no rhythm, but can it keep time?

I need sub-millisecond timing in Java; I want to measure events in the low microsecond range. What to do? My options seem to be:

  1. Use System.currentTimeMillis() and average over long numbers of runs; many problems here.
  2. Use System.nanoTime() and time individual events. Great, but the Javadoc is very scary for multi-threaded code.
  3. Try out sun.misc.Perf.highResCounter() (many non-official references for this.)
  4. Write our own JNI call for gettimeofday().

After months of hitting my head I wised up and looked into the JDK6 C++ source code. Surprise!

The C++ source

Drilling down points me to os::javaTimeNanos() (nanoTime), os::elapsed_counter() (highResCounter), and os::javaTimeMillis() (currentTimeMillis). On Linux these are:

System.currentTimeMillis()

jlong os::javaTimeMillis() {
  timeval time;
  int status = gettimeofday(&time, NULL);
  assert(status != -1, "linux error");
  return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
}

System.nanoTime()

jlong os::javaTimeNanos() {
  if (Linux::supports_monotonic_clock()) {
    struct timespec tp;
    int status = Linux::clock_gettime(CLOCK_MONOTONIC, &tp);
    assert(status == 0, "gettime error");
    jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec);
    return result;
  } else {
    timeval time;
    int status = gettimeofday(&time, NULL);
    assert(status != -1, "linux error");
    jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec);
    return 1000 * usecs;
  }
}

sun.misc.Perf.highResCounter()

jlong os::elapsed_counter() {
  timeval time;
  int status = gettimeofday(&time, NULL);
  return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
}

And:

void os::init(void) {
  char dummy;   /* used to get a guess on initial stack address */
//  first_hrtime = gethrtime();

  // With LinuxThreads the JavaMain thread pid (primordial thread)
  // is different than the pid of the java launcher thread.
  // So, on Linux, the launcher thread pid is passed to the VM
  // via the sun.java.launcher.pid property.
  // Use this property instead of getpid() if it was correctly passed.
  // See bug 6351349.
  pid_t java_launcher_pid = (pid_t) Arguments::sun_java_launcher_pid();

  _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();

  clock_tics_per_sec = sysconf(_SC_CLK_TCK);

  init_random(1234567);

  ThreadCritical::initialize();

  Linux::set_page_size(sysconf(_SC_PAGESIZE));
  if (Linux::page_size() == -1) {
    fatal1("os_linux.cpp: os::init: sysconf failed (%s)", strerror(errno));
  }
  init_page_sizes((size_t) Linux::page_size());

  Linux::initialize_system_info();

  // main_thread points to the aboriginal thread
  Linux::_main_thread = pthread_self();

  Linux::clock_init();
  initial_time_count = os::elapsed_counter();
  pthread_mutex_init(&dl_mutex, NULL);
}

(The net effect is to normalize to 0-time at JVM boot rather than the epoch.)

The solution

Just use System.nanoTime() and stop worrying so much. It is fine for microsecond timing—even across threads—just RTFM and ignore javadoc.

Sunday, October 10, 2010

Elena Yatzeck promotes the agile Army Leadership Field Manual

A positive, fascinating post from Elena Yatzeck on agile leadership as taught in the U.S. Army Leadership Field Manual. The only military members of teams immediate to me are presently serving overseas. Looks like I missed out.

Saturday, October 09, 2010

Larval Java

Very cool post from John Rose on larval objects in the VM. How are immutable objects really made in the JVM? How could it be improved? Read and find out.

Friday, October 08, 2010

Nice refactoring example from Bobby Johnson

Bobby Johnson walks us through a nice refactoring example. Its not rocket science or brain surgery, but good old-fashioned craftsman handling of code, great to show journeymen programmers not quite sure what code cleanup looks like.

Saturday, October 02, 2010

Come hear me at the Houston TechFest

Come here my talk at the Houston TechFest! I am speaking on Hands-free Coding: Code Generation with Annotation Processors on October 9, 2010 03:45 PM - 04:45 PM at the University of Houston University Center. See you there!

UPDATE: Unfortunately, I spent today laid up at home with a bad back, and was unable to present at TechFest. This is very disappointing. However, as promised, I'll still post sources in the next day or so.

Friday, October 01, 2010

Dick Management

Some Guy's Blog captures dick management perfectly: the difference between good and bad managers. I pursue the former and eschew the latter. You should, too.

Wednesday, September 29, 2010

Hamlet D'arcy on Mockito

A beautiful post from Hamlet D'arcy on Mockito - Pros, Cons, and Best Practices. My team at work uses EasyMock. I want to use Mockito for my next project; this post makes it an easier sell.

Friday, September 10, 2010

Getting maven dependency sources and javadocs

I found Ted Wise posting on the problem I tackled today: how to download sources and javadocs from command-line maven:

$ mvn dependency:sources
$ mvn dependency:resolve -Dclassifier=javadocs

Unsure why the discrepancy.

Sunday, September 05, 2010

The error of group-think

Idris Mootee writes at Blogging Innovation about the error of group-think. My favorite quote:

I see this all the time, one smart person can make a quick decision to solve a problem, two smart persons can frame an issue better and share perspectives and ten smart persons often have no idea of what problems they are trying to solve.

I have seen this all my work life: decision-making by committee produces the proverbial camel instead of a horse.

UPDATE: Fixed article link.

Friday, September 03, 2010

IntelliJ made me $1500 trading on my portfolio today

IntelliJ made me $1500 trading on my portfolio today! No, not really. But is there anything for Java programming it won't do? I read about a "new" (new to me) feature in the IDEA blog, Referencing marked objects in expression evaluation. The post describes cools updates for IDEA X to this already cool feature.

And a picture to save (1000 - N) words: