Ruby in Twenty Minutes (2006)
ruby-lang.org
ruby-lang.org
This thread is really opening my eyes to the sheer vitriol that gets directed at Ruby outside of its own echo chamber.
I get that it has performance issues (to be addressed in Ruby 3) and interest in Rails is now less than half what it was at its peak.[0] Everyone has very strong opinions, and when people start soapboxing like they are in this thread, nobody learns anything.
At this point, honestly, I just think the rest of the community could use a little bit of Ruby's characteristic niceness.[1]
[0]: https://trends.google.com/trends/explore?date=all&q=%2Fm%2F0...
You are correct that there are latencies involved that don't involve executing code, however my experience with Ruby, Python, and PHP is that they contribute a significant portion of the total latency in the most basic CRUD LAM(P|R|Py) stacks. Once you start getting into much heavier applications such as CMS's or eCommerce app code execution can easily dominate request latency by more than an order of magnitude.
Look, I spend a fair amount of time looking at the performance monitoring tools for the Rails apps I deal with. Ruby execution time just isn't that big of a deal most of the time. And when you have a monster of a page and it is an issue, you use caching, like you do with every other language/framework.
You really note the difference with that load falls down and then there are this weekend all nighters converting script code into C.
Ivo Anjo (now working for Amazon) has talked about their use of JRuby at TalkDesk: https://ivoanjo.me/blog/2017/01/29/benchmarking-jruby-invoke...
However I did mentioned "on their canonical toolchains" on purpose, as not many in the Ruby community would welcome Java on their computers and rather fork a C compiler as pseudo-JIT.
MJIT uses C to mimize the maintenance burden on the core team. Using LLVM would mean either pinning to an LLVM version as Rust does or supporting what would probably be 6 different versions of IR to support as far back as say, Ubuntu 14.04.
As for MJIT, it is not like LLVM would be the only way to implement a JIT compiler, plus the impact of forking a C compiler and linker is quite considerable versus an in-process JIT.
The alternative proposal which Evan Phoenix explored was to compile the VM and standard library into LLVM IR and keep it for use when JIT compiling Ruby methods.
If you look at the JIT compiler in Racket which is maintained by a small team like CRuby but does use a custom backend, then it has some big limitations like a maximum of 3 function args.
Implementing something like C1 would be an enormous amount of work.
That being said, I enjoy Ruby a lot, and mostly enjoy working on Rails codebases (depends on how the front end is built, as Rails particularly _doesn't_ prescribe any form of convention here). I wish they worked on improving the front end story like Laravel has.
And everyone is coming at this conversation like caching isn't a thing that you do on any high-traffic site (and lots of low-traffic ones too).
Speed stats - https://www.techempower.com/benchmarks/#section=data-r14&hw=...
https://github.com/reactjs/react-rails
Sets up Webpack and directly integrates into your templates with ERB tags like
<%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
(First argument is name of component, second argument is a hash of props)
Easy as pie!
(I know Django is a thing, but that has always been in the shadow of Rails, and rightly so.)
I looked into Ruby and it struck me as being a truly aesthetically pleasing language, and since it espoused the "principle of least surprise" -- with caveats, naturally -- most Ruby code tended to be straightforward to read.
Python on the other hand, while clean -- I came from Perl -- had a fair bit of ugliness like the "self" argument in class methods, and the "dunders" in dunder methods (__init__). That said, the Python ecosystem, especially in the numerical computation space, was far ahead of Ruby's at the time, so I chose Python. It worked out really well and allowed me to accomplish what I needed to. To this day I have no regrets choosing Python.
Compared to many languages (like Haskell etc.) Python's design isn't the most aesthetically pleasing or orthogonal or clean. But being a Dutch design, at least initially, it was very pragmatic. And Python is by no means ugly on an absolute scale, on the contrary. It’s just not as beautiful as some others.
Python's main advantage is the energy behind it: to this day there are no converged alternatives to Numpy or Pandas on Ruby.
I can't help but wonder that if in an alternate universe/timeline, Travis Oliphant, Pearu Peterson, Wes McKinney and others happened to have encountered Ruby first, we might have a different de facto language for scientific computing and data science.
Also beginners don’t have to mentally blot out in their heads the self argument when calling a method (“you mean self isn’t the first argument?”). Debug messages are also more consistent (“the debug message says my method needs 1 argument. Isn’t self right there?”)
I accept Python’s explicit self for what it is (Python’s philosophy prefers explicit over implicit), and don’t have trouble with it but aesthetically it deviates from most OOP languages out there. It’s a valid choice for practical reasons but I would also say that an implicit “this” is an equally valid choice for aesthetic reasons.
Here’s a survey of this/self choices: https://en.m.wikipedia.org/wiki/This_(computer_programming)
At some point I read somewhere that the whole point of upvote and downvote on Reddit was for “contributed to conversation” (upvote) or doesn’t (downvote).
That, to me, makes sense.
Disagreeing is part of what promotes good, challenging discussions. It also buffers us from external influences controlling the crowd of “agree’ers”. By promoting and encouraging differences of opinion or view, we make it harder for someone to come in and sway the crowd.
btw, our little subthread here is off topic and may be downvoted for that. (rightfully as we aren't contributing to the actual topic)
I never had a problem with ruby map/reduce, but any expression more complex than a simple loop becomes hard to write with list comprehensions.
On the plus side, python has type annotations and static type checking with the help of mypy.
It has async/await which was a good strategic move to give javascript users a sense of familiarity. Ruby is somewhat lacking in this aspect.
By design, at that point write a function or proper loop. This provides an opportunity for documentation.
How much of your like/dislike do you think comes down to familiarity with the language?
When I was first learning python, I definitely didn't like it as much because I was unfamiliar with some fairly basic syntax. Exactly the feeling that you're describing (I was coming from matlab). I've been using python for two years now and expressing most 'programs' feels like second nature. I.e. if I am to describe an algorithm on a whiteboard I may as well do it in python because then I don't have to worry about coming up with pseudo-code conventions on the fly, and there is little syntax getting in the way of me expressing semantics.
Based no the link, it seems like ruby is largely similar to python, but it has slightly different choices. I'm curious what someone who's experienced with both would have to say about the stylistic features of the languages (ignoring libraries).
Python does not feel natural at all. And I don't mean the indentation, that's in your face enough that it can be handled fast. But Python is just everywhere almost like you'd expect, only to still be different whenever it can. Dicts for example, why is that in there instead of a Hash or what I'd call a assiociative array? Using list instead of Arrays, as if it were a lisp, only that the list behaves like an array with different syntax, and Python is not lisp like at all. Null is of course not null (I already disliked ruby's nil), it's None. Compare how easy ruby makes range, and how inelegant Python makes that.
In the end none of that matters that much and discussing it too much probably only leads to a flame war. What mattered to me: My python program (an audio player for the tray) was completely unstable, it ran into multi-thread issues without me ever understanding why and how to solve them. My first ruby program was enough to pass my employer, my second one is still online (and one of my active projects linked in my profile).
If I want got get something done and have it work well, I use Ruby. Though fact of the matter for ML or even just statistics the ecosystem is way less nice and I will be forced to use Python next time, my try to use Ruby during my last encounter with ML just failed.
I looked up the select/filter syntax in ruby. I guess the main difference is that the name of the element you're iterating over is left implicit compared to comprehensions, but equivalent to filter.
details.select{ |item| item[:qty] != "" }
[item for item in details if item.qty != '']
filter(lambda item: item.qty != '', items)
I'm curious if the implicitness is cumbersome when you need to do a selection that combines multiple lists. How would you express the third line of the following in ruby? A = range(65,69)
B = ['A', 'B', 'C', 'D']
[a for a, b in zip(A, B) if b=='C'] A = (65..69).to_a
B = ['A', 'B', 'C', 'D']
A.zip(B).select{|x, y| y == 'C' }.map{|x, y| x }That looks equivalent to python without comprehensions.
As far as I can tell the difference in the expressiveness of `map/filter/reduce` is mainly about whether you like or don't like comprehensions. Do you have any examples where you believe ruby has cleaner syntax?
Comprehensions don't replace reduce, they are equivalent to a combination of map, filter, and flat_map. The difference is not just about comprehensions, since map/filter/reduce, and friends, in Python are functions, where in Ruby they are methods; so in Python when you can't do it all with comprehensions (reduce, zip, etc.), it's either imperative loops or functional notation (inside-out), while Ruby uses method call notation, which results in operations reading in the order of application.
I definitely like how method call notations can be read left-to-right rather than inside out.
Now I'm curious why python developers decided not to add these 'transformation methods' to all Iterables.
It was one of those unexpected moments of extreme enlightenment I haven't experienced in a while now.
not entirely sure what the "in twenty minutes" bit is aiming to achieve here
I volunteer to teach an intro to Rails class to folks getting ready to graduate a local code school and always enjoy watching their facial expressions as I live demo in about 15 min what they just spend the last couple months learning how to implement in the node/JS stack.
Plus, Ruby is just a joy to work with. Hard to put a price on enjoying the language and framework you work with.
As a side point though, it is much less mature than rails.
Just going off the age, and number of: commits/releases/contributors.
Its GitHub pulse is also obviously not as “rapid”
Rails also has a rich set of libraries in the form of gems - which AdonisJs most likely doesn’t rival
Rails is also used/has been used in production by some major companies. Perhaps AdonisJs has been too, but it can’t be as many
Nest has a bit more mindshare right now - with Triplebyte, etc using them
The good part is that it uses Express under the hood (which probably is ending up becoming the Rack of JavaScript middleware) ...so you get the third party ecosystem compatibility.
I'm familiar enough with JS that i would primarily use JS now for web stuff, but Ruby is quite a nice language to use, and I wouldn't be surprised if its easier for beginners to learn than JS.
In any case I think that skills in any one of the popular 'big' higher level dynamically typed languages (Ruby, JS, Python) are fairly transferable to the others too.
I feel too bad that Python had taken over the position of Ruby more or less.
Also my favorite: https://learnxinyminutes.com/docs/ruby/
EDIT - I asked 9 months ago and the top comment recommended pipenv and flit:
https://news.ycombinator.com/item?id=18612590
I just use pythons integrated venv and pip, which work fine for me. However, it was in that same thread (the link posted in this comment) which suggested poetry and another I believe, which I do feel like trying out.
Definitely give poetry a shot, it's really good. In particular, I enjoy how the maintainer engages with the community and is receptive to feedback. He's pretty good about adding features to satisfy the users, rather than handwaving legitimate concerns in one-line responses.
I haven't had to deal with Ruby in a couple years though.. I don't miss mixin hell, or chasing down a code line from a strack trace that doesn't exist because it was generated at runtime(I hope your ears are burning Chef).
There's too much magic and Ruby is seriously sllllooowww. Slower than PHP, Perl, and Python. The main draw of Ruby was rails, which is functionally obsolete for modern front end frameworks like React and Angular. It's the OSS version of Asp.Net WebForms
Using rails-api as a backend with your choice of frontend is still a viable option. Perhaps it’s not one’s first choice these days but it’s far from obselete.
I have three languages I use. My web sites are done in Rails because it's fast and logical. One site has a Vue front end, only on a couple of pages where I need the JS fancy stuff. Most of my pure APIs are done in Flask because it's lighter weight. I use React Native for my native apps. I tried using Express.js for the APIs backing these apps but I could never get it all working right. I ended up rewriting it in Rails and now it's rock solid and fast as hell.
I'd also like to mention most web development out there is still right in line with even old school PHP and does not need React or Angular or anything fancier than Rails. YAGNI.
Devise does a great job of it though - https://github.com/plataformatec/devise
https://api.rubyonrails.org/classes/ActiveModel/SecurePasswo...
Because on production servers we have 10 Ruby front ends for a single Postgres database that barely sweats. At the same time, we have a lively Hibernate setup in crufty java using 4 front end servers and overloads our database regularly.
Ruby is slow as hell, to the point that it costs a lot more money to run servers vs ancient J2EE junk. V3 speed increases will be interesting if it's 10x+ . If not, Ruby is dead. Even Python and it's crazyness is far faster and somewhat easier to use.
Ruby is doomed
For a lot of people (and businesses), Ruby more than suffices. If it doesn't, other languages always exist. So no, Ruby is far from doomed–one just needs to evaluate the pros and cons of Ruby vs something like Go, etc. Ruby with Rails isn't hype or sexy technology, but it is quite mature and robust.
Sometimes Ruby's faster, sometimes Python is.
However all those benchmarks are probably useless. They are not testing how the language is used or should be. The trick with all the scripting languages is to make the CPU spend most of its time in the C code inside the standard library or the implementation of the native constructs of the language with as little overhead as possible.
Example: you don't want to do numerical computation using plain Python, you want to use Numpy.
You also want to learn very well all the ways Ruby's standard library can group operations in a single method call saving time compared to naive multi method chains.
When it reaches 1.0 and becomes stable I’d like to work with it again. For small simple APIs raze was great.
My problem is: I already _know_ that LISP is the best language(-family) ever and probably nothing in future will change that.
And meanwhile I accepted python for daily use because it has so many libraries.
i feel that newer languages add a more complex syntax without necessarily simplifying the the process. though here i feel that ruby and python have a rather nice syntax, and it's debatable which is actually easier to read.
for my part, i like the minimalistic syntax of either lisp or smalltalk, because they make it easier to reason about the code once you get used to it because there are not so many syntactic elements that i need to keep track of. but both do take some getting used to.
maybe ruby and python today feel easier to pick up because we start learning with rather complex syntax.
while the basic bricks are much easier to understand, maybe it does take more skill to use them to build complex systems than if you have a lot of specialized parts...
One of my previous teams at one of the big tech companies who's products or services you likely use every day had an entire suite of tests for data pipelines that were quickly implemented in Ruby. That system is still in production today.
I guess none of the folks on that team were "real developers", huh?
A bit of YAGNI is clear here.