Java Jokes

So I ran across a snippet of code today in a Java codebase:

additionalCommands.add(new XYZAdminClientMenuItemAdditionalCommand(START_COMMAND, "Start Cluster"));
additionalCommands.add(new XYZAdminClientMenuItemAdditionalCommand(STOP_COMMAND,  "Stop Cluster"));
additionalCommands.add(new XYZAdminClientMenuItemAdditionalCommand(MON_COMMAND, "Start Monitor the Cluster"));

which, to any Python programmer looks like someone is pulling your leg.

Here's a Java version that doesn't seem quite so crazy to a Python programmer:

protected static String[][] menu_items = {
{START_COMMAND, "Start Cluster"},
{STOP_COMMAND, "Stop Cluster"},
{MON_COMMAND, "Start Monitor the Cluster"}
};

And you can then iterate with a simple for-each loop like so:

for (String[] item: menu_items) {
    System.out.println( item[0] );
    System.out.println( item[1] );
}

I know that Java teachers tell you to turn everything into a named type, but stop pulling my leg, it already hurts.

Comments

Comments are closed.

Pingbacks

Pingbacks are closed.