Aug 3 2009

The Rubyist: July 2009 Edition

Here is a recap of the top Ruby-related links for the month of July 2009. Links for The Rubyist are provided by A Rubyist Railstastic Adventure, a tumblelog.

Ruby

Rails

JRuby


Jul 22 2009

Don’t Turn a Code Review Into a Code Rant

In programming circles and when talking about code, I’ve often hear mentioned the Perl slogan “There’s more than one way to do it.” Thinking about the many ways we do it, whatever feature ‘it’ represents, I believe that the root cause of many of the software bugs we encounter are because engineers implement the feature in more than one way, then refactor it down the line, then add new conditions, then forgot how it did what it did. This often occurs because programming is like fashion, each season brings about a set of new best practices and technologies. We update the implementation to adapt to the current best practices, new technologies, and new features and don’t remove old bit rotten code.

Recently I a debate with a fellow engineer whose code I reviewed. As it is often the case, we had some existing functionality which we wanted to update with a feature. Most of the code review revolved around one existing method whose existing code looked something like the following.

public void setValue(DataRow dr) throws DataException {
  dataHelper.setValue(dr, false, true);
}

For the sake of this example, imagine that DataRow is a map of data that represents a row of data from a database and contains the meta-data of the columns it contains. The new functionality need to support a DataRow with a less number of meta-data, columns, than normally expected. We called this new feature partial value and so it was initially implemented as follows.

public void setValue(DataRow dr) throws DataException {
  dataHelper.setValue(dr, false, true);
}

public void setPartialValue(DataRow dr) throws DataException {
  setPartial(true);
  setValue(qube);
  setPartial(false);
}

Believe it or not, I had a very difficult and long drawnout debate with the engineer that implemented the above code. In my mind, there is no debate, the above code can be made to improve. In the engineer’s mind, this was good enough for this feature for the time allotted for the the current specifications for this release and for whatever other reason he counjured up.

One of the concerns I originally brought up with the initial implementation of setPartialValue was that if the setValue method throws an exception after having set the partial state to true, then the code will break out of both methods leaving an improper partial state behind. This will cause problems because the partial boolean field will have an invalid state which will caused problems if you the setValue method is called at a later point. Another problem, with this sort of style of programming, is the following scenario. Imagine that instead of a simple primitive boolean the partial property required an object reference that retained a lot of memory and you had the same exception, the memory for that field might not be garbage collected.

The sort of bugs that can be caused by the above implementation lead me to the following rule of thumb: Avoid instance fields. Always question the need for instance property. Try to be a team player and pass the object reference as a parameter down the stack. If you only need this little bit of state information for a method call, pass it as a parameter!

I couldn’t believe we had this much disagreement over three lines. At that moment I felt that code reviews are another form of micromanagement, but then I remembered who is the one that gets called if there is a bug in the system…. Yeah, me! The approach I was advocating did not require a object instance to keep the state of a boolean, which was only used within the context of the setPartialValue method call. In my approach the set/getPartial methods are not needed and it could have been refactored to the following.

public void setValue(DataRow dr) {
  setValue(dr, false);
}

private void setValue(DataRow dr, boolean partial) {
  dataHelper.setValue(dr, false, true, partial);
}

public void setPartialValue(DataRow dr) {
  setValue(dr, true);
}

The engineer countered that it “does not look nice” aesthetically to have a method call with to many parameters, and that we can’t just add parameters to methods whenever we need to pass another value. Touché. To this I responded that four parameters is not a big deal. Even though four parameter will not negatively affect a method signature, lets imagine that a method signature grew to 10 parameters, this can be solved by encapsulating all these parameters to one object. Programming languages such as Ruby use map literal for optional parameters and long parameter method signatures.

In the end, I won the debate but it didn’t feel like a victory. I doubted myself for pushing so strongly for what I know is right, in the end he was doing all the heavy lifting and this was just one small aspect of the feature as a whole. There is a line that if crossed you will be considered a micromanaging standard fascist, but that if you do not enforce you will inherit unmaintainable code. Coding standards goes beyond naming convention and third party libraries. There is a fine line, and you need to walk the line.


Jul 20 2009

Remote Debug Your Thinking Process

Here two tweet snippets of a conversation I had on Twitter about code. The first tweet snippet started from the realization that we can not only debug and optimize code but our thinking process.

  • @techknow: Debug your thinking process.
  • @DavidKaneda: @techknow Can’t — I only have the compiled version.
  • @techknow: @DavidKaneda You can remote debug your thinking process, so it is like a outer body hacking.

This tweet snippet of a conversation I had recently just pokes fun at Microsoft. Even after all these years, Microsoft blue screen of death and the negative perception/meme of Microsoft products provides so much joy to the world in the form of jokes!

  • @techknow: Most rehash it up, some mash it up, a few smash it up, I fresh it up!
  • @jzy: @techknow I trash it?
  • @techknow: @jzy LOL Microsoft Crash IT UP!

Jul 20 2009

This Week in Startups Twitterers

I just started listening to the This Week in Startups (TWiST) podcast. TWiST is hosted by Jason Calacanis, CEO of Mahalo, and is broken up into segements like Ask Jason, TWiST news, and an interview. The show usually runs close to two hours and it is jam packed with tips, advice, and rants that every technology entreprenuer should listen to. In the last nine episodes Jason has had the CEO, founder, or directors of Savings.com, Yahoo! Local for North America, Microsoft’s Business Development, DocStoc.com, Yammer, Break Media, and Meebo.

Jason promotes listeners to thank advertiser via Twitter. He also encourages listners of the show connect, network, and follow each other Twitter and similar social media networking sites. To help in that end, I’ve compiled a short list of folks that have tweeted the This Week in Startup Tiwtter hashtag (#TWiST). Most of these twitterers are developers, entreprenuers, and small business owners.
Continue reading


Jul 8 2009

Google Chrome OS

Google just announced that they are working on a new Operating System designed for netbooks. You might think they are talking a new version of Android specially designed for netbooks, but you’ve be wrong. Google is developing a new web-based browser-powered Operating System dubbed Chrome OS. Android is Google’s Operating System for mobile devices such as the G1 phone. Chrome is Google’s internet browser comparable to Mozilla Firefox or Apple Safari. Android, Chrome OS are two different and separate overlapping projects intended for the the same market. Technology pundits had for the longest time talked about a Google Operating System of mythical proportion that would go head to head with Microsoft Windows.

The idea of a Internet Operation System is not new. The idea of the browser as a platform is as old as, well the first browser. More recently, the Palm Pre uses a proprietary Web OS, there have been rumors floating around that Facebook has been working on a web Operating System, and yet the idea has never taken off.

The engineering masterminds behind Google Chrome OS intend to initially target the new Operating System for netbooks to be released sometime after the second half of 2010. That’s like, next year! Originally, when the first netbooks started to be sold by ASUS, like last year, the de facto OS was a version of Linux. But consumers don’t want a netbook with a watered down Operating System, consumers don’t want to run some wonky cloud clone of Word. Netbooks users, myself included, want to run a full Operating System with all of the application I have already invested time and money on, such as Word! For all the engineering capital behind this project, I feel that they haven’t taken into account the trends behind current netbook sales!

As computer users, we all want a better experience. But Chrome OS is not thinking outside the box, it is not revolutionary, and it is not a disruptive technology. Chrome OS is definitely not what consumers asked for. When users say they want to get to their email instantly, that they hate waiting ten minutes to startup, and that they hate having to constantly upgrade applications… All this does not mean users want a browser powered OS! Their can better be meet with an “always on” computing device, much like the iPhone.

The iPhone is the device of the future, not a water down web powered netbook device! The OS behind the iPhone is the same OS behind OS X! Your iPhone is a netbook device! When the iPhone was initially released, the only way to develop application for the device was through the Safari browser, so all iPhone applications were initially web applications. For a whole year, web applications were the only way to develop for the iPhone. As soon, as Apple released the native iPhone SDK an explosive new market has been carved out by developers. I don’t see this same effect being caused by Google Chrome OS.

Here are a few select links regarding Google Chrome Operating System.


Jul 7 2009

Retweet June 2009

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 I’ll be sure to follow back.

Programming

  • Doing Java Profiling… It is fund finding memory leaks and bottle necks in enterprise Java applications!
  • Greatest strength is that I am a software architect, greatest weakness is that I think I am an architect.
  • Exceptional FAIL: Worst exception handling is when the log message throws an null pointer exceptions.
  • As a software architect you don’t build solutions, you build opportunity for solutions and likewise opportunity for defects.
  • A code freeze slows productivity.

Product Placement

  • Really disappointing with HP Support. I thought they have 24-hour support but they want me to call between 8 – 4PM PST to open a request…
  • I thought the reason HP Support outsources and off shores support folks is to provide around the clock support! HP can’t keep up with me!
  • In this flat world I was wondering why I need to call HP Support between 8AM – 4PM PST to get a box for a laptop sent to me?
  • The best support I have had is from Apple Genius Bar at Apple stores. It is best to go in the morning as soon as they open!
  • Eating and loving Japanese treats, Hori Hokkaido Corn Chocolate.
  • Mac OS X has had 5 upgrades, Puma, Jaguar, Panther, Tiger, and Leopard. I can’t wait until Mac OS X LOLcatz version.
  • For a company that claims to do no evil, Google sure employees a lot of lawyers.
  • Ticket Master would love to scalp it own tickets and keep all the cash!
  • It used to be that patron, gucci, and cristal used to dominate hip-hop product placement, now it is youtube, myspace, and twitter.
  • Having Wetzel’s Pretzels and a heart attack. Ouch!
  • Which would you pick: netbook + $150 or Kindle DX?
  • Amazon unvail new 9’7″ Kindle DX priced at nearly $500, that is more expensive than a netbook.
  • Watching Hell’s Kitchen.. Chef Ramsay should do School Cafeteria Nightnare.
  • McD’s new motto: Condiments upon request.
  • Even though their use of nano is not copyright infringement, the Tata Nano is piggy backing on the iPod Nano marketing and name recognition!
  • American Idol is the modern day Roman Colosseum spectacle and today it has been an a bloodbath!
  • Jamba Juice cup says ‘it’s hard to frown with a straw in your mouth.’
  • Just bought a 120GB XBox 360 hard drive.
  • One XBox Live point is worth about 4/5th of a cent…
  • The Bachelor should really be renamed to The Womanizer.

Business

  • The big part of getting things done is to have others to get things done for you and have things done automatically.
  • The worst plan is one that does not allow for spontaneous serendipity.
  • Wealth trickles down from the top, but it grows from the bottom. Invest where it grows, encourage the source of growth.
  • The worst mistake is not making enough calculated mistakes and taking enough measured risks.
  • When given lemons, some make lemonade. I like to make sucess out of failure, it is more refreshing.
  • Your next success is right behind your current failure.
  • Not all problems are meant to be solved. First try to remove problem, if it still persist reduce it, and then try to reframe it…
  • Not all clients are profitable equally. Fire your under performing customers.
  • If someone says a thing is easy and enumerates ten steps, it could be easier.
  • If you can do something in ten steps, then you can reduce it to one step.
  • A good leader leads by asking better questions than by giving bad answers.
  • When you use assumptions as axioms, you end up with calculations such as 1 + 1 = Profit!
  • Build a better mousetrap and the world will find a better mouse to trap.
  • The problem with a 800-pound gorilla is that it does the job of a monkey.
  • Don’t listen to words, listen to actions.
  • You had me at show me the money!

Twitter

  • Do I need a Verified Twitter Account to avoid my own identity confusion and doubts?
  • I think of the Trending Topics as the collective mood of Twitter.
  • Twitter should allow users to explicitly note the copyright of their tweets… I would make mine as Create Commons-Attributions.
  • Every other trend on Twitter an inside joke…
  • What is the best twitter client on the iPhone? The desktop?