Nov 25 2010

Retweet October 2010

From time to time I just blast tweets about software development, project planning, team dynamics, or whatever else comes to mind. Here is a synopsis of recent tweets and rants. If you want to follow the conversation follow me at techknow and/or juixe and I’ll be sure to follow back.

Software Development

  • If rhythm is a dancer, then algorithm is a break dancer.
  • If you were a Java language reserve word what word would you be? I would be volatile!
  • I get personally insulted when I am prompted to prove my humanness with a captcha. It makes me wanna bust a cap-tcha on some webdeveloper!!!
  • Is there group think in the development community? Yes, but we build patterns around group think and call it Best Practices.

Team Leadership

  • Change your perspective and you can change the world.
  • If you don’t have an original idea you can remix existing ideas in original ways!
  • Go hard, go home, go big. Pick two.
  • If a web site’s end users are not paying customers, then the end users are the product that web site then sell to their advertisers.
  • Why do people compensate their inability to communicate with the belief that others just know what they mean, you know what I mean?
  • Hype is the food of lemmings.
  • The plan was to have no plan, the backup plan was to leave the backup plan at home.
  • Most people are natural born followers, it’s human nature.
  • The toughest competition doesn’t always come from a competitor trying to build a clone of your product but from market shift in the industry

Product Placement

  • In terms of hardware, mobile, and even operating systems Microsoft is anywhere between 3-5 years behind the leader.
  • Startups age really fast in Internet time, by my calculation Digg is already and Old Media Company.
  • Like what percent of Tumblr’s posts are reblogs and reposts?
  • I want JJ Abrams to do a movie about do a remake of The Muppets in an alternate time line like he did for Star Trek.
  • I want an iPhone that transforms into an iPad when I need a bigger screen.
  • Google is an advertising company with great search technology. Facebook is a virtual share cropping company with great social technology.
  • Who collects more personal data and knows more about a given user, Facebook or Google?
  • Apple should add a few filters to their iPhone camera app.

Mini Meme Machine

  • Scotty and Christopher Walken Mashup: Captain, I’m giving her all’s she got.  She needs more cowbell.
  • You know who would be great in a reality television show? A prison gang! Imagine, Real World San Quentin.
  • r-EPO, the performance-enhancing drug of champions!
  • Monetize common sense because people don’t have it.
  • I want to trademark the & char so that I could file a trademark infringement to all law firms with names of the form Dumb Dumber & Dumbest.
  • The best part of a bagel is the creme cheese.
  • My all time historical hero is Johannes Kepler.
  • Your life comes with terms of service, batteries not included, void where prohibited.
  • In Silicon Valley, everyone drinks the kool-aid but using bottled artisan water from a 10,000 year old glacier.
  • In Silicon Valley, everyone is more interested in their piece of the pie than in the recipe of success.

Quote

  • I didn’t mean for it to be released so quickly because I wanted to control peoples’ being offended by it. – Mark Zuckerberg
  • I think people might be slightly offended but whatever, maybe there’s a way to control that. – Mark Zuckerberg
  • Quitting while you are ahead is not the same thing as quitting. – American Gangster
  • Living at home with your parents is a very powerful contraception. – David Willetts
  • We should start a new social media web 2.0 holiday: Friend, Fan, and Follower Appreciation Day!!!

Nov 23 2010

The Learning Library

I’ve always been a book lover. I have a private collection of Ruby, Perl, and Java books, amongst other topics, that would make a public library jealous. In fact, I recently moved and was surprised that that the bulk of the items boxed up where books. I’ve been making the trend of moving my library to ebooks. I was an early adopter of the Amazon Kindle, I still use my first generation Kindle. Here are some books in my collection, which I’ve use as reference.

I’ve even dedicated a blog post to a few of my favorite books, such as the following.


Nov 18 2010

Predictions 2011

Just like opinions, at the end of the year everyone has their own predictions for the new year. I came to these predictions by reading the back of caps of green tea bottles. If you like to see my accuracy with past predictions see the predictions for 2009 and 2010.

  • Mark Zuckerborg will be summoned by congress for a congressional hearing to clarify privacy settings and violations when some White House intern force checks in the President at a Hooters.
  • Digg will buy Reddit from Conde Nast and rebrand the merged organization as Reddigg.
  • DVDs and Blu Rays sales will slow as users switch to on demand streaming service such as Netflix and Apple iTunes.
  • Groupon will be purchased by Yahoo for $1.5 billion dollars.
  • Facebook will have a major privacy and security flaw but non of its users will notice because they all found a pony in their stream.
  • Google will allow its developers to only use cheap commodity Linux machines. Google employees will no longer be allowed to program in Macs.
  • Google will start to aggressively push and market the Go programming language as an replacement of the Java programming language in the enterprise.
  • Google will buy PostreSQL.
  • Google will buy the Library of Congress.
  • Quora will buy the domain ask.com.
  • Ticket Master will buy Eventbrite.
  • Rupert Murdoch will sell MySpace for $35 million.
  • Mashable will be sold to Rupert Murdoch for an undisclosed $50 million dollars.
  • Michael Bay will write, Steven Spielberg will direct, and Johnny Deep will star in Zynga: The Movie.
  • Zynga and Rock Star Games will co-develop a crossover game called Grand Theft Auto: Farmville.

Mar 8 2010

Top Worst Java Errors

I’ve had my fair share of Java bugs. There is a stage in a programmer’s career that he or she either knows that they rather manage a convenience store or that they can debug common Java errors just by the way the code smells. Here are my list of worst common Java bugs I have been frustrated to solve. These issues have come up more than once, most often in code that I inherited, and had to fix under a time crunch or tight deadline.

mkdir
I’ve had to fix a few bugs related to the mkdir() method in the File class. The mkdir() method creates or makes a new directory. The mkdir() method only creates one directory. But in many situations, especially if the end user is supplying the path of the directory to be created, you will need to crate a whole new directory hierarchy. Often times you will create a directory and subdirectories at one time. In these situations, you want to use the mkdirs() method instead.

Index Of
Most software bugs are caused by assumptions made by the programmer. One common assumption I see developers making is that file names have only one period to separate the file name from the file extension. It is common to see code that finds the first period and everything after that period is assumed to be the extension. Other assumptions regarding file names include that extensions are three characters long or that the file name does not have special characters. The following code snippet is a dramatization of code I have seen in the field, which incorrectly tries parse the file extension.

String filename = "a.file.path.ext";
int index = filename.indexOf(".");
String extension = filename.substring(index);

A different approach, which would have the desired result is to use the lastIndexOf() instead.

Null Equals
I’ve seen a whole slew of null pointer exceptions due to this sort of Java bug where a possibly null object reference will be used to check the equality of a hard coded constant. Here is the code snippet of what I mean.

boolean equals = maybeNullObjectReference.equals("CONSTANT");

The object reference may be null, so you need to check for null values. I found that if you switch your thinking, you can write less code and still achieve a better solution that having to constantly check if the object is null. A safe approach is to use a object that you know is not null, the constant value.

boolean equals = "CONSTANT".equals(maybeNullObjectReference);

Equals
Yet another Java bug that can be easy to miss is the use of the Java equals operator instead of the equals() method. The equals operator returns true if the two object references you are testing point to the same object instance. The equals operator compares the equality of the object references, not the object values but since it reads the same it is easy to overlook.

Map Key
The worst Java bug that I had to ever deal with involved the use of mutable objects as keys in hash maps. The implementation of the Java HashMap is really simple, the hash code of the key is used to locate the bucket in which to store the map entry, which consists of the key/value pair. Once you put a key/value pair in a hash map you should not change the value of the key, ever, in any way that changes the hash code. If the key is changed where it generates a new hash code, you will not be able to locate the correct bucket in the HashMap that contains the key/value pair. I had a scenario where key/value pairs were stored in a HashMap, then the keys where updated generating a new hash code, and there after the value was not able to located.


Jan 17 2007

Reopening Ruby Classes

In Ruby the implementation of a class is not closed. In Ruby, it is incredibly easy to add new methods to any existing class at runtime, even core system classes like String, Array, and Fixum. You just reopen a class and add new code. This language feature makes the language incredibly flexible. You might be wondering, why would you need this? Well, take a look at the API documentation of the Java String class. In most development organizations that I have been a part of we have had to write small string libraries that provide far more functionality that provided by the Java String class. The Apache Jakarta Commons Lang project provides a String helper class in StringUtils. StringUtils provides methods such as IsEmpty, Chomp/Chop, and LeftPad. StringUtils. StringUtils is a great class that has saved me from re-inventing the wheel several times, but it is another library to download, configure, learn, and import. Using the StringUtils class is more verbose calling a method on a string.

// Using StringUtils to trim a string.
str = StringUtils.trim(str);
// Calling a trim on a string.
str = str.trim();

Isn’t more concise and easier to read when you invoke a method on a string instead of using StringUtils? Unfortunately, even if an JCP is approved to add your custom string methods to the String class, the whole process is very time consuming. Each incremental release of Java takes years to develop. In Ruby, you can just reopen the String class to add the few methods you feel it lacks. To reopen the Ruby String class we can use the following code:

# reopen the class
String.class_eval do
  # define new method
  def get_size
    # method implementation
    length
  end
end

Continue reading


Jul 23 2006

Ruby Language Goodies For Java Developers

If you are new to the Ruby programing language you might not be familiar with some of the short semantic sugar or language goodies that Ruby provides. I think that for most of the hard core Java developers the code samples that will be provided here will be novel but Perl hackers will not be impressed. So as an aid to all my fellow Java developers I will try to compare and contrast Ruby code with Java. To get started lets set three values to three variables in one line of Ruby code:

var1, var2, var3 = 'one', 'two', 'three'

You can’t do this in Java. The best you can do in Java is set three variables with the same value, which Ruby also supports, like this:

var1 = var2 = var3 = 'same value'

Methods
In Ruby, you can initialize default values to method parameters. Here is an example of a method with three parameters initialized to a numeral literal, empty list, and empty hash.

def my_method(parama = 1, paramb = [], paramc = {})
  # method implementation here
end

To invoke my_method you can do so with any of the following lines of code:

my_method
my_method()
my_method(2)
my_method(2, [:abc, :def])
my_method(2, [:abc, :def], :abc => 'abc', :def => 'def')
my_method 2, [:abc, :def], :abc => 'abc', :def => 'def'
my_method 2, [:abc, :def], {:abc => 'abc', :def => 'def'}

This is not method overloading as seen in Java. All of the above method calls invoke the same block of code, the same method implementation. In Java you would define overload the method by defining a separate implementation for each method signature.

Java 1.5 recently introduced variable length arguments, varargs. You could have done this in Ruby years back. To define a Ruby method with variable number of parameters you can do the following:

def my_vararg_method *params
  # params is an array
end

To invoke my_vararg_method you can do so with any of the following lines of code:

my_varargs_method # params is empty
my_varargs_method 'string', :symbol, {} # params = ['string', :symbol, {}]

At this time I invite you to notice that parentheses, like semi-colons, are not required.

Objects
In Java you have two types of data, objects and native. An int is completely different than an instance of Integer and depending on the situation you had to constantly convert one to the other. In Ruby everything is an object, and when I say everything I mean everything including the nil value. The nil value is Ruby’s equivalent to the Java null keyword. In Ruby you can do the following:

1.nil? # false
nil.nil? # true
1.3.class # Float
1.is_a? Float # false
'0'.to_i + 1 # 1
Float.class # Class

And because in Ruby everything is an object you don’t need a autoboxing hack to use the literal 1 as a key in a hash.

hash = {1 => 'one', 2 => 'two', 3 => 'three'}

Lists
Another convenient language goodie available in Ruby is the array initializer. If you want to construct an array of string values without white spaces in them you can quickly do so with the following statement:

list = %w(female male) # list = ["female", "male"]

If you need a whitespace inside a word just escape it with the backslash (\). Now If you want to define an array with the first 10 digits you can easily do so with ranges. Here is an example of how to construct an array composed of the numbers between 0 to 9, inclusive.

nums = (0 .. 9).to_a

Here is how to iterate through each letter in the alphabet using ranges.

('A' .. 'Z').each { |char| puts char }

If you want to loop over an array you will need a range from 0 to the array size, exclusive. To create an exclusive range use the … operator as in the following:

arr =  get_list # some array
(0 ... arr.size).each { |index| print arr[index] }

Control
To wrap let me walk through some Ruby control constructs. In addition to the control construct that Java developers are familiar with Ruby provides a unless and until. The ‘unless condition’ is equivalent to ‘if not condition.’ The ‘until condition’ is equivalent to ‘while not condition.’ Here is a trivial example of the the unless construct.

unless item.invalid?
  print item.to_s
end

Ruby also provides a shortcut for the above code in the form of conditional modifiers.

print item.to_s unless item.invalid?

In both of the above code snippets the item will only be printed if the item is in a valid state. You can use if, unless, while, and until as conditional modifier.

As a bonus, let me state where Ruby is lacking. The Ruby language does not support the — and ++ operator. The best you can do in Ruby is use the next method available to the Integer class.