Matthias sends us what he calls the "tern of the century". Which, before I share it with you: bad news, it's just a regular bad ternary. But it remains bad in interesting ways, so it's definitely worth talking about. But let's not oversell it.
private static String getOrderTypeCode(CreateOrderRequest order) {
return !StringUtils.isBlank(order.getOrderParams().getReceivingCompanyFoo()) && ORDR_TP_DQQ_FOO.equals(order.getOrderParams().getOrderType()) ? ORDR_TP_DQQ_BAR_CDE : order.GetOrderParams().getOrderType().getOrderTypeCode();
}
This function takes an order, and inspects it to figure out the type of order it represents. The logic is this: if the receiving company has the "foo" property set, and the order is already set to type "Foo", then we return the "bar" code (not a bar code- Matthias is using "foo" and "bar" as anonymous placeholders), otherwise we return whatever order type code that was set on the order type.
Now, I've left this all on one line, as it is in the codebase, which certainly helps with the WTF feeling of the whole thing. Protip: don't write ternaries that need to wrap across three lines to be readable.
This is messy and unreadable, but by ternary standards it's just regular bad. No, the thing that is driving me up the wall is the code-golfy constant names. ORDR is short for ORDER. CDE is CODE. I have no idea what TP or DQQ stand for. But I see no good reason to turn every constant into the name of some droid loitering around Jabba's Palace in Star Wars just to save a few keystrokes.
I'd be less bothered if the abbreviations were more cryptic, but just dropping a middle vowel from "ORDER" sits in this bizarre half-point between "exists as meaningless jargon, good luck" and "I wrote something readable". I'd be less annoyed if it were more of a WTF.
This post originally appeared on The Daily WTF.
