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
[WiP] Add a simple example for basic/common things done in extensions #2
Conversation
@monkstone not sure how I can help with the issue, I have to admit myself I'm fairly new to the world of jruby-extensions, however more than willing to collaborate here adding examples and documentation. Next thing I would really like to add here is a super simple example integrating with a jar, lib. Any idea which one would be simple and basic enough? /cheers |
@purbon - this looks like a good start, but should there be more comments in the Java? e.g. @JRubyClass(name = "Bar")
public class Bar extends RubyObject { should we ask for clarification from @headius, @enebo or others about the annotation @JRubyClass(name = "Bar")
public class RubyBar extends RubyObject { etc. |
I would like to see some discussion that reveals insights about the different ways the BasicLibraryService can be implemented and which bits are necessary etc. For example, the ObjectAllocator is defined as an anonymous class but it can be an inner class. |
I fear that we will create dogmatic cut and paste examples. |
Hi, I'm not so new to jruby extensions and can state categorically that the class names should just be different (as should method names, and there is a convention regarding method names). My issue with @headius is that he has never replied to my question, however it seems pretty clear by his actions that he favours implement Library over LibraryService. rake-compiler/rake-compiler#87 |
By convention all Ruby instances in native extensions are called 'RubyXXX' (e.g. RubySocket, RubyString, etc...). Another common convention for stateless module definitions is to bind with static methods: @JRubyMethod(module = true)
public static IRubyObject default_options(ThreadContext context, IRubyObject self) { Any arg logic would follow self but self ends up being the self of the module itself. @monkstone You mean BasicLibraryService right? I did not remember this even existed. We do not use it internally and I am not sure there ends up being a real difference but I also only use Library. |
* Classes and Modules | ||
* Static methods in both elements | ||
* Loading the extensions | ||
* ... |
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.
An ellipsis, how ominous! 😃
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.
Yeah! I was more on the idea shared later here by @enebo, using BasicLibraryService, using Library, etc... but yeah! the naming is funny!
IMHO this is a great start and we should merge it and continue to iterate upon it. |
[WiP] Add a simple example for basic/common things done in extensions
@purbon can you followup by renaming Bar to RubyBar and I also think using static methods for module is more idiomatic so I would like to see that change based on my comment above. |
@purbon and I should say I am very happy you are doing this for us! |
@monkstone yeah agreed we have perhps too many ways to do things but I think providing a golden single path might be best for example apps. |
@guyboertje in next iterations I will improve comments on both sides, my idea here is to provide good learning examples, if people end up c&p is hard to avoid, but I hope reader learn/understand what they will be doing. |
@enebo thanks for bringing this in, I will follow up with your proposal of improvements. And obviously with more examples. A pleasure to help a nice community and project like this one! On the other side, I wonder what do you mean by golden single path? can you elaborate this a bit more? @rtyler thanks for the appreciation man! looking forward to keep improving this! @monkstone please contribute here, I really would like to see here a good discussion on providing good learning examples for jruby. Thanks!
|
@purbon by golden path I mean recommended idioms vs elaborating on different mechanisms for achieving the same task. |
Makes sense, looking forward to keep this going! Thanks for making jruby happen! |
maybe this should have been the right place for my comments: #3 (comment) |
I started working on this with the idea of providing simple enough examples of working with jruby-extensions. Including things like class and module definitions, working with static methods, passing parameters and creating internal objects, etc.
I'm opening this PR to get feedback if the direction is the one expected or should I take another direction to provide meaningful examples to help document this.
Welcoming all proposals and ideas,