We serve our clients as integrated, strategic business partners by planning, designing, and building innovative software solutions that help businesses run more efficiently and realize their full potential.

Thursday, December 26, 2013

Software development: It’s not the code you write, but how you write the code that makes all the difference…


When it comes to programming, there typically is no one “right” way to write code. Every developer, depending on his or her education, background, experience etc. writes code differently. In the programming realm (just like in real life), there are many ways to say or write the same thing; some are more efficient, while others are more intuitive and easier to understand.

Lots applications are written using code extracted from text books. Fortunately or unfortunately (depending on who you are--human or machine); text books are written primarily so people can easily follow and grasp concepts-they are not typically written with performance in mind. Very little thought, if any, is given to alternative methods of writing code and how to make it more efficient.

For example, while it seems that current browsers continue to optimize their JavaScript engines for basic operations, how the code is written can directly impact the performance, capability, scalability and end-user experience of any application. Let's analyze a simple JavaScript loop. The purpose is to iterate through a simple array or list of items using different approaches. Notice the differences in the performance of each browser:

IE 11

Firefox 25.0.1


Google Chrome 31.0.1


As you can see, each loop implementation serves exactly the same purpose. However, there are quantifiable variations in performance.  All browsers have strengths and weaknesses. The browser must be taken under consideration when writing code. For example, while Chrome may be optimized to perform loop operations more efficiently as compared to IE; it does not perform as well when invoking functions. This explains why Chrome, in this specific example, is the slowest one when using JQuery approach.

A few other things to consider…

It's important to consider the environment (Operating system, Hardware, etc.) where your code will be executed. Equally important is to benchmark the environment where the code will be running. This will allow you to develop adaptive code that is optimized regardless of the environment.

What can I do with this information? That depends on you. You can try to convince your company into switching to a different browser. Cross your fingers and quietly hope that your application is not using code that runs slowly or that makes the application unusable.

Or…..

A better idea might be to set the goal of writing smarter, flexible and adaptive code that takes into account all of the different techniques and environments that are out there. It’s your call. So, whether you are a developer or hiring a developer, it always pays to THINK…DESIGN…BUILD before you start any project. A little R&D like this can go a long way to ensuring the overall success of your project.

We would like to thank jfPerf (http://jsperf.com/) for the use of their tool. jsPerf aims to provide an easy way to create and share test cases, comparing the performance of different JavaScript snippets by running benchmarks.

Here is the link to our test:



No comments:

Post a Comment