Preferences

I've probably not tried hard enough, but I always got zero joy from writing Ruby. Way too much magic.

Totally valid point, but I do think magic is more a property of the clever (usually reflection-based magic) things people make with Ruby, less so the language. The draw towards magic is actually because of the logically-consistent object model Ruby is built around that I find to be less magical and edge-case-filled than other script-y languages.

If you just use it as a glue language to call out to other things, prepare data, and iterate over results: it's pretty clear and concise.

(I do personally like the reflection-magic in a lot of Ruby apps, so I might be overlooking something that feels normal to me, but is some very weird behaviour to anyone else!)

How is pythons object model less "logically consistent"? Multiple inheritance is dangerous but I'm not sure if its logically inconsistent. And it doesnt have the issue that ruby has of procs not being objects
Ruby borrows a lot from Smalltalk. Everything is an object, including things that are normally keywords elsewhere like Class or Module. There are no public properties on objects, only methods, which is technically only « messages » and object can receive.

Ruby does well with metaprogramming magic because most of the languages own keywords and concepts can be rewritten at runtime. They’re implemented AS Ruby code.

I would say it’s logically consistent because there isn’t as many « special » things. Python’s def keyword is special. You can’t make your own, nor can you hook into it. In Ruby, that’s just a message being passed to the current scope’s object. You can do anything you want to it. Ruby plays by a pretty consistent rule book.

In python everything is an object.

I'm sure there are minor exceptions or arguable cases but that's also the case with Ruby. Most infamously with Proc.

Classes are objects in python, usually instances of class called type or a subclass of type(usefulfor controlling class creation), this is called the metaclass. A constructor call MyObject() is basically just the __call__ method of the metaclass.

Modules are also objects usually of type types.ModuleClass or a subclass although really you can stick any object in sys.modules dictionary and have it act like a module and import it.

Sure it doesn't use messages instead attributes whether field or methods both go through the same lookup method __getattribute__ which goes up the class inheritance chain in an OO manner. There's also __getattr__ for more method_missing like access instead of overriding every object attribute access.

A function or lambda is an instance of function class although I don't think you can't modify or override the function class I think you can hook it to log it.

You can also do all sorts of stuff by hooking module import and rewriting the ast. Or more easily you can decorate/wrap the functions in another function object.

It's true that you can't modify c based classes but you can do a lot of magic in python, people usually just don't because unnecessary magic is frowned on. But sometimes it's useful like the way pytest rewrites assert a==[1,2,3] to print a nice error message with both variables https://github.com/pytest-dev/pytest/blob/main/src/_pytest/a...

I forgot to mention

There's was recently a cool article on things to you can do with python decorators

https://www.hackerneue.com/item?id=42918846

Basically the python function is created as a regular python function but then passed to a jit decorator

@something.jit def some_func(): ....

Which takes the source code and uses it as a dsl for something else compiles it say something to run in the GPU and assigns it the name of the original function. Technically you haven't hooked creation of of the func just replaced it with a wrapper or in this case a related function that doesn't call the original but it does the job.

Same. I've been using Ruby+Rails for the past year as my company's entire back-end is Ruby. I found it to be ugly and almost intentionally designed to be difficult to read. The tools for Ruby (RubyMine, Ruby LSP for VSCode) are slow and unreliable. It also seems that debugging Ruby works sometimes, but not always, which is ridiculous. RubyMine has its own wacky debugger support, which breaks whenever there's a new Ruby release. VSCode tries to use rdbg, but frequently stops working.
> Way too much magic.

Are you referring to Ruby, or specifically Rails?

At least for me - Rails solidified my distaste, but Ruby gets tarnished by it.

It's like seeing a c++ codebase riddled with macros. Is c++ directly responsible for the madness? Probably not, but the tooling allowed it.

And Ruby takes a double whammy on this front because Rails was really what drove the popularity. Hard to describe the frustration of hitting a very large Rails codebase and literally not even being able to find the definition for a class because it's got a fairly generic name and is getting auto-loaded in the bowels of the codebase by someone who thought they were clever like 7 years ago.

It's like a special version of DLL hell. Or all the pains of global window/self vars coming from script tags in JS, but at least that gave some breadcrumbs, and the ecosystem is generally moving away from it even if ESM is still painful in a lot of ways.

Either way - I don't like hidden things. I'd much rather see the sausage get made then try to save a couple lines of typing, and the older I get, the more I judge languages on the simple metric of "How well does text-based search work for finding relevant code?". Rails performs really badly on that metric.

Ruby except with Python style imports where you had better god damn explain in explicit detail where every symbol in the file came from would pretty much be my ideal. Python from blah import * is banned in pretty much every codebase but in Ruby that, or worse autoloading, is all you have.
I don't think that's a fair comparison.

In Ruby, you always use the global name (with caps) that normally matches the library with possibly some nesting. (exceptions exists, but its also possible to add globals in Python)

Unless you are talking about include, but thats for mixins, which are snippets of reusable coee you can add to you class.

It doesn't feel at all as dirty as `from blah import *`.

My problem also. Loved Ruby's object model, but it seems the metaprogramming gives too much freedom to run free and wild. I had a hard time understanding understanding how some gems even achieve, as they crisscross across files and other gems.
Too much magic? Ruby is super straightforward and consistent.

Unless you're talking Rails, which indeed uses a lot of metaprogramming under the hood and is quite different than programming in basic Ruby.

It's only magic if you don't understand how it works.
I agree. And it's impossible to follow. No type hints, missing syntax, generated identifiers all over the place, etc. Awful awful language. I'd rather write Perl.
> missing syntax, generated identifiers

I’ve been writing Ruby for almost ten years now, and I honestly have no idea what these refer to.

1. It leaves out parentheses in places where they really should be there for clarity. Ok it's not nearly as bad as e.g. OCaml, but it's still a downside.

2. Basically Ruby code seems to favour magically generating methods and variables based on other strings, which makes them impossible to search for.

Other languages sometimes do that too, e.g. ill-advised __dict__ Python tricks, or with macros in C++ or Rust. But it's definitely worse in Ruby, and it's a common complaint (search for "magic" in these comments).

I literally have given up following Gitlab's code before. That never happens in better languages, e.g. I can easily follow VSCode's codebase (Typescript) or gitlab-runner (Go).

> 2. Basically Ruby code seems to favour magically generating methods and variables based on other strings, which makes them impossible to search for.

You might be talking about Rails here and not Ruby per se.

I happen to have just come across another case of this, not in Rails.

In Asciidoctor, which is unfortunately written in Ruby, where is `convert_inline_anchor` called from?

https://github.com/search?q=repo%3Aasciidoctor%2Fasciidoctor...

Nowhere apparently!

Until you eventually find this monstrosity:

https://github.com/asciidoctor/asciidoctor/blob/8d3f6230c964...

You might be right, but Rails is always touted as one of the best things about Ruby...

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal