6
kinnrot
8y

people who writes 'if (!isActive){} '
I do not do like you.

Comments
  • 3
    What do u do instead ?
  • 1
    @AboMahdi I think he writes 'if(isNotActive)' 😜
  • 0
    You don't like me?!?! :) On a serious note, what's the alternative or better way?
  • 1
    Maybe he writes

    if(isActive()) {
    } else {
    // code here
    }

    Sooo much better...
  • 1
    Then he perhaps must create a new variable called isNotActive which is bad for performance.
  • 0
    @simeg That depends. Most compilers optimize that away. Unless you use a crappy language of course ;-)
  • 0
    @pardeike ah cool didn't know that. Can you give me an example of a language that does that?
  • 0
    And i'm the only one o doesn't like that because of the "is" and just use "active" instead?
  • 4
    @pneves I think it's good to prefix booleans with "is".
  • 1
    @simeg java, swift, c/c++, JavaScript and many more. Basically anything that gets compiled or turned into bytecode
  • 2
    @simeg Thinking about it and maybe you're right. Because I'd some trouble in the past when I want a method to active something and a property to know if it was active. You give me the solution and I'm thinking how dumb I was! 😐
    But I'm thinking now that a active() method that gives you the state and change the state when you give it a argument wold be right too, but when performance is a really concern, this was not the best solution.
  • 0
    if (!activeEh) {...}
  • 1
    Stop reverse boolean-ing. 😂😂
  • 2
    As a general best practice you should keep all your methods positive and if needed use bang (!) to negate them.

    Otherwise you end up with crazy code like this and it takes you 3min just to comprehend it.

    if(!isNotDisabled()){
    ...is it enabled?!?!?
    }
Add Comment