rubyist
rubyist copied to clipboard
Extensions page contentions
I disagree with a couple of things in the extensions page.
Firstly, I feel that crossing out the word "monkeypatch" and having "hack" as a crossed-out term also makes the document a little personal. This should be an educational document and any personal vendettas you have against this coding style should be explained in a neutral tone with clear examples of why it is bad or when it is bad. Sometimes it's a Necessary Evil.
Secondly, I view this line as a hack:
Dir[File.expand_path("../../../lib/extruby/**/*.rb", __FILE__)].each { |f| require f }
Honestly, I was going to suggest adding the lib/extruby dir to the autoload_paths for the application (in config/application.rb) but that wouldn't work, as many of the constants you are "extending" are already loaded, and so it will not attempt to autoload them.
Anyway, I would rather this be put here:
Dir[Rails.root + "lib/extruby/**/*.rb"].each { |f| require f }
This is much cleaner (no relative paths) and reads much better.
Thirdly, you should be more explicit in this sentence for point #2 of your "Considerations" sub-section:
It prefixes the initializer with _ causing the initializer to be loaded before any initializer, making the extensions available as soon as possible.
It will not be loaded before any initializer, because if I had an initializer called _do_something.rb that initializer would be run first! You should write that initializers are run in alphabetical ordering and by prefixing this initializer with an underscore we make it run first.
Firstly, I feel that crossing out the word "monkeypatch" and having "hack" as a crossed-out term also makes the document a little personal. This should be an educational document and any personal vendettas you have against this coding style should be explained in a neutral tone with clear examples of why it is bad or when it is bad. Sometimes it's a Necessary Evil.
I have nothing personal with this approach. I'm sorry you had this feeling, I believe it just depends by the fact I'm not English native speaker and sometimes the documentation I write is not that clear.
I just wanted to underlying that you should not abuse with this feature. I agree with the hack section, I might probably want to keep monkeypatch because actually I believe people should be aware that monkey patching is a very dangerous activity. In my experience, newcomers are usually prone to monkey patch a lot of things. The method foo doesn't do what you expect? Let's monkey patch it, instead of creating a new method!
Also consider this repository originates from internal discussions and some content probably need further review before being considered a documentation for public audience.
Dir[Rails.root + "lib/extruby/*/.rb"].each { |f| require f }
That's fine. I honestly don't remember why I used expand_path.
It will not be loaded before any initializer, because if I had an initializer called _do_something.rb that initializer would be run first!
Indeed, you're right. I assumed it was implicit, but this is a wrong assumption. It probably makes sense to add a footnote/paragraph that explains this assertions is true as long as you don't have other _ initializers.
Thanks for all your feedback!