general
Quickest way for a one-off XML sort – OR – Learning to keep the heavy tools in the shed
Jan 15th
What’s the quickest way/tool to sort a 1000 entries xml file?
Your requirements: The xml is parked on your desktop. You only need to sort it just once so you can manually examine it. Sort by the tag “relevance:score”.
How would you go about it? Would you:
A) Craft a pipe stream of shell utils?
B) Use the heavy tools – a Java main() that with uses JDom?
C) Refresh the XSLT skills you never had?
D) Try your luck with a Python script?
E) search for an online XML editor tool?
F) Or, my pick at the bottom.
Example xml document to sort:
<feed> <entry> <title>Bibi</title> <score>0.21000001</score> </entry> <entry> <title>Lapid</title> <score>0.42000002</score> </entry> <entry> <title>Yechimovich</title> <score>0.235</score> </entry> <!--- 997 more entries --> </feed>
My Pick: considered all the above but it sounded like a headache for a simple sort operation. So I’ve …. thrown the file at MS Excel, turns out it can digest it rather well, and then I sorted by the score column. Yes! Surprising. But crappy MS Excel did the job (the original schema had more nesting than the document in the example above).
Life-saver lesson: Spend time picking the right tool for the job, than on the job itself.

One click to sort
Specifing arrays size/capacity – my latest buggy code and a best practice
Dec 5th
We’re often required to specify size/capacity when allocating array like structures.
While you MUST specify size for Java’s primitive arrays. With realizable arrays like ArrayList/Vector, specifying #capacity is too often a #premature-optimization, that you could avoid.
I happened to introduce a bug to our code base, by initialized an ArrayList with a negative capacity value:
List<RetrievedDocument> docs = new ArrayList<RetrievedDocument>(scoreDocs.length - resultsOffset);
Performing such profanity results in an #IAE being thrown (triggered by a NegativeArraySizeException thrown by the underlying primitive array structure.
public ArrayList(int capacity) {
firstIndex = lastIndex = 0;
try {
array = newElementArray(capacity);
} catch (NegativeArraySizeException e) {
throw new IllegalArgumentException();
}
}
Lesson for the next 50 years (or until I switch off from Java):
Whenever setting the size of an array (or anything sizable) to an unknown ahead value, spend a second to consider whether the value could be negative.
Then, if the desired resulting behavior is to create a zero-sized array instead, use this one-liner for that:
new ArrayList( Math.max(0, possiblyNegativeCapacity) );
Q: Do you know if other languages makes the use case above easier/less error prone?
Q: Any other related best practices and pitfalls you would like to share?
Cleaner code with Apache Commons
Aug 26th
It seems I can no longer write any piece of code without including the Apache Commons libraries.
They just contain everything that the ancient architects of the Java language forgot to include in the java.* APIs; Commons save huge amounts of coding debugging time, by capturing ever repeating patterns, allowing effective reuse which results helps with clean code.
More >
HPEL – A fast binary logging for WebSphere v8
Nov 29th
Troubleshooting Java EE apps running on WebSphere just got a bit easier with WebSphere v8′s new binary logging and tracing mechanism: HPEL (High Performance Extensible Logging).
HPEL provides logging/tracing run-time performance boost (x3.5-x5 claimed) increasing the chances that you’ll be able to turn on tracing on a production system.
HPEL comes with two offline viewing tools: A crafty command-line tool for log analysis, and a web based traces viewer on the Web admin console (handy for remote servers).
The command line utility has a tail function and can filter by: Logger/Thread ID/Time/Server startup instance/etc. Which is a good enough reason for me to get rid of my (slow performing) custom Python based filtering scripts.
Good old legacy text based logs are still supported but are recommended for development mode only.
10 things I like about Android development
Apr 5th
- Java – Write in Java on both the Client and Server sides. Simplifies development and presents a low learning curve for newcomers.
- Paid apps culture - Unlike when using web apps, mobile app users we’re tamed to pay for the apps they like (Thank you Apple for cracking the ice). Developing for Android might be the first time that you’ll sell a piece of software directly to your users (it is my first time, and I’ve been programming since 1996).
- TTD – When creating a new Android Eclipse project it auto suggest to create matching test project. Proves to show that the Eclipse perspective designer had TTD in mind.
- API Demos – Good samples project to copy code segments from. Bundled with the SDK.
- No single point of entry - No single main() function. Your application can have multiple entry points (Activities), which can be used to service the user’s Intents. Different from what I’m used to.
- Construct UI using XML - specifying UI elements using a markup language makes more sense than doing it programmatically (attention Swing).
- Multiple App markets – More choices for us developers.
- Coping with multiple device resolutions – using density independent pixels worked well for my modest needs.
- App Inventor - Ridiculously easy to build your first app. Go try it.
- What’s your 10th? Comment if you have one.
My first App:
My first app is the Weight Watchers Points Tracker (diet related), that I’ve initially created for my own usage, then later posted to the Android Market. Surprisingly it has been doing pretty good (>10K installations). I’ll need to see what comes next…
Spice up your tests – execute in (repeatable) random order
Mar 25th
We have a series of SIPp tests that periodically runs against a SIP server we develop. The tests repository keeps on growing and we’ve gathered up a nice pile of tests.
As good tests should be isolated from one another, their order of execution is arbitrary by definition. The tests should produce the same results consistently regardless of where they are located in the execution chain. I thought I might take this to the test, and perhaps find a bug or two along the way.
Working in Python, I now simply shuffle the list of tests prior to execution:
random.shuffle(testList)
executor.exec(testList)
Nice. Now what happens if a certain execution order fails? I would find the issue and fix it, what else?! Right, but how will I reproduce the same exact execution order that failed before, in order to validate the fix?
One naive option is saving the entire execution order as a list of indices, this is not very comfortable. A simpler option is to simply seed your random object with the same seed int value used during the execution to reproduce. Here’s the code:
import random
seedValue = options.get('shuffleSeed', random.randint(0, 10000)) # Seed is provided by the user in an attempt to reproduce, otherwise it's set to some random value.
random.seed(seedValue)
random.shuffle(testList)
print 'Shuffled with seed=' + str(seedValue)
executor.exec(testList)
Software development podcast in Hebrew
Mar 24th
Having recommended podcasts before, I now want to recommend Ran Tavori’s and Ori Lahav’s great (in Hebrew) software development podcast: רברס עם פלטפורמה.
Some of my favorite episodes include:
50. Content acceleration and CDNs
42. Garbage Collection (including myself with a guest appearance)
39. Designing products for the military
22. Internet products and usability in general
10. SundaySky real-time video generation
8. think twice before you debug instead of trace
If you know any other good software development podcasts in Hebrew, please comment here to let me and the world know.
New Java blog out there
Jan 4th
A new baby blog was born: Java Tech Sharing.
Proud father: Guy Moshkovich.
Google is pregnant again – Noop
Oct 5th
After the zillion new dynamic languages that had flooded the earth
(groovy, ruby, …), Google is concocting Noop; a new type-safe language to join Java, Scala, and the rest.
The new language sets out to excel in testability, dependency injection, and readable code (see the proposed features). More interesting than whether Noop will gain a crowd of enthusiasts, is the language’s dynamic and lucid development process; made available through Google code (Sun’s JSRs, are also transparent but here it’s a whole new language).
What do you think?





Via e-mail