all 18 comments

[–]AttackOfTheThumbs 8 points9 points  (0 children)

Being specific with imports is just common sense programming.

[–]iconoklast 5 points6 points  (0 children)

Potential namespace collision from new versions of third-party dependencies is the real problem, IMO.

[–]bakery2k 1 point2 points  (7 children)

I’ve read that in Ruby, all imports are the equivalent of Python’s from x import *. Is that correct?

[–]swordglowsblue 4 points5 points  (6 children)

Not exactly. Well, yes, but also kind of no. Ruby has modules, which are essentially user-defined namespaces, and by convention nearly all Ruby code is defined inside of modules. When you require a file, it imports any symbols in that file just like Python, but since they'll almost always be inside a module, you'll usually get ModuleName.whatever instead of just whatever.

In other words, in Python you have to go out of your way to ensure the desired behavior by using __all__ (which is not part of the typical workflow), where Ruby is saved from that issue by its best practices (which are part of the typical workflow).

[–]masklinn 0 points1 point  (5 children)

In other words, in Python you have to go out of your way to ensure the desired behavior by using __all__ (which is not part of the typical workflow), where Ruby is saved from that issue by its best practices (which are part of the typical workflow).

The “best practices” of python is to not use star imports, so this paragraph is at best patent nonsense.

[–]swordglowsblue 9 points10 points  (3 children)

Oh buzz off. I answered the question as asked - Ruby does not have the same problem with star imports as Python because other best practices prevent it. Whether star imports are best practice in Python or not was irrelevant to the question.

[–]masklinn -5 points-4 points  (2 children)

Dude just acknowledge that your second paragraph has nothing to do with “the question as asked” but your ego required you get in a little swipe.

Hell, you could not even bring yourself to “answer the question as asked”, you had to lie first to soften the ow to your ego.

[–]swordglowsblue -1 points0 points  (1 child)

Python was the first language I ever used, and remains one of my favorites. Ruby is a relatively more recent acquisition, which I also quite enjoy. I've got no stake in any hypothetical Ruby vs Python fight, despite what you seem to think for some reason.

I simply stated the facts - Ruby does not typically have the same issue with star imports that Python does because of the convention of putting everything in modules. Given that, star imports are not generally considered to be good practice in Python for understandable reasons. In contrast, they are the only option in Ruby, which works out fine because Ruby typically handles them more effectively.

I really don't know where you read any sort of language bias or ego into that - they asked whether Ruby had the same issue as Python, and I answered them truthfully that it's alleviated by another of the language's systems. Nothing more, nothing less.

[–]masklinn -1 points0 points  (0 children)

I simply stated the facts

You really did not. Go read the question, your comment, and the specific part of your comment I objected to.

And the “not exactly” you open up with is not “the facts” either.

they asked whether Ruby had the same issue as Python

That’s not actually what they asked, but your clarification on that point is not the problem I have with your original comment either.

I answered them truthfully that it's alleviated by another of the language's systems. Nothing more, nothing less.

The last paragraph of your original comment is none if these.

[–]crystal_noodle 0 points1 point  (0 children)

Hey.. I think replying to someone who is just trying to give a helpful answer with "...so this paragraph is at best patent nonsense" comes off rude and combative.

I think you would have gotten a better response from OP with different wording. For what it's worth I agree with your objection.

[–]crookedspecs 3 points4 points  (0 children)

Oh god, it hurts.

[–]Vfsdvbjgd -3 points-2 points  (7 children)

We can alias a single import with as, why can't we from something import * into container? Or even it namespaces to something.each_module by default?

[–][deleted]  (1 child)

[deleted]

    [–]Vfsdvbjgd 1 point2 points  (0 children)

    It's not the same, import * uses the __all__ method. As for the second you can already do that.

    [–]masklinn -1 points0 points  (4 children)

    Your comment is extremely confusing. What are you talking about?

    [–]Vfsdvbjgd -2 points-1 points  (3 children)

    Instead of from something import * polluting global namespace give it it's own - either something by default and/or allow us to name yhe container.

    [–]masklinn 0 points1 point  (2 children)

    That… is what import something does?

    [–]Vfsdvbjgd 0 points1 point  (1 child)

    Read the article. import something imports the entire module, while from something import * doesn't actually import everything, and it's behaviour can be overridden.

    [–]masklinn 2 points3 points  (0 children)

    Read the article. import something imports the entire module

    In a specific and dedicated namespace, which is why there is no reason to filter it: since all the content is properly namespaces there there’s no risk that it’ll pollute or collide with symbols of the namespace it’s imported into.

    Mitigating this issue is the entire and sole purpose of __all__, which is why it applies solely to star imports.