JavaSchool Perils

<1 min read

[@593]
JavaSchool Perils

Joel has written an interesting article titled The Perils of JavaSchools.

While I don't disagree that the state of computer science education has gone down the tube. I really don't think that being able to learn pointer arithmetic is any indicator of someone's ability to become a good programmer.

Vital (and often complex) programming concepts can be learned using any modern language. The problem is that they are simply no longer being taught. Some people may argue they no longer need to be. I think that is just another excuse to lower the standard of education.

I've interviewed literally hundreds of programmers over the years, and have never been impressed by a great formal education on a resumé. A great programmer must be, first and foremost, flexible; capable of choosing the right language and tools for the task at hand. You may learn the mechanics in school, the rest only comes from experience and hard work.

[@601]
What is Joel doing interviewing Java programmers? Isn't Fog Creek a Windows/Visual Basic-only shop?

[@913]
More interesting comments on the subject via TSS and Javalobby.

Simple Sudoku

<1 min read
[@714]

Simple Sudoku

If you like playing Sudoku. Really, who doesn't? I'd recommend giving Simple Sudoku a try:

It's good, and free. What more can you ask for?

Ghost Rider Revealed

<1 min read
[@205]

Ghost Rider Revealed

Joyeux Noël

<1 min read
[@378] Joyeux Noël

toString Velocity Template

1 min read

[@586]
toString Velocity Template

I'm using the excellent GenereateToString plugin to automatically create toString() methods in IDEA.

I've modified the default Velocity template as follows:

/**
* Returns a string representation of the object.
*
* @return A string representation of the object.
*/
public final String toString() {
final StringBuffer sb = new StringBuffer(super.toString());
#set ($i = 0)
#foreach ($member in $members)
#if (!$member.modifierStatic)
#if ($i == 0)
sb.append("[ ##
#else
sb.append(", ##
#end
#if ($member.string)
$member.name.replaceFirst("_", "") -> '")##
#else
$member.name.replaceFirst("_", "") -> ")##
#end
#if ($member.primitiveArray)
.append($member.name == null ? "null" : "");
sb.append('{');
for (int i = 0; $member.name != null && i < $member.name .length; ++i)
sb.append(i == 0 ? "" : ", ").append($member.name[i]);
sb.append('}');
#elseif ($member.objectArray)
.append($member.name == null ? "null" : Arrays.asList($member.name).toString());
#elseif ($member.string)
.append($member.accessor).append('\'');
#else
.append($member.accessor);
#end
#set ($i = $i + 1)
#end
#end
#if ($members.size() == 0)
sb.append("{}");
#else
sb.append(" ]");
#end
return sb.toString();
}

Here's an example of the code it automatically generates:

public class Test
{
  private String _name;
  private int _port;
  private String _url;
  private String[] _validIPs;
  // …
  /**   * Returms a string representation of the object.   *   * @return A string representation of the object.   */   public final String toString()   {     final StringBuffer sb = new StringBuffer(super.toString());     sb.append("[ name -> '").append(_name).append('\'');     sb.append(", url -> '").append(_url).append('\'');     sb.append(", port -> ").append(_port);     sb.append(", validIPs -> ").append((_validIPs == null) ? "null" : Arrays.asList(_validIPs).toString());     sb.append(" ]");
    return sb.toString();   } }

Here's a sample of what it returns:

Test@126b249[ name -> 'Test', url -> 'http://www.test.com', port -> 80, validIPs -> [127.0.0.1, localhost] ]

Overall not that many modifications from the default template:

  • The default template uses name=value, I use name -> value which I find more legible.
  • The default template prepends the class name, I prepend the super's toString() representation.
  • I also remove the underscore in front of field names, once again for legibility.
  • Finally, I added some javadoc comments.

Array Initialization

<1 min read

[@687]
Array Initialization

public class Example {
  public Boolean flags[] = new Boolean[4];
  public static void main(String[] args) {
    Example ex = new Example();
    System.out.println( "Flag 1 is " + ex.flags[1] );
  }
}

Yes, Flag 1 is null. I can't believe I forgot that.