7 ms·
> without a lot of the strange quirks of perl And instead with a lot of the strange quirks of Ruby! \s, only kind of, I love Ruby but it does have a few quirk
by cutety 8y ago
> without a lot of the strange quirks of perl
And instead with a lot of the strange quirks of Ruby!
\s, only kind of, I love Ruby but it does have a few quirks that I see confuse some people coming from other languages when they start writing non-trivial Ruby code (literally everything is an object being a big one — “what do you mean a class is an object?! modules too?!”).
However, these quirks are much, much easier to learn, understand, and possibly eventually come to like, rather than some (many) of the quirks that exist in Perl.
- chrisseaton 8y ago> what do you mean a class is an object I think that's pretty standard for object orientated languages. I can't find of any where it isn't the case off the top of my head. Is it not the case in Perl's object orientated support? And why wouldn't it be an object? Seems more surprising for classes to be an exception.
- Fellshard 8y agoPeople coming from Javaville or C#land definitely don't have that kind of abstraction (and yes, the usual rebuttal is that they're procedural, not OO).
- chrisseaton 8y ago> what do you mean a class is an object > People coming from Javaville or C#land definitely don't have that kind of abstraction What do you mean? A class is an object in both Java and C#.
- Fellshard 8y agoNot exactly. What you see as the Class type in Java, at least, is simply a representation of a class. It can tell you about a class, but it doesn't represent an actual thing you can manipulate, change, or use. I can't add a method to that class, or add a field, or manipulate its instances beyond basic method lookup and dispatch. In something like Ruby or Smalltalk, a Class is an object. It can be changed live, altered, adapted, cloned, or otherwise used just like another object; and the application will change its behavior accordingly, right there on the spot. I'd recommend reading up on prototype inheritance, as that is the model generally used in the latter languages.
- chrisseaton 8y agoYou’re telling me that class objects in Java are immutable while they’re mutable in Ruby. That’s orthogonal to whether they’re objects. > I'd recommend reading up on prototype inheritance Thanks but I’ve already literally got my PhD in metaprogramming in Ruby and object model implementation in Java. Ruby doesn’t use anything like prototype inheritance.
- kazagistar 8y agoIts more then that... It's not even inmutable, not really. There are some things, like privaCy of access, that can be mutated by manipulating Java class objects. That said, maybe the difference here is how often the janky metaprogramming of classes interferes with day to day peogramming; a java programmer might have never seen this stuff, moreso then a ruby one?
- Fellshard 8y agoYeah, the correction re: prototype inheritance is a good one. That said, there is a qualitative difference in what we call 'classes' in those two environments, which is part of why I think there's confusion. Class in Java is a fairly different concept than a Class in Smalltalk, Ruby, or JS.
- jonathankoren 8y agoJava has Class which is an Object.
- repsilat 8y agoHonest question: Can you write Class foo = String; in Java? If so I guess classes really are objects, if not I'd say "there are some objects that represent (or wrap) some classes somehow."
- akdas 8y agoClass foo = String.class; (Though `Class` is actually a generic type, so you'd want to include the type parameter in actual code.)
- repsilat 8y agoSure, I'd say that fits my second suggested wording -- `String.class` is an object that represents or wraps the `String` class.
- chrisseaton 8y agoHow do you tell the difference between an object that is the String class, and an object that represents the String class? If you can call .toString on it, and you can compare it to other classes, and you can call .newInstance, then how is it more of a representation than being the actual thing?
- lmm 8y agoIn java you have to call the special and awkward .newInstance rather than being able to use standard "new". Whereas in e.g. Python I can equally well do >>> str("foo") 'foo' >>> x = str >>> x("foo") 'foo' and the "builtin" str and "userspace" x are equally first-class.
- 8y ago
- jcranmer 8y agoClasses are objects in Java. You can even create new classes at runtime in Java or use java.lang.reflect.Proxy to make existing objects implement different interfaces. I once did this in a class project, including even manually creating the bytecode at runtime. Ironically, it's probably the most understandable and maintainable of the crazy metaclass-style reflection I've done (although that's probably mostly due to the fact that the scope was much more limited: I was only mirroring a set of interfaces into a different namespace to work around some stupid limitation in a different library).
- Fellshard 8y agoYou can, yes, but not nearly in the same way.
- rileyphone 8y agoIt means they lack a metaobject protocol.
- sytringy05 8y agoNot to mention the nightmare of ruby versions and packages. I quite like the language by my biggest drawback to using ruby for anything is versioning and packages.
- cutety 8y agoI would agree, however bundler & rvm are incredibly easier to setup and use when comparing to Python’s virtualenv (and the few other alternatives frequently brought up). I’m not sure there is even an equivalent for the Perl ecosystem, as I gave learning Perl an actual effort a while ago (no idea why) and all it’s quirks and weird syntax immediately turned me away and I’ve never looked back.
- dotandimet 8y agoThe rough equivalents in the Perl ecosystem would be cpanm (for installing), carton (for managing project-specific dependencies), and perlbrew or plenv (which I think are more like pyenv than virtualenv)
- toasterlovin 8y agoHonestly curious: can you give an example of what kind of issues you run into? Asking because I basically never have versioning or package issues with Ruby. And on the rare occasions when I do, there's usually a good Stack Overflow answer or Github issue.
- yxhuvud 8y agoHuh, with Bundler, Ruby was one of the first language ecosystems that actually got it's act together on those points. It is so much more mature than python in this regard, for example.
- rat87 8y agoReally? I haven't used it much or in a while thought Ruby had their package story down. Python packaging is pretty bad requirements.txt is a pretty adhoc list and pipenv doesn't seem ready for prime time(haven't tried poetry yet)
- rat87 8y ago> \s, only kind of, I love Ruby but it does have a few quirks that I see confuse some people coming from other languages when they start writing non-trivial Ruby code (literally everything is an object being a big one — “what do you mean a class is an object?! modules too?!”). That's also true in python ---| type(enum) <class 'module'> Also ruby Procs aren't objects And unlike Smalltalk &&/and ||/or are not methods