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-free codes

IF-free codes

Scheduled Pinned Locked Moved The Weird and The Wonderful
htmlcomtutorial
32 Posts 22 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.
  • G Gary Wheeler

    SarK0Y wrote:

    superfluous IFs make code slower.

    That isn't necessarily true. Modern processors use a variety of tricks that reduce the 'cost' of unused branches. One of the problems of 'computed conditional' logic is that you incur the cost for all cases, not just the unused branch. Your overall performance actually decreases.

    Software Zen: delete this;

    C Offline
    C Offline
    Chad3F
    wrote on last edited by
    #21

    Especially with moores law hitting the ceiling lately (until someone finds a trick to break through and go up another 100 floors). Can't make it go any faster -- so add more cores. Can't utilize all the cores -- so add more microcode parallelism. Soon they might end up having CPUs that can follow dozens and dozens of branch path pipelines at the same time (until it can prune unused ones). Of course, the information that can be saves during context switches may limit that technique. On a side note.. Some languages (like Smalltalk) don't actually use branching in "if"'s (well, their equivalent to an if).. what may seem a condition check/branch is really an expression returning a boolean object, and then when asked to _run_ the "ifTrue" conditional code block it either does, if it is a "true" object, or doesn't if a "false" object, without any checks/branching. And the same for the "ifFalse" (aka "else") code blocks, only reversed.

    1 Reply Last reply
    0
    • S SarK0Y

      Good Time to all, Amici(Friends). Here, i'd like to discuss how to reduce conditional branches in the code. 1st of the all, i would like to share some tricks. Their description is here. :-D ----------------------- Thanks in Advance for attention of Yours.

      M Offline
      M Offline
      Member 4608898
      wrote on last edited by
      #22

      The old IBM 360 JCL didn't have any if statements. In PERL, you'd normally see something like open ("fred") || die which translates to if (not open("fred")) then die If you look at the assembler, in both cases, it is exactly the same.

      1 Reply Last reply
      0
      • R RonDsz

        in OOP use duck typing as means to avoid using if's and case statement to invoke objects of different classes. [^]

        B Offline
        B Offline
        Brisingr Aerowing
        wrote on last edited by
        #23

        RonDsz wrote:

        duck typing

        Quack, Quack!

        Bob Dole

        The internet is a great way to get on the net.

        :doh: 2.0.82.7292 SP6a

        1 Reply Last reply
        0
        • S SarK0Y

          Good Time to all, Amici(Friends). Here, i'd like to discuss how to reduce conditional branches in the code. 1st of the all, i would like to share some tricks. Their description is here. :-D ----------------------- Thanks in Advance for attention of Yours.

          I Offline
          I Offline
          Ingo
          wrote on last edited by
          #24

          We had such discussion in the eighties when programmers wanted to be artists, writing unreadable code just to be irreplaceable. If you would be one of my programmers I would fire you immediately for this waste of money and time and delivering error-prone code. I thought those times were gone! X|

          ------------------------------ Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.

          S 2 Replies Last reply
          0
          • S SarK0Y

            Good Time to all, Amici(Friends). Here, i'd like to discuss how to reduce conditional branches in the code. 1st of the all, i would like to share some tricks. Their description is here. :-D ----------------------- Thanks in Advance for attention of Yours.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #25

            Without a doubt, that's the worst idea I've seen in a long time. Instead of using a nice, easy to read if, you've turned it into a very-expensive-to-support-and-debug piece of crap that you'd have to throw unit test after unit test at with a crap-ton of edges cases. Congratulations! Now go back and wipe that smiley face off your post before I smack it off.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            1 Reply Last reply
            0
            • 5 5urd

              Oh my gosh! A program with no if-else statements! Please don't make me learn assembly! Oh, wait - I already did...

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #26

              Yeah, there's some optimization for ya. Instead of typing a nice little two letter word like if, now you have to remember a ton of 3 letter "if" statements that all being with "J". ;)

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              1 Reply Last reply
              0
              • S SarK0Y

                yes, readability is worse :) but superfluous IFs make code slower. Actually, it will be extremely helpful, if new compilers shall be able to generate such blocks of IFs. :-D

                D Offline
                D Offline
                DarthDana
                wrote on last edited by
                #27

                Actually, modern compilers do a very good job of optimization. They've come a long way over the years. You probably won't see enough of a change to notice.

                1 Reply Last reply
                0
                • I Ingo

                  We had such discussion in the eighties when programmers wanted to be artists, writing unreadable code just to be irreplaceable. If you would be one of my programmers I would fire you immediately for this waste of money and time and delivering error-prone code. I thought those times were gone! X|

                  ------------------------------ Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.

                  S Offline
                  S Offline
                  SarK0Y
                  wrote on last edited by
                  #28

                  heh, i wasn't here for awhile

                  1 Reply Last reply
                  0
                  • I Ingo

                    We had such discussion in the eighties when programmers wanted to be artists, writing unreadable code just to be irreplaceable. If you would be one of my programmers I would fire you immediately for this waste of money and time and delivering error-prone code. I thought those times were gone! X|

                    ------------------------------ Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.

                    S Offline
                    S Offline
                    SarK0Y
                    wrote on last edited by
                    #29

                    heh, i wasn't here for awhile :) actually, ye're wrong on that: readable codes are good, only if you have no the needs of deep optimizations. deep optimization means vast asming. P.S. for fast sorting of floats, my if-reduced code http://sourceforge.net/projects/fsort--no-if/?source=navbar :)

                    I 1 Reply Last reply
                    0
                    • S SarK0Y

                      heh, i wasn't here for awhile :) actually, ye're wrong on that: readable codes are good, only if you have no the needs of deep optimizations. deep optimization means vast asming. P.S. for fast sorting of floats, my if-reduced code http://sourceforge.net/projects/fsort--no-if/?source=navbar :)

                      I Offline
                      I Offline
                      Ingo
                      wrote on last edited by
                      #30

                      SarK0Y wrote:

                      readable codes are good, only if you have no the needs of deep optimizations. deep optimization means vast asming.

                      Code can be both: Optimized and readable. It's just depends on the plannings. Cryptic code isn't any faster than good, optimized readable code. It's just harder to understand and correct. That's all.

                      SharePoint Consultant and Developer at acocon Author of Primary ROleplaying SysTem I'm the ninth in a row of seven!

                      S 1 Reply Last reply
                      0
                      • I Ingo

                        SarK0Y wrote:

                        readable codes are good, only if you have no the needs of deep optimizations. deep optimization means vast asming.

                        Code can be both: Optimized and readable. It's just depends on the plannings. Cryptic code isn't any faster than good, optimized readable code. It's just harder to understand and correct. That's all.

                        SharePoint Consultant and Developer at acocon Author of Primary ROleplaying SysTem I'm the ninth in a row of seven!

                        S Offline
                        S Offline
                        SarK0Y
                        wrote on last edited by
                        #31

                        Ingo, did you write asm codes ever???:D

                        I 1 Reply Last reply
                        0
                        • S SarK0Y

                          Ingo, did you write asm codes ever???:D

                          I Offline
                          I Offline
                          Ingo
                          wrote on last edited by
                          #32

                          SarK0Y wrote:

                          Ingo, did you write asm codes ever???

                          :laugh: Okay. I talked about higher languages. If you write asm codes, I won't mind if you code another way. :rolleyes:

                          SharePoint Consultant and Developer at acocon Author of Primary ROleplaying SysTem I'm the ninth in a row of seven!

                          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