Thread: Can you convert this code to not use an IF statement?

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29
  1. #11  
    Registered Member
    Join Date
    Dec 2013
    Posts
    318
    Thanks given
    109
    Thanks received
    72
    Rep Power
    309
    Quote Originally Posted by Arham View Post
    You said without if-statements, not conditionals. Moreover, it isn't a statement, it's an expression.
    It's conditional on input but I've updated the thread!
    Reply With Quote  
     

  2. #12  
    (Official) Thanksgiver

    Arham's Avatar
    Join Date
    Jan 2013
    Age
    20
    Posts
    3,377
    Thanks given
    7,120
    Thanks received
    1,879
    Discord
    View profile
    Rep Power
    3454
    Code:
    Runnable[] runnables = {() -> handleHigh()};
    try {
        runnables[Math.min(0, index - 10)].run();
    } catch(Exception e) {
        handleLow();
    }
    Quote Originally Posted by MrClassic View Post
    Arham is the official thanker!
    List of my work [Only registered and activated users can see links. ]!
    Reply With Quote  
     

  3. #13  
    Registered Member
    Join Date
    Dec 2013
    Posts
    318
    Thanks given
    109
    Thanks received
    72
    Rep Power
    309
    Quote Originally Posted by Arham View Post
    Code:
    Runnable[] runnables = {() -> handleHigh()};
    try {
        runnables[Math.min(0, index - 10)].run();
    } catch(Exception e) {
        handleLow();
    }
    That works!
    Reply With Quote  
     

  4. #14  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Age
    28
    Posts
    2,549
    Thanks given
    192
    Thanks received
    761
    Discord
    View profile
    Rep Power
    1332
    Quote Originally Posted by Kiissmyswagb View Post
    That works!
    source openjdk: [Only registered and activated users can see links. ]
    Code:
        public static int min(int a, int b) {
            return (a <= b) ? a : b;
        }
    Basically just an IF...
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  5. #15  
    Registered Member
    Join Date
    Dec 2013
    Posts
    318
    Thanks given
    109
    Thanks received
    72
    Rep Power
    309
    Quote Originally Posted by Advocatus View Post
    source openjdk: [Only registered and activated users can see links. ]
    Code:
        public static int min(int a, int b) {
            return (a <= b) ? a : b;
        }
    Basically just an IF...
    So the point is to write the code yourself without IFS or conditionals. We don't care if any frameworks, libraries etc use them as long as we're not using them.
    Reply With Quote  
     

  6. #16  
    The One And Only

    01053's Avatar
    Join Date
    Apr 2011
    Age
    25
    Posts
    2,888
    Thanks given
    416
    Thanks received
    884
    Rep Power
    856
    Sounds like the kind of guy that spends half of the day overthinking simple solutions.


    Reply With Quote  
     

  7. Thankful users:


  8. #17  
    Registered Member

    Join Date
    Feb 2010
    Posts
    3,187
    Thanks given
    1,124
    Thanks received
    834
    Discord
    View profile
    Rep Power
    1514
    interestingly all of the solutions so far are way worse than using a simple if statement, so if the senior devs intention was to demonstrate their clear superiority they did a good iob
    Reply With Quote  
     

  9. Thankful users:


  10. #18  
    Developer


    Join Date
    Aug 2012
    Age
    22
    Posts
    2,491
    Thanks given
    179
    Thanks received
    1,703
    Rep Power
    2470
    Quote Originally Posted by Fire Cape View Post
    interestingly all of the solutions so far are way worse than using a simple if statement, so if the senior devs intention was to demonstrate their clear superiority they did a good iob
    100% agree

    this thread is nonsense, either ur senior dev is stupid or u didn't understand his point properly, but avoiding conditional checks for a performance gain, which in most cases (see OP's self called 'excellent solution' code for example) will only make things worse
    Reply With Quote  
     

  11. Thankful users:


  12. #19  
    Registered Member

    Join Date
    Feb 2010
    Posts
    3,187
    Thanks given
    1,124
    Thanks received
    834
    Discord
    View profile
    Rep Power
    1514
    Quote Originally Posted by Savions View Post
    100% right, what kind of senior dev we talking about because anyone can be a senior these days with how corporate works lmao

    OT: this thread is nonsense, either ur senior dev is stupid or u didn't understand his point properly, but avoiding conditional checks for a performance gain, which in most cases (see OP's self called 'excellent solution' code for example) will only make things worse
    I think Harry is probably on the mark about his senior dev wanting him to be mindful of design patterns rather than just passing everything off in mindless control flow statements, but idk why anyone would have an inherent dislike for if statements, they're just simple control branching and as we see here the alternatives are usually shit.
    Reply With Quote  
     

  13. Thankful users:


  14. #20  
    Registered Member
    Dread's Avatar
    Join Date
    Nov 2013
    Posts
    40
    Thanks given
    16
    Thanks received
    91
    Discord
    View profile
    Rep Power
    300
    Believe the thread was more about coming up with interesting ways to avoid an if-statement rather than coming up with better / more elegant solutions (because we're all aware that it's easier to just do a conditional branch).
    Reply With Quote  
     

  15. Thankful users:


Page 2 of 3 FirstFirst 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Convert this code to PI
    By Eclipser in forum Help
    Replies: 7
    Last Post: 06-29-2012, 12:35 AM
  2. Replies: 1
    Last Post: 12-07-2011, 03:34 AM
  3. Replies: 4
    Last Post: 06-22-2010, 09:07 PM
  4. Can someone explain this code to me?
    By jordan641 in forum Help
    Replies: 3
    Last Post: 04-24-2010, 07:52 AM
  5. Can anyone convert this to espeon (508) Repp++
    By massacre215 in forum Requests
    Replies: 2
    Last Post: 08-02-2009, 01:39 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •