Since then I've done a little rails work, learned enough Python to be moderately useful, and stumbled through a few other languages. I still try to be impartial, and to use the best tool for the job, but it's always a joy when I find a chance to use Ruby again.
As someone who started writing in Ruby with tabs indentation, I switched over to 2 spaces as most other projects were using it.
After a short period of getting accustomed to it, I can't imagine doing it any other way (but only in Ruby!). It just feels more natural in Ruby than any other indentation style.
I'm not sure why, maybe the language keywords are different enough and the length of line is just so that 2 spaces hit a sweet spot?
We use linters at work, but even setting linter rules will cause a lot of arguments.
In retrospect, I'm not sure how successful Matz has been in upholding the principle of least surprise. In many ways, Ruby is one of the worst offenders.
Although I like what Rust and Nim are doing with making the method/function distinction irrelevant -- there, x.f() is just syntactic sugar for f(x) -- so you can use whichever you prefer.
It is true that you can invoke it either way if it's a method, but you cannot if it's a function, as well.
As I pointed out in another comment, the way lookup is handled for instance is really a clusterfuck (http://norswap.com/ruby-lookups-scopes/)
Other OO languages like Java or Smalltalk (the more direct Ruby inspiration) do much better in this regard of having simple rules for lookup (and other things).
On the other hand, in Python lists, tuples and arrays are fundamental data types and thus len() is defined as a fundamental built-in function. I think it makes sense.
What i didn't like was when map() and reduce() were moved away from the basic functions.
But len() is only a fundamental built-in function for fundamental data types and you can implement it on any class by implementing the method __len__(self).
For those it doesn't make sense any longer to be able to do len(x).
Can you explain why? I'm curious.
The three topics (module linearization, scope lookups and method parameters) are constant source of wtfs as soon as you go beyond something basic.
What is your standard for non-offender? Certainly not C++ or Common Lisp. Scheme, Smalltalk, Go?
C++ is probably an offender but for other reasons. My experience is limited, but from I've seen it's mostly vast But when you look at each feature they're not incredibly unintuitive. A huge problem in C++ is that there many ways to do everything (the old way and the new way and the new better way, all which have slightly different semantics).
Common Lisp is also vast but seems really solid on its foundations.
Scheme, Smalltalk and Go, definitely better. Lua. Java as well excepted maybe the really fine points of generics (captures) -- but in practice understanding that is almost never needed. C, unless you count undefined behavior as against least surprise, then it fails. Python I'm really not practiced enough to tell.
All in all, we're probably not using the same criteria for least surprise. I'm not even considering libraries, just baked in language features, and being able to predict what they do. In that sense, Ruby is really much worse than Java. It's really bizarre (see my blog posts in the other comments). And the problem is made worse by the fact that all that weird behavior is not documented anywhere.
(1) e.g. https://drive.google.com/file/d/0B0O9lcl5dMLQbDFkYk1kX28xM1U...
Additionally, the MRI is perhaps the slowest implementation of a dynamic language out there (besides "R"). I know there are alternative implementations; is there any implementation that is significantly faster (at least as fast as Google V8 for ECMAScript) and that supports the full Ruby language without compatibility issues?
* in place of Python
Ruby is multi-paradigm; in particular it's easily the most "functional"-feeling of the major scripting languages.
> and moreover OOP of the old way (a method must be tied to only one object. This is what prevents me from going to Smalltalk, btw.)
I'm unsure what you mean by this. Ruby has one of the most flexible OOP systems in existence, a good deal more flexible than Python's, and lets you create more or less any conceivable relationship between methods and objects. (Which is why Ruby is slow).
> Additionally, the MRI is perhaps the slowest implementation of a dynamic language out there (besides "R"). I know there are alternative implementations; is there any implementation that is significantly faster (at least as fast as Google V8 for ECMAScript) and that supports the full Ruby language without compatibility issues?
Ruby's not fast, but it's improved quite a bit from the 1.8 days. It's comparable to Python.
As for high-performance alternative implementations, there's TruffleRuby, but it still has compatibility issues and isn't ready for production use. There's also Crystal, which is a very similar (but incompatible) compiled language with performance on par with Go/Java/Swift. It's also still in beta but they plan to have a 1.0 release by the end of the year.
>I'm unsure what you mean by this.
I believe that any OOP system that wants to be flexible, modern, and powerful, should have most of the features that CLOS (Common Lisp Object System) has. Julia (language) did, for example.
It would be lengthy to explain all the features and benefits of CLOS here, but in CLOS, methods are not tied to objects, and all methods do multiple-dispatch. This also allows doing OOP in a functional-like way (this is easier to understand once you see how CLOS works.)
In comparison, most other OOP systems feel limited and restrictive, and very different from CLOS.
>a good deal more flexible than Python's
Probably, but OTOH Python's OOP system is perhaps one of the weakest OOP systems out there, and speaking from my 2 years of professional experience with Python. I find it acceptable, but not good.
While Ruby's OO is not a verbatim copy of CLOS, it is much more versatile than you've described above. The best way to think of it is it's delegation under the hood using a little syntax sugar to resemble classes. It's not multiple dispatch, but methods can be aggregated into modules that can be mixed into classes or objects arbitrarily. Dispatch is dynamic and structural (duck typing). All of this combined with ruby's meta programming features make for an expressive system. It's not restrictive, in fact it runs the risk of the opposite problem, which is people over use the flexibility and write overly magic code that proves difficult to maintain down the road.
I got excited the first time I read that phrase (i think it was Matz who said it?), but they are very very different languages; for example metaprogramming is a piece of cake in Lisp, while it is something reserved for advanced Ruby users, to put just one example. And for me, metaprogramming is extremely important.
In any case, I think i'll give Ruby a second look.
It is worth your time.
Actually that was delayed to next year.
What do you mean by that?
You can do this:
class A; def m; 'A'; end; end
class B; def m; 'B'; end; end
=> ["A", "B"]
I like Ruby especially because "everything is an object". That's a simple concept that you can understand easily.
Every time I use Python I stumble over how it does things differently. I can't wrap my head around the Python way.
Note, I don't like the metaprogramming approach that Rails popularized. Metaprogramming in small doses is okay but when everything you touch has some kind of indiscernible magic around it, it's just too much.
"m" is a method in class A,
"m" is a (different) method in class B.
Each method is tied to only one class. While in CLOS i can do the following:
let's say i have class Vehicle -> subclasses Spaceship and Car
then i have class Person
i can define, for example, the method "drive" two times:
drive (Spaceship, Person)
drive (Car, Person)
To put it in another way,
drive (Spaceship, Person)
Thus if i call the method "drive" and pass it two objects (a,b) , the language will check if there is an implementation of "drive" for the specific combination of class-of "a" and class-of "b" and apply the correct method.
CLOS also allows, for example, doing other interesting stuff, like, for example, if we have method "xxx" and when we call method "xxx" with some objects as arguments, there is more than one method that could apply, i can also configure things such as:
a) all methods are called and the results of all methods are collected in a list
b) the maximum of all results is used
c) the minimum
etc etc (you can define your own behavior)
There are much more features as well. For example, on your code you can specify the code that should execute whenever any vehicle is driven by a person; also, in separate, the code that should execute when a person drives a Spaceship, and also some piece of code that should be executed after any kind of vehicle is driven. These three methods aren't tied to a particular class definition, and will be called accordingly with just one line of code that calls the method "drive".
The point to all these features is that they allow mapping your problem domain to OOP in an easier way, because the language's limitations do not get in your way. You directly tell the OOP system what do you want it to do; there's less need to do workarounds.
My explanation, of course, is weak compared to the excellent explanation/tutorial here:
I think you can get close to this with modules, for example defining a Drivable module with the drive(Person) method, and including that into Spaceship and Car. But I see how method combination would be more flexible and cleaner in many situations.
Not by a long shot.
> and that supports the full Ruby language
And that's not even counting that.
Your best bet for speed with some remotely Ruby flavored language would be Crystal. Your best bet for parallelism (using JVM threads) with full Ruby support would be JRuby. Topaz is dead. There's the experimental TruffleRuby but I'd rather not bet on this yet.
That's a pretty strange stance. OOP is around and alive, and with the prudent addition of functional constructs, you get the best of both worlds.
To me, the deal breaker about a language is static typing: if the language is dynamically typed (like Ruby, Python and Smalltalk), it's a non starter.
The interesting stuff is happening in the runtimes (See TruffleRuby https://github.com/graalvm/truffleruby )
Was it really cutting edge? I understood it as an improved OOP-only Perl. Rails, on the other hand, did knock me out the first time I saw it.
I guess few languages can be called 'cutting edge', perhaps the ML family including Haskell and (yes, after all these years) the Lisp dialects.
And so it did! https://en.wikipedia.org/wiki/YARV