Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. if and if not do it anyway

if and if not do it anyway

Scheduled Pinned Locked Moved The Weird and The Wonderful
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TorstenH
    wrote on last edited by
    #1

    // ask for property
    final boolean bKVSatzInklSonderbeitragProperty = getModulContext().isKVSatzInklSonderbeitrag();
    // get same property from another point in code
    final boolean bKVSatzInklSonderbeitrag = m_oKV_SatzInklSonderbeitrag.isTrue();

    // try to figure out this!
    if(!(bKVSatzInklSonderbeitragProperty && bKVSatzInklSonderbeitrag
    || !bKVSatzInklSonderbeitragProperty && !bKVSatzInklSonderbeitrag)) {
    if(bKVSatzInklSonderbeitragProperty) {
    m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() + 0.9);
    }
    else {
    m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() - 0.9);
    }
    }
    return m_oKVSatzNeu;

    I never finish anyth...

    K D R 3 Replies Last reply
    0
    • T TorstenH

      // ask for property
      final boolean bKVSatzInklSonderbeitragProperty = getModulContext().isKVSatzInklSonderbeitrag();
      // get same property from another point in code
      final boolean bKVSatzInklSonderbeitrag = m_oKV_SatzInklSonderbeitrag.isTrue();

      // try to figure out this!
      if(!(bKVSatzInklSonderbeitragProperty && bKVSatzInklSonderbeitrag
      || !bKVSatzInklSonderbeitragProperty && !bKVSatzInklSonderbeitrag)) {
      if(bKVSatzInklSonderbeitragProperty) {
      m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() + 0.9);
      }
      else {
      m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() - 0.9);
      }
      }
      return m_oKVSatzNeu;

      I never finish anyth...

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      i like more: if( bKVSatzInklSonderbeitragProperty != bKVSatzInklSonderbeitrag ) { double dSatz = m_oKVSatzNeu.getDouble(); if(bKVSatzInklSonderbeitragProperty) { dSatz += 0.9; } else { dSatz -= 0.9; } m_oKVSatzNeu.setDouble( dSatz ); } it can only happen here :(( :(( :((

      Press F1 for help or google it. Greetings from Germany

      L 1 Reply Last reply
      0
      • T TorstenH

        // ask for property
        final boolean bKVSatzInklSonderbeitragProperty = getModulContext().isKVSatzInklSonderbeitrag();
        // get same property from another point in code
        final boolean bKVSatzInklSonderbeitrag = m_oKV_SatzInklSonderbeitrag.isTrue();

        // try to figure out this!
        if(!(bKVSatzInklSonderbeitragProperty && bKVSatzInklSonderbeitrag
        || !bKVSatzInklSonderbeitragProperty && !bKVSatzInklSonderbeitrag)) {
        if(bKVSatzInklSonderbeitragProperty) {
        m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() + 0.9);
        }
        else {
        m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() - 0.9);
        }
        }
        return m_oKVSatzNeu;

        I never finish anyth...

        D Offline
        D Offline
        David Skelly
        wrote on last edited by
        #3

        I think he's trying to do an exclusive or. If I'm interpreting that right, it boils down to:

        NOT (both true OR both false)

        T 1 Reply Last reply
        0
        • D David Skelly

          I think he's trying to do an exclusive or. If I'm interpreting that right, it boils down to:

          NOT (both true OR both false)

          T Offline
          T Offline
          TorstenH
          wrote on last edited by
          #4

          yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.

          I never finish anyth...

          P S 2 Replies Last reply
          0
          • T TorstenH

            yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.

            I never finish anyth...

            P Offline
            P Offline
            PanchoM
            wrote on last edited by
            #5

            I agree with KarstenK it boils down to: if(A!=B) { if(A) {//do stuff} else {// do something else} }

            1 Reply Last reply
            0
            • T TorstenH

              yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.

              I never finish anyth...

              S Offline
              S Offline
              supercat9
              wrote on last edited by
              #6

              TorstenH. wrote:

              yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.

              It looks like he's comparing two similarly-named but different properties (bKVSatzInklSonderbeitragProperty and bKVSatzInklSonderbeitrag). The code is redundant in that it would be more efficient to say:

              if (a && !b)
              action1();
              else if (b && !a)
              action2();

              than to say

              if (!!(a) != !!(b))
              {
              if (a)
              action1();
              else
              action2();
              }

              which is what the latter effectively does. On the other hand, the latter formulation would allow code to be executed before or after action1/action2 any time either was executed (e.g. if action1 or action2 set a visual property for a control, one could use common code to force a refresh).

              T 1 Reply Last reply
              0
              • K KarstenK

                i like more: if( bKVSatzInklSonderbeitragProperty != bKVSatzInklSonderbeitrag ) { double dSatz = m_oKVSatzNeu.getDouble(); if(bKVSatzInklSonderbeitragProperty) { dSatz += 0.9; } else { dSatz -= 0.9; } m_oKVSatzNeu.setDouble( dSatz ); } it can only happen here :(( :(( :((

                Press F1 for help or google it. Greetings from Germany

                L Offline
                L Offline
                Lutoslaw
                wrote on last edited by
                #7

                Or even:

                if (bKVSatzInklSonderbeitragProperty ^ bKVSatzInklSonderbeitrag)
                {
                double dSatz = m_oKVSatzNeu.getDouble();
                dSatz += 0.9; // teez my smart optimization
                if (bKVSatzInklSonderbeitrag)
                dSatz -= 1.8;

                m_oKVSatzNeu.setDouble( dSatz );
                }
                else
                throw ArgumentException("Ha ha, see how smart my validation code is, eh?");

                Greetings - Jacek

                1 Reply Last reply
                0
                • S supercat9

                  TorstenH. wrote:

                  yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.

                  It looks like he's comparing two similarly-named but different properties (bKVSatzInklSonderbeitragProperty and bKVSatzInklSonderbeitrag). The code is redundant in that it would be more efficient to say:

                  if (a && !b)
                  action1();
                  else if (b && !a)
                  action2();

                  than to say

                  if (!!(a) != !!(b))
                  {
                  if (a)
                  action1();
                  else
                  action2();
                  }

                  which is what the latter effectively does. On the other hand, the latter formulation would allow code to be executed before or after action1/action2 any time either was executed (e.g. if action1 or action2 set a visual property for a control, one could use common code to force a refresh).

                  T Offline
                  T Offline
                  TorstenH
                  wrote on last edited by
                  #8

                  nop, it was the exact same boolean, read from an property-file. He just needed to name it different due to some strange java code convention :^) :omg: so in this case it comes to:

                  if(!(bConditiontrue && bConditiontrue || bConditionfalse && bConditionfalse)) {
                  if(bConditiontrue) {
                  doSomething();
                  }
                  else {
                  doOpposite();
                  }
                  }

                  or simpler:

                  if (bConditiontrue) dosomething();

                  I never finish anyth...

                  S 1 Reply Last reply
                  0
                  • T TorstenH

                    nop, it was the exact same boolean, read from an property-file. He just needed to name it different due to some strange java code convention :^) :omg: so in this case it comes to:

                    if(!(bConditiontrue && bConditiontrue || bConditionfalse && bConditionfalse)) {
                    if(bConditiontrue) {
                    doSomething();
                    }
                    else {
                    doOpposite();
                    }
                    }

                    or simpler:

                    if (bConditiontrue) dosomething();

                    I never finish anyth...

                    S Offline
                    S Offline
                    supercat9
                    wrote on last edited by
                    #9

                    nop, it was the exact same boolean, read from an property-file.

                    One of them seems to have been accessed via getModulContext(), and the other one not, so I don't see that it's obvious from the code snippet posted that they would always return the same thing (both with the code as it is, and with adaptations that might occur to various other parts of the code).

                    1 Reply Last reply
                    0
                    • T TorstenH

                      // ask for property
                      final boolean bKVSatzInklSonderbeitragProperty = getModulContext().isKVSatzInklSonderbeitrag();
                      // get same property from another point in code
                      final boolean bKVSatzInklSonderbeitrag = m_oKV_SatzInklSonderbeitrag.isTrue();

                      // try to figure out this!
                      if(!(bKVSatzInklSonderbeitragProperty && bKVSatzInklSonderbeitrag
                      || !bKVSatzInklSonderbeitragProperty && !bKVSatzInklSonderbeitrag)) {
                      if(bKVSatzInklSonderbeitragProperty) {
                      m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() + 0.9);
                      }
                      else {
                      m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() - 0.9);
                      }
                      }
                      return m_oKVSatzNeu;

                      I never finish anyth...

                      R Offline
                      R Offline
                      RichardM1
                      wrote on last edited by
                      #10

                      I tell people and tell people and tell people to use parens and not assume people know operator precedence. People tell me I'm stupid. I choose to believe they mean for saying use parens. Walk through it and change the values in the debugger and make a state table. I also go with the XOR interpretation.

                      Opacity, the new Transparency.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups