Add EOLconstant (End-Of-Line)#11303
Conversation
…ng#10885). * Is OS aware ("\r\n" on Windows, '\n' otherwise).
|
Some additional thoughts:
|
Yes, it should be the same type on all platforms (cf #10645).
I don't think that's necessary. Libraries like
|
|
What is the use case of this constant? |
|
👍 for
|
|
Do we have consensus on |
|
I may be alone, I still prefer |
|
@j8r If I'd like to write code that would be read by my grandma I'd agree with you for sure, but most programmers I know have a pretty firm notion of |
|
Anyway, can this constant be useful in the stdlib, and even the compiler? |
|
crystal/spec/std/process_spec.cr Lines 53 to 59 in 4204bce |
|
|
|
Another one: crystal/spec/compiler/macro/macro_methods_spec.cr Lines 36 to 42 in 3a360b1 |
EOLconstant (End-Of-Line)
| EOL = {% if flag?(:windows) %} | ||
| "\r\n" | ||
| {% else %} | ||
| "\n" | ||
| {% end %} |
There was a problem hiding this comment.
Could be shortened into:
| EOL = {% if flag?(:windows) %} | |
| "\r\n" | |
| {% else %} | |
| "\n" | |
| {% end %} | |
| EOL = {{ flag?(:windows) ? "\r\n" : "\n" }} |
There was a problem hiding this comment.
I find ternary statements overly confusing. They only help reduce line count at the cost of readability.
There was a problem hiding this comment.
I suppose you could also write it as {{ if flag?(:windows) "\r\n" else "\n" end }} if that's more approachable?
Anyway, these are all equivalent expressions of the same thing and there's no clear preference for one or the other. So let's keep it as is.
EOLtosrc/kernel.cr."\r\n"on Windows,'\n'otherwise).Resolves #10885