Ad
  • Custom User Avatar

    Maybe they were just trying to practice numpy like I was ;)

  • Custom User Avatar

    I don't like your solution because you kill flies with cannons.

  • Custom User Avatar

    Switch statements or if/else clauses are not (imo) about number of options, nor is one simpler that the other. What I like about the switch statement is that it focuses on the char I'm discriminating for, not in the comparison.

    But of course that both approaches work, and you should go with the one that you feel most comfortable with. I do disagree, however, that one should choose between switch and if based on number of branches.

  • Custom User Avatar

    Using #define in modern C is not a good practice. You could use inline function, but IMHO neither was necessary in this case. Furthermore, the ? expression is totally unnecessary.

  • Custom User Avatar

    I disagree with "Best Practices" because using "switch" for just two options is too much, it is better with a simple "if else".

  • Custom User Avatar

    That's the reason I didn't vote his as best practice.