-
-
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
Would it be possible to add an alias for __dir__
?
#8546
Comments
In Crystal we try to avoid aliases as much as possible to relieve users of having to learn different equivalent solutions to the same problem when you actually only ever need a single one. The only thing I could think of would be to enhance the error message for an undefined local variable/method |
Technically, another idea would be to allow parsing |
Ok that makes sense about aliases! But I really like the idea of the formatter providing an automatic fix! I couldn't find any documentation or threads about But if the code formatter automatically changed it from |
FWIW it's documented under https://crystal-lang.org/reference/syntax_and_semantics/constants.html#pseudo-constants. |
I like to think of Crystal as a new language. In 20, 30 years, when someone sees Elixir got it right: it took what it liked from Ruby and dumped the rest. I think we should do the same. So I won't approve the PR for this. |
That makes sense! I also learned why Either way, it's been great to have the discussion here, because this will make it easier for developers to find in the future. Thanks! |
Hello, sorry if this has already been asked! I'm working on the advent of code puzzles, and I figured out how to read a file in the same directory as the script:
I noticed that
__dir__
isn't defined. But I actually just realized that Crystal supports__DIR__
, and that does work:I was just wondering if you might consider adding an alias for
__dir__
?__DIR__
does make more sense and it has the same case as__FILE__
, but it's just one less surprise for people coming from Ruby.The text was updated successfully, but these errors were encountered: