Ad
  • Custom User Avatar

    Oh my, please don't apologize! I'm learning a lot from this thread, and I think others are as well.

  • Custom User Avatar

    Thanks @mcclaskc!

    I remember having a weird logic problem somewhere which happened because I was using 'and' instead of &&, but I cannot seem to replicate it - my apologies for starting this thread! ><

  • Custom User Avatar

    I agree that 'and' and '&&' have different precedences, and new programmers should not assume 'and' is just a pretty way to say '&&'. That doesn't make the solution incorrect. 'and' still short circuits, so both values have to be true in order for the method to return true. For logical evalutation, the two function the same way.

    The problem happens when, like your link says, in when you try to do control flow with '&&', assuming it has the same presedence as 'and'.

    For this kata, I really don't see a problem with this solution, but I 100% agree that ruby coders need to be aware of the subtle difference between 'and' and '&&'

  • Custom User Avatar
  • Custom User Avatar

    @surajreddy thanks for the link! I assumed it was a prettier way of writing && and ||...I was way off!


    I'll keep that in mind when deciding to use &&/|| or and/or (I mean &&/|| || and/or haha..)

  • Custom User Avatar

    This is not a good solution because "and" should not be used for logic evaluations in Ruby - "and" is a control flow operator, while && is a boolean operator.

    See http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/ for more info.

    Basically this code seems to work, but continuing to use "and" for boolean logic can create unexpected problems.