IE rendering engine

I just know that IE is a pain to deal with. I assumed that IE9 would be better at doing certain things and be more standard it is way to render web pages. I learned from that mistake.

We have an application that can list all items tracked in a table. The convenience is for users to quickly do global searches or to import this data in excel to do the manipulation they need.

When the table reached 1500 elements I received emails asking me what I changed to make it so slow in IE.

After some testing I realized that IE was rendering that web page in “quirks mode” which is not very efficient with large table.

After looking for a few minutes on Google I found an MSDN article talking about adding this header to tell IE to use the latest rendering engine for this page:

It is now applied across the site and IE9 performs fine but IE8 still shows some signs of slowness. Maybe more a computer issue that an IE issue but I can’t verify.

During my search on this IE issue I certainly came across a fair amount of displeased programmer with how IE does things (even in newer version) and I can see why. Hopefully I won’t be bitten too often.

Java Performance when you go through an entire list of elements

This week I was told that my way of going through each elements in an ArrayList was not the most efficient. I should be using an Iterator.

No reason to doubt an experienced programmer so I changed my code.

I never trusted anyone when I did troubleshooting before. I always need to see the evidence for myself. So I decided to do this code to check the validity of the data I was given:

/**
 * Testing the performance of different ways to go through a list of items
 */
package com.cinq.test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @author mc
 * @version 0.1.0
 *
 * last updated on 2011-11-27
 *  initial release of these tests
 */
public class Performance {

    /**
     * @param args
     */
    public static void main(String[] args) {

        long dstart = 0;
        long dend = 0;

        // Allocate an ArrayList
        ArrayList<String> data1 = new ArrayList<String>();
        ArrayList<String> data2 = new ArrayList<String>();
        for ( int i = 0; i < 10000; i++ ) {
            data1.add("abc" + String.valueOf(i));
            data2.add("xyz" + String.valueOf(i));
        }

        // Start going through all the elements with a get index method
        dstart = System.currentTimeMillis();
        for ( int j = 0; j < data1.size(); j++ ) {
            data1.get(j);
            for ( int k = 0 ; k < data2.size(); k++) {
                data2.get(k);
            }
        }
        dend = System.currentTimeMillis();

        System.out.println("Get Index for " + data1.size() + " by " + data2.size() + " elements took " + (dend - dstart) + " ms.");

        dstart = System.currentTimeMillis();
        for ( String s1 : data1 ) {
            for ( String s2 : data2 ) {
                // nothing
            }
        }
        dend = System.currentTimeMillis();

        System.out.println("For each for " + data1.size() + " by " + data2.size() + " elements took " + (dend - dstart) + " ms.");

        dstart = System.currentTimeMillis();
        Iterator<String> it1 = data1.iterator();
        try {
            while ( it1.next() != null ) {
                try {
                    Iterator<String> it2 = data2.iterator();
                    while ( it2.next() != null ) {
                        //nothing
                    }
                } catch ( NoSuchElementException e0 ) {
                    //ignore
                }
            }
        } catch ( NoSuchElementException e1 ) {
            // ignore
        }
        dend = System.currentTimeMillis();

        System.out.println("Iterator for " + data1.size() + " by " + data2.size() + " elements took " + (dend - dstart) + " ms.");
    }

}

The output I get from this is:

Get Index for 10000 by 10000 elements took 12 ms.
For each for 10000 by 10000 elements took 271 ms.
Iterator for 10000 by 10000 elements took 166 ms.

This makes no sense. I should see the performance of the Iterator way of doing things to be faster than my get(index) way. I will have to ask my co-worker tomorrow why I am getting this bad performance. Conclusion to follow in the next few days.

Basic: Java return code or throwing exceptions

Sometimes you have this basic question that you  are too shy to ask around because you should know. Reality is that I always have a few of those and eventually you have to look around for what others are doing if you want to get better.

I just completed some code and I was wondering if using the return code for errors was a good idea or if I should have used exceptions everywhere.

After reading a few articles I think that I did the right thing.

One key sentence that I like is: exceptions are for exceptional conditions. So you should see an exception if the failure is not expected and abnormal to the working of your application. A good point.

Others are saying that you should crash loudly. They are saying to use exceptions as much as possible so that it gets your attention and you fix the issue sooner than later.

The argument that return code makes the application more stable seems to be a bit simplistic because you might be hiding issues that will be more difficult to identify later.

There is room for both approach and I think that experience tells you what to do. Always using one or the other does not seem to make sense. Balance.

Return code makes sense right now because this Java code needs to integrate with some Bash code. If the solution was purely Java I think that I would need to change this strategy.

I may start using more checked exceptions since it gives me a better sense of balance and allows to have more information about the failure.

Continuous improvements.

GrepCode

I was searching on how to use some library in my Java code and I came across the GrepCode.com site.

It was great help to find the documentation/code for the library I was using. They only claim to have index for Java, JBoss and Eclipse but the F5 library was there as well.

I installed the Eclipse plugin because that could save some time when searching why I am getting a certain error or why some code is not working as expected.

You find new things every day.

Java 7 Optimization

I have not started to use Java 7 but I have started to read on the differences. This is a great blog post to learn a few new tricks to optimize the JVM:

http://marxsoftware.blogspot.com/2011/10/javaone-2011-definitive-set-of-hotspot.html

It is also funny that the small, almost irrelevant, option is the one that will relieve a serious pain for me:

-XX:+PrintGCDataStamps If this works as I expect we will be able to read GC logs and easily figure out when events have happened

How to be an exceptional programmer

It is funny that sometimes I read an article about a totally different subject but I replace the words and it apply to my aspiration of being a programmer:

How to be an exception photographer

This article highlights the fact that you need to focus on something you like and you are good at. You keep working on it and you become better. This is the way to plan your future compared to trying to being good at everything which will fail you sooner than later.

I have read enough of these articles to know these simple principles. What they also admit in the article is that it is not always easy to find where you are and where you should go. They have a few questions that you should ask yourself and answer honestly to be able to find where you want to go.

They key to success is having a realistic plan and actioning it. Keep working at it. Wishing for results is not enough.

Annoying to see moving text when you are reading

I am sure this is an error in a UX design that too many are not even aware they need to correct.

If I am reading some text on your page (more than 2-3 sentences) I can’t have this feed constantly moving on the left or right of the text I want to read. I can’t focus if something is moving non-stop so close to where I need to focus.

Like audio can be muted on many sites there should be a “stop the feed” icon/button next to this annoyance.

Am I alone complaining about this?

Java Debugger That Really Helps You – Chronon

Wow.

This new type of debugger is something on its own.

It allows you to record your application executing and then replaying it has you need to figure out where the errors are. You simply need to watch their video to get the “wow” factor right away.

It simplifies the code you have to do and gives you a better insight in your application.

I am quite curious to know how it would work on JBoss servers running multiple apps.

http://www.chrononsystems.com/

Continuous Deployment – so much to learn

I have a lot to learn about the pattern and how to be effective at doing continuous delivery of a web app. This presentation is giving a few hints on what you need to be successful:

  1. Monitoring
  2. Testing
  3. Remediation

The monitoring portion is more than just availability. You need to be able to detect any failure quite rapidly otherwise you won’t know to which release to rollback or what to remediate. Monitoring your logs is probably the next thing I need to implement and see how good I can get this. Jez Humble talks about monitoring revenue and it is a great idea for real businesses, it just does not apply to my web app. You can monitor the number of transactions or logins instead of revenue but I will keep that as my next step. Logs first.

Testing, I have a clue on what needs to get done but the cascading of the different type of testing was not something I had in mind until I listened to this presentation. Unit testing is the first step to what needs to get done and I knew that but the next few steps are a bit more clear now.

The remediation pattern that were shown are good ones. Failure does not mean a full code rollback. You can deploy features and turn them on later. I especially liked his Facebook example where the code was there and user loging in were making calls to the back-end without knowing it. This allowed the team to see how the code/app would behave under a more realistic load. That is clever.

Now I have to write down how this is going to change my architecture for this web app. It certainly will improve the plan.

Spring Roo bug for beginners

I did not have this issue on my macbook air but on the iMac I faced a problem when trying to build and deploy my demo app.

I would get errors like this:

[WARNING] The POM for javax.servlet:jstl:jar:1.2 is missing, no dependency information available

Took a few Google searches to find an article that recommended to replace this section:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

With this:

<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>

As soon as I saved the modified pom.xml it downloaded the dependencies and the new “perform package” produced a working app on the tc server.

Next: more advanced demo app and then something of my own.