May 9 2009

Repetative Recursion

One of my pet tech peeves is repetition and redundancy. I wish documentation had the same level of reuse as code. But in reality I find that we tend to repeat ourselves even in code just for duplication’s sake and we don’ realize it. Were I see a lot of superfluous repetition that is easy to overlook is in naming of variable, fields, columns, and classes. Here are a few examples of what I mean.

You have a folder called ‘Experience’ and under that all files are named like the following ‘exp_search_test.xml’ filename. The filename repeats that this document is an experience, whatever that really means. If you really want to indicate a file is of a given data type use the extension, so you rename the file as ‘search_test.exp’ or ‘search_test.exp_xml’ to indicate the file type.

Another example dealing with code is that variable names repeat their purpose. For example, you have an Employee class and the class has a subsequent employeeFirstName. If the variable is inside the Employee class, it is not required to prefix the class name to each field name. Use the context of the class to define meaning, don’t ad verbose comments to repeat what is clearly obvious like ‘This is the employee first name.’

I see this same problem in database column names. Another example that comes to mind of a real database schema used in production is of a fund table with column names such as fund_long_name, fund_type, etc. Again, I prefer concise and succinct column names.

Let me repeat myself again, if you try to add context to field name where it is already obvious you actually populate the namespace. Here is a more concrete example of that, again from code used in production. There was an ExcelExport class that contained the following two methods, exportExcel() and urlExportExcel(URL). Which method name should we refactor to simplify the API? … You might be thinking to rename urlExportExcel(URL) to simply exportExcel(URL) and in this way provide a concise API by overriding the same name but with different parameter list. Remember, the method signature of most languages includes the parameter type/list. But I would not stop there, I would actually rename the exportExcel() and exportExcel(URL) method names to simply export() and export(URL)! Why? Well, because you don’t just export data to Excel, you usually export data in different formats and flavors such as XML, RSS, CSV, etc. I hope that you can now see, that simply naming this method as export and using polymorphism, interfaces, subclasses, and factory pattern you simplify not just your method names but code.

An example of recursive repetition is where a word in the dictionary refers a different word, but if you look up the second word it refers to the first. As rule of thumb to avoid dubious verbose recursive repetition, variable names are not comments and comments should not repeat variable declarations.


May 7 2009

Laws of Source Code and Software Development

I’ve worked in a variety of projects, in a myriad of languages, and have learned the following universal truths about software development the hard way.

  • Commented out code are not comments – Use version control, don’t track code changes by commenting them out. Commented out code is schizophrenic code.
  • Let your reputation and code precede you – If you work on open source projects, blog, and work your network, you will get more job offers even when you aren’t looking for a job than people that are looking for a job and just email out resumes.
  • Don’t make excuses for code, let it speak for itself – You are paid to find solutions using code, not find excuses for your code. ‘It worked on my machine’ is not a solution. You will not ship out your computer to the client with the application.
  • Don’t take code personal – Don’t take code reviews personally, it is not about you but a business feature and the overall performance of the application.
  • Your code is your career legacy – For years after you leave, those that will maintain your code will either curse you or thank you.
  • Coding does not equal programming – Writing code is not the same thing as software development, one requires thought while the other does not. Just like playing with your iPod does not make you a musician.
  • Code is about learning – Moore’s Law states that technology doubles every 18 months, you should keep up. If you are not learning you are doing it wrong. Every project is an opportunity to learn.
  • Code is communication – People will read the code you write. Use best practices and common design patterns and idioms. Strive for simplicity over impressing the monkey on your back. Your code should communicate clearly and concisely it’s intent. Code talks, bugs walks!
  • It is not the tools that make a developer – Know your tools and use them to their full power but don’t use them as a crutch! Switching between IDEs should not stop you on your tracks because you can’t find the correct code generation wizard. Michelangelo was a great artist with nothing more than a chisel and a slab of marble.
  • Don’t trust your code – Trust in your coding abilities does not replace repeatable testing. Don’t trust your code, assumptions, or users.
  • Code is not written in Latin – Code is not dead once the application ships. Code is always refactored, modified, re-used, and evolving. Your greatest strength is not writing mountains of new lines of code but maintaining, refactoring, and herding existing code into performing business requirements as per an agreed specification.
  • Respect the API – Your API is a contract others will depend on. Keep the API clean and explicit! The least amount of methods you expose is less testing and maintenance and documentation that you need to maintain.
  • Code outlives its intention – As much as you would like, writing your application from scratch in the latest programming language or framework will not benefit the number of end users that for one reason or another are stuck with the current version of the software. Code can outlive it’s original intention, design for extensibility and adaptability.
  • Code means different things to different people – In the end, to end users code simply means the ability to do what they expect.

May 5 2009

Top JavaScript and Web Performance Presentations on Google Tech Talks

Google has a YouTube channel with over 1000++ videos of presentations on a large number of programming and software development topics. Here are the top videos recently released in the Google Tech Talks channel regarding JavaScript and web performance that every web developer should see.

  • JavaScript: The Good Parts / Douglas Crockford – In JavaScript there is a beautiful, highly expressive language that is buried under a steaming pile of good intentions and blunders. The best nature of JavaScript was so effectively hidden that for many years the prevailing opinion of JavaScript was that it was an unsightly, incompetent abomination. This session will expose the goodness in JavaScript, an outstanding dynamic programming language.
  • Drop-in JavaScript Performance / John Resig – Browsers are continually upgrading – providing new features from the latest specifications. We’ll look at modern JavaScript and DOM techniques that you can easily drop in to your applications for instant speed-ups.
  • Best Practices in Javascript Library Design / John Resig – This talk explores all the techniques used to build a robust, reusable, cross-platform JavaScript Library such as jQuery.
  • High Performance Web Sites and YSlow / Steve Souders – Yahoo!’s Exceptional Performance Team has identified 14 best practices for making web pages faster. These best practices have proven to reduce response times of Yahoo! properties by 25-50%.
  • Life’s Too Short – Write Fast Code / Steve Souders – Techniques to help yoru web site perform better are discussed such as coupling asynchronous scripts, use iframes sparingly, and flush the document early.
  • Debugging and Testing the Web with Firebug / Rob Campbell – In this talk we explore web development and debugging strategies with Firebug. An overview of new and improved features and how to use them is presented. We wrap-up with a peek at FireUnit, a new Firebug extension by John Resig and Jan Odvarko, and it’s role in unittesting Firebug itself.
  • Faster HTML and CSS: Layout Engine Internals for Web Developers / David Baron – How fast Web pages load and how fast they change dynamically depends on both the Web page and the browser it’s running in. Browser makers put significant effort into making their browsers faster, but there are also things that Web page authors can do to make their pages more responsive.
  • jQuery / Dmitri Gaskin – jQuery is a JavaScript library that stands out among its competitors because it is faster, focuses on writing less code, and is very extensible.

May 4 2009

TechConf

Techies don’t get much sun as it is and to avoid direct exposure with sunlight many of technology conferences are scheduled around May and June. Most tech conferences cluster around the early summer months but there are other great technology and programming conferences held around the year and the country. Below is a tentative schedule of important software and programming related conferences. And don’t worry, if you missed or can’t make it out to your favorite conference this year, they are usually scheduled at about the same time each year.


May 3 2009

The Rubyist: April 2009 Edition

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

Ruby – Earlier in the month the hot topic in the Ruby community involved Twitter and their use of Scala for some back-end processes. Just suggesting that Ruby, and in particular Rails does not scale starts the debate all over again. This time Dave Thomas chipped in with a defense for Twitter’s right to choose the right tool for the right job. Other highlights are the NetBeans’ support of Ruby 1.9 and MountainWest RubyConf 2009 videos.

Rails – A favorite post this month regarding Rails was an article from Chad Fowler and a list he compiled of 20 Ruby on Rails development no-no’s. Chad gather much of the material for the article from fellow Rubyists via Twitter. Also of interest was the Ruby on Rails template for creating Twitter applications.

JRuby – Google recently released Java support for Google App Engine, this means that there has been a lot of activity around JRuby on Rails on App Engine.

GoGaRuCouchDeBate – Scalability is not the only stigma in the Ruby community. The other hot button has been the brash attitude and behavior of certain key members in the community. This all came to boiling point, yet again, at Golden Gate RubyConf when Matt Aimonetti gave a presentation entitled CouchDB: Perform Like a Pornstar. The subject matter of the presentation was overshadows by the images of scantily clad women, then the allegations of male chauvinism amongst the rank and file in the Ruby and Rails community. The way recent Ruby conference have been shaping up, I think RailsConf 2009 in Las Vegas will have strippers giving presentations on cache girth and performance.


May 1 2009

Retweet April 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

  • The way recent Ruby conference have been shaping up, I think RailsConf 2009 will have strippers giving presentations on cache girth and performance.
  • What is it that you enjoy about programming? Is it the language, the libraries, the framework, the tools, or the community?
  • What is your favorite code editor? On Windows I use Eclipse and NetBeans. On OS X I use Aptana and Komodo Edit.
  • There are many self proclaimed programming laws, my law states: Any hack that can name a law after himself should be arrested under that law.
  • I just heard a new variation to the infamous developer excuse ‘It works on my computer.’ Just heard, ‘I’ve never tried it on that computer.’
  • I think software bugs like wild animals can smell fear!
  • Herding bugs and bytecode!
  • I would like to use a Eclipse plugin that is a Twitter client.
  • JavaScript + jQuery UI + Google Gears + Twitter API = Yet Another Twitter Client! Juixe Tweetbox
  • I don’t have a golden hammer, I have a golden jackhammer and when that is not enough I bring out the golden bulldozer!
  • Alas, hacks make the world turn.
  • Hacking away at a hack. I that like a compound hack?
  • Is Scala the new Ruby? Is Scala the new Scheme?
  • Some people like texting, others sexting, I like hexting.

Continue reading