Warning! Strong JAVA radiation!
Lasu2String

18 December 2009

The logical-complement operator !

Maybe I'm weird but I really do not like syntax for this operator.

Now time it's like:

if (!person.getThinkingModel().isThinking()){...}

I would personally prefer:

if (person.getThinkingModel().!isThinking()){...}

I would do same about instanceof to allow:

if (obj !instanceof Person){...}

Work around:
Would be nice to see both methods generated isThinking() as well as isNotThinking() instead of one in that case. Problem in this solutions involve setters which should be duplicated as well, and mostly 'Not' version should call traditional with simple negation, which increases stack traces.

if (person.getThinkingModel().isNotThinking()){...}

This way have one more advantage. When you write in more than one language you can worry less about operators priority.

Use yours own judgement, which is easier to read and write.

3 comments:

  1. Hello

    This is hard to read because You use a train of get()...get()...get()... The situation will become even worse if You will use more get()...

    When You put ! in that chain it is easy to omit by someone who reads it (for me sometimes it may look like small letter L). Besides this construction is not natural: why draw outside some personel's object internal details just only to ask them about something more?

    Hide the logic inside personel object. I think personel object has (or should have) all required knowledge about "thinking" process. Create method isThinkingNow() inside personel object, and inside this metod do simple:
    return getThinkingModel().isThinking()

    Now Your code looks clear and is easy to understand:
    if(person.isThinkingNow())
    if (!person.isThinkingNow())

    ReplyDelete
  2. Anonymous is right...
    old Chinese wisdom says:

    If You think against Object Oriented (encapsulation in this case) paradigm than Your code stinks.

    ReplyDelete
  3. I never thought that someone my consider this as OO sample, while it's pure XML like.

    Any way, now I know where the problem is, so I'll rewrite this post.

    ReplyDelete