97 points · by ciconia · 1y ago · 56 comments
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!)
Are you referring to Ruby, or specifically Rails?
Unless you're talking Rails, which indeed uses a lot of metaprogramming under the hood and is quite different than programming in basic Ruby.
I’ve made peace with python, accepted that I need to use it, but I hate it. Death to for loops.
The problem with DSLs is that you now have a different language for each project you have to maintain.
Each time you come across some little DSL that shortens the original writers work by a few lines (at most), you have to read it carefully, and in depth, to understand what was intended.
I'm turned off by Ruby for this reason alone. If I want the ability to throw little DSLs all over my code, Lisp does it better and more readably.
I'm not saying this to attack the language, just pointing my current mental picture to ask: what's the magic everybody loves? I know there is something there because it's an almost unanimous view among ruby devs, so I want to get it.
You’re probably talking about the ability to reopen (or “monkey patch”) classes (which is why defining the same class again can’t be an error). That’s a powerful tool if you use it carefully, especially for debugging or hacking on someone else’s code.
> blocks feel like a more cumbersome/limited version of lambdas
Yes, that’s basically what they are. You could totally write JS-like code and pass even multiple lambdas to methods. However, the most common use case — passing a single important lambda (e.g. to a “map” or “each” method) — gets special treatment and its own language feature.
> what's the magic everybody loves
For me it’s the “batteries included” factor. Ruby can do a lot out of the box and most of the interfaces are well designed with tons of useful methods with descriptive names. It feels like someone cares about my experience and is trying to anticipate what I might actually need.
Also the object oriented mechanisms are easy to understand and don’t feel weirdly bolted on like in Python.
Ruby makes message passing first class. That just changes how you think about programs. In exchange you give up passing functions so our anonymous functions are our blocks (actually just another object that can receive messages). So you don't `list(something)` you `something.list` and that lets you change what `.list` does depending on who `something` is very easily.
Ruby's defining feature is that the line between language author and program author is razer thin. You can completely change the language yourself by extending core classes. This is why we have `1.day` in Rails even though its not supported in the main language. DHH (author of Rails) could add that without consulting Matz (author of Ruby). So lots of stuff gets prioritized to make developers happy because its easy to add.
In Ruby the messages you receive are passed up the chain of ancestors. Your ancestors are a linked list of classes going back to a root class like `Object`. You can modify this linked list at will with mixins and inheritance with complete control (should I go before or after this other receiver).
Ruby's REPL and debugging experience is amazing. I often keep one tab with an `irb` or `rails console` open to sketch things while developing the code for it elsewhere. I'm also always inside a debugger to figure things out. When I'm in Rust or Python I'm met with a very different environment.
Already in early 2000's CERN was scripting their builds, Fortran and C++ tooling with Python.
Their Grid Computing tutorials, predating what we now call Cloud, already used Python.
I don't imagine the overhead will be too bad though, so it may decrease latency while keeping throughput essentially the same.
Of course you'll want to benchmark on your specific load. For example, at my day job it'd make no difference because we don't use threads, each Passenger worker has just one thread and handles one request at a time.
Python’s “new gil” (it’s some 15 years old...) uses a similar scheme, with a much lower timeout (5ms? 10?), but it still suffers from this sort of contentions, and things get worse as the number of CPU threads increase because they can hand the gil off to one another bypassing the io thread.
Well, _scaling_ is queuing. But other things: cache hit rates, data packing efficiency, efficient use of hardware intrinsics, etc, don't relate to queuing.
* An arrival rate of requests * A processing time for each request * A corresponding queue length when a new request comes in before the current one is done being processed.
So anything that affects processing time affects queueing. Cache hit rates, data packing, etc., all affect processing time, but processing time is in the context of a queue.
Algorithmic complexity affects the processing time of each request / task. Knowing the latency distribution is crucial in understanding the queueing characteristics of the system, and the algorithmic complexity will greatly affect that distribution.