-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EOL
constant (End-Of-Line)
#11303
Add EOL
constant (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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
EOL
constant (End-Of-Line)
EOL = {% if flag?(:windows) %} | ||
"\r\n" | ||
{% else %} | ||
"\n" | ||
{% end %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find ternary statements overly confusing. They only help reduce line count at the cost of readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
EOL
tosrc/kernel.cr
."\r\n"
on Windows,'\n'
otherwise).Resolves #10885