Hacker News new | ask | show | jobs
by kruffin 5021 days ago
If an assumption can be made that you won't put null values into the map then it can be rewritten where it doesn't need to do the check described above:

  value = map.get(key);
  if (null == value) {
    // Handle no value in the map
  }
Any class correctly implementing Map in Java won't throw an exception if there is no value for an input key (http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#...) and some don't allow you to put null values in to begin with (http://docs.oracle.com/javase/6/docs/api/java/util/Hashtable...).
1 comments

I think one of the points of the OP's article is that in Go you don't have to code like you've done here, where a single return value means one of two things (in your example: value in the map, or special reserved value that indicates the key wasn't found in the map). Go is cleaner, even if it's just a small improvement.