Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Personal vision and experience</strong></p> <p>I personally do not frown upon the comparison between different types. I even encourage it, as it may improve code readability; making what you are doing seem more logical. Outside of the basic number types, and maybe a string and a character, I find it hard to give you a logical intra-type comparison, and I don't remember having met many. I have met alot of arithmetic operators used like this though.</p> <p><strong>How to use them</strong></p> <p>You should be careful with what you are doing, they are used scarcely for a reason. If you offer a function for the comparison of two different types, the outcome should be logical and what the user intuitively expected. It is also desirelable to write good documentation for it. Mark Ransom already said it, but it is good if users can compare in both directions. If you think your comparison is not sufficiently clear enough with an operator, you should think about using a named function. This is also a very good solution if your operator can have multiple meanings.</p> <p><strong>What can go wrong</strong></p> <p>You do not have full control over what the user will do with what you have written. tletnes gave a good example of this, where two integers are compared, but the outcome has no meaning. In contradiction to this, the comparison of two different types can be very right. A float and an integer both representing seconds, can be well compared.</p> <p><strong>Arithmetic operators</strong></p> <p>Next to logical, I would like to show an intra-type example with arithmetic operators. Arithmetic operators are much like logical operators when talking about intra-type usage.</p> <p>Say you have an operator + for a two dimentional vector and a square. What does this do? The user might think it scales the square, but another user is sure it translates! These kinds of issues can be very frustrating to your users. You can solve this by providing good documentation, but what I personally prefer, is specifically named functions, like Translate.</p> <p><strong>Conclusion</strong></p> <p>Intra-type logical operators can be useful and make clean code, but bad usage makes everything just more complicated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload