Bye, ternary?!

In this post I want to talk about something unthinkable. Namely – is the usage of the ternary operator in our connectors poisonous for our partners? Okay, I hear voices in my head now. They whisper “terna-what” operator?

This one: something ? result1 : result2

And now especially for those who hate (my) lame style:

ternary operation is an n-ary operation with n = 3

Now the voices whisper something totally different: “This guy went completely nuts…”. Surely this is close to reality but give me a chance to explain what I mean.

Our partners often do not have the source code of our payment connectors. So they play one of the oldest and dirtiest IT games:

  1. Decompile
  2. Modify
  3. Recompile

Yes! I love this game (as a hobby though)! But this is off-topic. Back to the question – here is a piece of code that I put in many of our connectors:

public String getMoneyToDivertToMyAccount(String customerCareful) {
    String sum = customerCareful.equals("yes") ? "1 cent" : (new StringBuilder()).append("10 USD").toString();
    return sum;
}

And here is what one of the popular java decompilers thinks about it:

image2016-2-18 22-17-4

I don’t want to discuss bytecodes here. Not yet. I just want to mention that we got an escalation that says that there is an error in “class XYZ” in one of our connectors. In an informal chat our partner buddies easily made me believe in their theory because they decompiled our class in front of my eyes. After half a day of investigations and many days of oblivion this post was born.

So… it may sound ridiculous… but it might sound wise to say “Goodbye, ternary!”. But I won’t. Will you?

Bye, ternary?!
Tagged on: