7

If I write the expression,

if not (expr1 or expr2) then value

I get the following warning from FSharpLint, In F# code, use 'e1 || e2' instead of 'e1 or e2'.

Why is using || preferred over using or? I want to write idiomatic code, but this appears to me to degrade readability. I really like the readability of the not function over !. the above example expression reads nicer and is much more declarative than the C# counterpart,

if (!(expr1 || expr2)) { return value; }

So why regress the readability improvement by suggesting double pipes instead of or?

pluralMonad
  • 173
  • 2
  • 3
    F# has banana clips `(|...|)` and this abomination: `|||>`, and you're worried about `||`, an operator that every curly-brace programmer on the planet instantly recognizes? – Robert Harvey Apr 20 '16 at 19:21
  • Yes, the scope of this inquiry was intended to be limited to the use of `||` and `or`. I don't think that the syntax of some languages is by itself a justification for idioms of other languages. I think this is especially true when discussing languages of different paradigms. – pluralMonad Apr 20 '16 at 19:28
  • 1
    MSDN says those two operators are identical. *Use the one you prefer.* See also https://github.com/fsprojects/FSharpLint/issues/158 – Robert Harvey Apr 20 '16 at 19:50
  • Do you have an opinion/thought on the use of those two operators? Thank you for opening the issue. That was my next stop if not finding a satisfactory response here. – pluralMonad Apr 20 '16 at 19:55
  • As a curly-brace programmer, I would probably prefer `||` in simple conditions. Although the `or` operator would look really nice in query expressions, Microsoft apparently still prefers `||`. See https://msdn.microsoft.com/en-us/library/hh225374.aspx, about halfway down the page. Query expressions look very similar in C#, though I find the F# ones slightly more readable. – Robert Harvey Apr 20 '16 at 20:05
  • 6
    Um, crazy guy who hasn't actually used F# speaking, but I'm guessing it's because there is no equivalent `and` operator. Or did I miss something [here](https://msdn.microsoft.com/en-us/library/dd233228.aspx)? – Karl Bielefeldt Apr 20 '16 at 22:17
  • @KarlBielefeldt: Ah, that makes sense. There's an `and` keyword, but it's not used in boolean operations. – Robert Harvey Apr 20 '16 at 22:38

1 Answers1

6

According to the FSharpLint folks, it's not a Lint warning; it's a warning emitted by the F# compiler.

It's probably there because or doesn't have a corresponding and counterpart. There is an and keyword, but it's not used for boolean operations, so you have to use && anyway, which means its better to use || for consistency.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
  • 3
    Which raises the question, why is the language so inconsistent? – Mason Wheeler Apr 21 '16 at 15:04
  • 2
    Eh, that's is a minor nit, and an inconsequential one since `&&` and `||` both exist. The only inconsistency here is the use of `or` as a synonym for `||` without a corresponding `and` synonym for &&. The `and` keyword [already does three different things](https://msdn.microsoft.com/en-us/library/dd233249.aspx), which is probably why they decided not to further overload it. – Robert Harvey Apr 21 '16 at 15:07
  • 1
    @RobertHarvey That is disappointing. Considering how context driven FSharp already is (type inference), I don't see the other uses of `and` as a hindrance to its use as an alias for `&&`. Thank you for your research efforts. – pluralMonad Apr 21 '16 at 15:31