News for hackers. Stuff that matters.
Re:Yukihiro Matsumoto: “Ruby is designed for humans, not mac... by matheusmoreira on Sunday January 19, 2020 @11:21PM (#22096271)
The code evaluation is not the problem. The fact all evaluation takes place in a single global interpreter context is the problem. When a file that defines a class A is required, the A constant of the Object class gets set to a new instance of Class:

  # a.rb
  class A
  end

  # irb
  require 'a'

  Object::A.new
All code evaluation modifies global interpreter state. Honestly it's not much better than the C preprocessor's #include directive.

A better design: files are always evaluated with a clean interpreter state and they can return values just like methods.

  # a.rb
  class A
  end

  A

  # irb
  a = require 'a'

  a.new
This makes all state local to each script by default. Users will only have access to the returned value which can contain anything or nothing. If a module needs to modify existing classes, they could return modules that can be mixed in or metaprogramming methods that perform the modifications when called with the targeted class as parameter. Perhaps existing classes could even be passed as parameter:

  require 'extensions', Object, Kernel
Of course, these changes would break compatibility with all existing gems. The result would be a completely different language that happens to also be called Ruby.
Re:Yukihiro Matsumoto: “Ruby is designed for humans, not mac... by vidarh on Tuesday January 21, 2020 @05:58AM (#22105836)
Most of the code that changes global interpreter state does so in predictable ways that are perfectly fine, so I don't think what you're suggesting would actually make much change.

Most modern Ruby code avoids monkey-patching "unasked" unless that is an explicit purpose of the project and using the gem is explicitly "asking for it" in the first place. Providing modules to include or making you explicitly call methods or explicitly require files documented to do optional monkey-patching has been the idiomatic way of handling it for years.

Adding the ability to explicitly provide guarantees that the required code is sandboxed might be useful and might particularly help tooling reason better about the code, but it would have quite little practical effect on most modern Ruby.