-
-
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
Remove Crystal::System, do system-specific methods by reopening #4906
Conversation
Actually, I like this PR. I never understand the reason for long naming like Also, I like the idea how to keep platform-specific functionality. Speaking about Dir/DirHandle example, |
I also like it. I always was in favor of not introducing modules that abstract the underlying implementation and directly defining the functionality in the needed types. It ends up being simpler in my opinion. |
I don't mind this either, as long as we keep the platform-specific stuff in |
Out of curiosity, how would this affect documentation? That is, I'm a newbie, I want to know what Random::System.random_bytes does, and googling would bring me where and for which platform? |
(I thought) this would not affect documentation, you'd still see it like this https://crystal-lang.org/api/System.html But well... apparently overriding a documented method with an undocumented one discards the documentation. Which could be changed, honestly... |
It looks fine. I liked the simple As long as we keep abstracting the underlying platform discrepencies, I guess reopening fits better with Crystal than external modules, especially since they shouldn't be used directly —unlike The one thing I don't like in this proposal is replacing compile time errors with runtime exceptions. Methods could be marked A solution could be to have private |
|
for the documentation issue, we could maybe add a # This is the doc
def method
end
# :previous doc:
# Add some additional details if needed? (<-- not sure about that)
def method
end |
My problem with the "only private methods" approach is that it's too similar to what we do currently - without the benefit of the added isolation that |
I'd suggest that we leave the documentation issues out of this discussion. Once we settle on the best approach for system-specific stuff, we can identify whatever gaps need to be addressed in the documentation system and track them in their own issues. Whatever we decide, something we need to keep in mind (which was discussed also in #4406), is that it needs to be easy to identify which parts of the code are platform specific, and it would be cool if the structure would guide people implementing new platforms, like @ysbaddaden said here: "Porting Crystal to support more platforms could be achieved by adding any required C bindings to src/lib_c then implement the API for the platform under src/sys —in the hopeful case that it won't require changes in the Sys API." To that end, do you think adding a "platform_specific" folder under "system" could help? For example, in this PR, every file that now is under
|
|
@oprypin would you elaborate on what confuses you? Is it the part about leaving the docs discussion out of this issue, the part of adding a |
@mverzilli |
Thanks for clarifying! Don't want to derail the conversation, so let's leave the doc part there, I guess we're on the same page then. About the |
What you did make me realize is that the crystal/system folder name stops making sense with these changes. So I'll add some folder renames to the mix. |
I still don't understand the event in which something not platform specific would end up in |
Solving the issue with documentaton in #4908 |
def self.random_bytes(buffer : Bytes) : Nil | ||
# Fills *buffer* with random bytes using arc4random. |
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.
Why did you put the doc under the method? (And not above)
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.
This is a platform-specific redefinition of a method. It must not override the documentation that is meant to be public. Implementation details shouldn't surface there anyway.
I think that something sane to expect is to avoid different representation of the std in different platforms. Using wrappers in Crystal::System namespace is a way to accomplish this. If we rely on reopening classes there will be no structure to prevent that. I want to go through the arguments against the crystal::system namespace to expose why I am more inclined to keep them, at least for now.
Some abstraction is needed. And I don't think the std should resolve/implement the abstraction, but rely on it.
I don't see how reopening classes would be better. All overridden methods will look as duplication. This overlaps with the previous item, but I think is good to have platform specific DirHandle. The alternative would be to allow a struct pointer of each platform to be in Dir, making the representation a bit messy.
Was this measured?
These applies whether the The thing that bugs me most of the current state is all the commented def that appears as intention of internal api for the abstractions. Those are a source of confusion since it happen only there. A way to solve it would be to allow the base implementation to raise, but that would move compile time to runtime error for missing parts of the platform. Maybe is not that bad, but is harder to track. |
I mostly like this. I find it much easier to understand and think others will too. The one piece that bothered me is runtime errors for unimplemented methods ... but perhaps they are only intended for developers who are porting Crystal to new systems? |
In the current state of the PR the errors are compile time |
Errr... I was OK with the initial pull request, except for the runtime errors, but now I'm puzzled:
|
@ysbaddaden the folder name |
I think the true issue uncovered by this PR is that there's a big difference between heavily platform-specific classes ( Perhaps the best way to compromise is to just export modules in |
First of all, I don't expect this PR to be easily merged without discussion, I acknowledge that putting platform-specific functionality into the
Crystal::System
module/namespace is an important decision of the core team. The contents of the PR is more of a preview of what it could look like when Crystal::System is gone, assuming "Unsupported functionality is a run-time error" just because it looks cleaner regarding docs.I felt that it is important to start this discussion because of some unnecessary confusion caused by this separation during the implementation of #4903 and also #4882 (comment), and @asterite's opinion in #4903 (comment) increased the confidence.
Initial discussion in IRC
Arguments against
Crystal::System
::nodoc:
)Arguments for keeping
Crystal::System
(partly quoted from @RX14):raise NotImplementedOnPlatform
or whatever)require
order though it's not the only way)Also note that this PR contains only one of the possible implementations. The other one is to keep the redirecting stub methods as they are right now and enforce all platform-specific files to contain only private methods. That would not force us to change the errors to be run-time [fix #4905] in order to keep documentation in one place.