Archive for March, 2006

Devgone

I wanted to continue with some of my diary entries which relate to programming. I don’t know what I was thinking when I wrote this one here dated the 8th of August of 2005:

A coworker moved on to greener code, before his last day we had a lot of knowledge transfer sessions. This guy was the process guy and a stickler for maintaining JUnit tests. During one of the knowledge transer sessions he said, “Testing saved my butt. I test often because I’m not that good of a developer.” I have to agree with his statement, testing saves your butt. Because he test so much he is a better developer. JUnit makes better developer out of us all. Do it early, do it often, like making love. If only sex had a green bar at the end to indicate your success! He also asked of all of us staying behind, “If you can’t write the unit test for the thing you are doing, how do you know what you are doing?” Again, like having sex! If you don’t have a JUnit for it, I don’t think you know what you are doing!

Technorati Tags: , , ,

Test Plenty

The following is from an entry in my diary dated back to June of 2005:

Test yourself before you wreck your. One of the interview questions asked during my interview for my current position was, “what do you do when adding a new feature?” I went on about understanding the specification, writing a use case, writing a test case, implementing the code and writing some unit tests. That is a text book answer that you don’t necessarily learn in school. Like comments, unit testing is one of those good habits that fall by the waste side when developers feel the crunch. At my new job you won’t believe the testing involved. The testing of a feature takes me longer than the implementation of said feature. In addition to JUnit our company has a proprietary testing harness that essentially tests the complete application including system correctness by replaying user experiences. We do so much testing that I proposed we adopt the motto, Leave No Test Behind. Sometimes my comments are twice as long as code. My testing takes me triple the time of development. But you need to remember that the life time of the software is four times what is expected.

MESA Day

Last Saturday I gladly volunteered as a web design judge for MESA day in San Jose State University. MESA stands for Math Engineering Science Achievement and is a program run throughout California to try to promote the sciences in socioeconomic disadvantaged communities.

For the web design contest, student where given a topic and 45 minutes to complete design a website with a minimum of three linked pages. Points were given for creativity, functionality, and content but most points were racked up by the different tags the students used. Points were handed out for using headers, relative links, absolute links, anchored links, style sheets, etc. After judging some of the web designs I could clearly see the influence of MySpace in some of the students work.

Select Top Candidate

Here is an interview questions that I have been asked. Given an employee table with a salary column, what SQL statement would give you the top five earning employees?

But before you select the SQL statement you have to select the database implementation. Here is how you might do it in Oracle:

SELECT name FROM employees WHERE ROWNUM < = 5;

In Microsoft SQL Server:

SELECT TOP 10 name FROM employees;

In MySQL:

SELECT name FROM employees LIMIT 10;

This is almost a trick question especially when the person asking the question might only know one of the many possible answers. Now, if the interviewer is reading the answer written along with the questions they might not understand that there is more than one way to do it. If they are asking questions where they don’t know the answer you might not want to work there, unless you are seriously strapped for cash. So remember, when you are looking for employment you should be looking for the top work environment.

Scale Resize Images

I recently had to look into the image scaling code that we employ in our application because of a known bug with the JDK. Here is the original code we used to resize image icons:

int hint = Image.SCALE_AREA_AVERAGING;
icon = new ImageIcon(original.getScaledInstance(w,h, hint));

As stated, the above code occasionally will throw a ClassCastException because of a bug with the JDK. The exception is thrown because of the use of the AreaAveragingScaleFilter class which is instantiated when you use the SCALE_AREA_AVERAGING hint. A work around for this problem is to use the Image.SCALE_REPLICATE hint but which produces images with jaggies.

You can use a different approach to creating image thumb nails as in the following code:

BufferedImage bi = new BufferedImage(w, h,
   BufferedImage.TYPE_INT_ARGB);
bi.getGraphics().drawImage(original, 0, 0, w, h, null);
icon = new ImageIcon(bi);

You can also scale, rotate, and shear an image using affine transformations. The following code resizes an image using the AffineTransform class.

AffineTransform tx = new AffineTransform();
tx.scale(scalew, scaleh);
AffineTransformOp op = new AffineTransformOp(tx,
   AffineTransformOp.TYPE_BILINEAR);
BufferedImage bi = op.filter(ogininal, null);
icon = new ImageIcon(bi);

Poor Man’s Profiling

Some time back I wrote about how OptimizeIt was useful in profiling our application. If you can’t afford OptimizeIt Java provides you an alternative poor man’s profiling tool in the Runtime class. The Runtime class allows you get the total heap size and the amount of available memory. Using these methods you can estimate how much memory you application is consuming with some simple math:

Runtime rt = Runtime.getRuntime();
long using = (rt.totalMemory() - rt.freeMemory()) / 1024;

Next Page »