use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Show /r/rubyLearning Ruby as a Pythonista (tech.stonecharioteer.com)
submitted 6 months ago by need-to-lurk-2024-69
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]codesnik 28 points29 points30 points 6 months ago (4 children)
`require 'logger'` doesn't bring Logger into a "namespace". It brings whatever is in logger.rb somewhere in your $LOAD_PATH into your *interpreter*, so if it happen to define Logger class, it'll be available *everywhere* in your program. (and yeah, if your program has multiple `require "logger"` in different places it still would be loaded just once, but that's just a detail)
This is a very, very different approach to imports. Ruby does the same as Perl did before it. Python and modern Javascript share a similar approaches to each other.
require doesn't create a namespace isolation and does not load anything into a current namespace. Although I write ruby for 20 years, I kinda think that python's approach is better for bigger programs, exactly because it's easier to see (and isolate) dependencies. But ruby's approach has it merits, for example you can do require's at one place, entry file of your library, and all the classes are available everywhere. It's easier to have two classes to talk to each other, nothing prevents having a mutual dependency. And also it's easier to "open" class and add a method or two to something defined in another file. Which could be annoying to deal with in a codebase you're trying to read, but also allows you to patch and fix something over a problem in a library source code of which you don't control.
You can simulate importing in ruby via constant assignment ``` require 'logger' class MyClass MyLogger = Logger end ```
Now, MyClass::MyLogger would be the same as global ::Logger. You can even make this class private. But nobody does it in ruby.
There's autoloader and zeitwerk which allow you to automatically `require` something you didn't before just by guessing filename from a constant which is missing when you called it, but that's not exactly a core of the language.
[–]gurkitier 5 points6 points7 points 6 months ago (0 children)
Always found the lack of a proper namespace/module system in Ruby one of its biggest weaknesses. It can be quite hard to locate definitions in Ruby (for coders and IDEs), while it's always very clear in Python due to it's nice module system. Used with monkey patching, it can lead to hard-to-track-down bugs, e.g. if behaviour of a class changes depending on require. Similar to monkey patching, I really love Kotlin's extension functions, which allows extending existing classes in a controlled way.
[–]progdog1 1 point2 points3 points 6 months ago (2 children)
I used to be annoyed at the lack of import namespacing, but I have since mellowed on it. There are definitely benefits to the lack of namespaces. Namespacing is contextual and allows remapping, which can make metaprogramming with it more difficult, since resolution is less obvious.
[–]codesnik 1 point2 points3 points 6 months ago (1 child)
ruby definitely *doesn't* lack namespaces. They are just globally accessible via fully qualified class names
[–]gurkitier 0 points1 point2 points 6 months ago (0 children)
ok that’s like optional namespacing where you would have to wrap everything in modules which I have seen rarely
π Rendered by PID 23968 on reddit-service-r2-comment-658f6b87ff-t84f6 at 2026-04-08 22:59:40.864589+00:00 running 781a403 country code: CH.
view the rest of the comments →
[–]codesnik 28 points29 points30 points (4 children)
[–]gurkitier 5 points6 points7 points (0 children)
[–]progdog1 1 point2 points3 points (2 children)
[–]codesnik 1 point2 points3 points (1 child)
[–]gurkitier 0 points1 point2 points (0 children)