From: danieldasilvaferreira@... Date: 2018-05-18T08:19:49+00:00 Subject: [ruby-core:87165] [Ruby trunk Feature#14758] Add a first-class support for isolated bounded packages / modules / contexts Issue #14758 has been updated by dsferreira (Daniel Ferreira). grzesiek (Grzegorz Bizon) wrote: > I guess that this is usually a bad idea, but it depends on what you are using your tests for. When I have to develop a complex module I usually follow TDD because TDD is a design tool for me, not a testing tool per se. But I would like to avoid diving into discussions about TDD / testing here. I use TDD. One thing doesn't imply another. Think about it: You set your test for the scenario on the public interface method. Red light. You create your code logic to get the green light. Add tests for other scenarios. Get green light for the other scenarios. Get 100% coverage. You can now refactor the code logic at your own will redefining your architecture and tweaking performance without thinking ever about tests. And you know that if your test suite passes and you still have 100% coverage all your code is good. ;-) ---------------------------------------- Feature #14758: Add a first-class support for isolated bounded packages / modules / contexts https://bugs.ruby-lang.org/issues/14758#change-72156 * Author: grzesiek (Grzegorz Bizon) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- While one of the core principles of Ruby is to extend the language in a way it is a most useful and convenient tool that a software developer can have in their toolbox, lack of a first-class isolation on module level can cause some serious problems when project grows beyond some size. This is especially visible in large projects, where most of the code lives in the `lib/` directory, and there are tens or hundreds of modules there. Ideally we would like to make these modules isolated and hide complexity behind facades. Currently it is not possible to isolate such modules, because a developer can still reach beyond boundary of a bounded context, and use `MyModule::InternalClass` directly. It is very difficult to enforce boundaries, currently it requires a lot of work to implement complex static analysis rules. Would it make sense to add support for first-class `package`, `context` or `boundary`, that would be a regular module but would not allow referencing inner constants from outside? ~~~ context MyModule class MyIsolatedClass # ... end def self.build MyIsolatedClass.new end end MyModule::MyIsolatedClass # raises context violation MyModule.build # => Returns an instance of MyModule::MyIsolatedClass ~~~ I'm pretty sure that I failed at finding similar feature proposal that has been already submitted, in that case sorry for that! Please let me know what do you think about that! Thanks in advance! <3 -- https://bugs.ruby-lang.org/ Unsubscribe: