Ruby 2.5.0 Released(ruby-lang.org) |
Ruby 2.5.0 Released(ruby-lang.org) |
So congratulation and thanks to Matz, and all the other Ruby contributors for creating and maintaining and growing and improving this amazing language that's still my favorite. 2.5 looks great, and I can't wait to see what's in store for the future.
Although I don't really think the language is anything special (i.e. it's a standard dynamic OO language), what really turns me off Ruby is this dogmatic, almost religious aspect of its community.
Take POODR - it's more or less the community bible. If it's not written in POODR - don't do it. If it is - do it that way or else. It's POODR's way or the highway.
According to more experienced Rubyists more than 80% of the Ruby community use Rails. Rails is so widely spread that its development even fundamentally affects Ruby's roadmap.
Now irregardless of what you think about POODR or OO or dynamic types or whatever, a homogenous echo chamber filled with people chanting the same things over and over again is not a good thing.
As a counter example, take Javascript. Yes, it has its warts; its equality table is a joke. Ruby is a better thought out and implemented language in almost every aspect (although I do like Javascript's minimalism better, but that's a matter of taste I guess.) However, Javascript's community is as diverse, vibrant and experiment-friendly as it gets - there are the OO diehards, but there's also React, fantasy-land, macros, monads. People are trying out new things constantly.
Now I know you have monads in Ruby too or flow-like gradual typing libraries or rewrites of Clojure's spec. But at least where I work (and I work with some very experienced Ruby people) those libraries and the ideas they embody would never ever be considered as serious alternatives for anything. POODR or else.
Guess I've been faking it for the past nine years... I mean, I did start a company that used Ruby/Rails as the primary platform. And I've worked the last six years in a shop that currently has a team of about 12 Ruby/Rails developers...
Don't get me wrong, Ruby's a tool in my toolbox; I use it like I would any other tool. I like solving problems. Most modern languages make it easy and fun to solve problems.
I don't like when it's easy to see where a language is encumbered by poor choices (I seem to have a diametrically opposed viewpoint of your opinion of the Javascript community; to me, the redundancy, low quality and churn of community libraries is one of Javascript's greater liabilities). But if it works for you, that's great.
Language Holy Wars are necessary for young, budding languages and young, budding programmers. Language Holy Wars help young communities draw others to their banner and young programmers define themselves. Unfortunately, having causes and "bad guys" is a big part of the underlying way we work as people.
But at some point, once a language's adoption has reached critical mass & once you've reached a point where you're comfortable with the underlying paradigms of programming, these Language Holy Wars get left behind for more interesting problems.
I mean, I definitely have opinions about what language I'd prefer to be working in and why, but at this point, I make my determination of technology based on the right tool for the job, not necessarily my opinion of any given language.
I have never seen any resistance to experiments or diversity in the space. There's a happy path, but there's plenty of room, and welcoming communities, outside of it.
(I like JavaScript, too, for much the same reasons you do.)
Sandi Metz would tell anyone espousing that the text written in POODR is to be taken at face value as gospel that they're completely wrong and completely missing the point. I've actually personally seen her correct this behavior at a conference and at a workshop and I've heard her say it many times in many places and mediums (podcasts, blogs, interviews).
Anyone who says "it's POODR or the highway" should be corrected, because they are very dangerous to any software engineering endeavor.
some comments here mention that they've been doing ruby for years and never even heard of poodr. i think that's less of a point.
it sounds more like you feel stifled at your current job. there's no right answer when it comes to a software stack and it doesn't sound like your coworkers are excited about the same things you are. it doesn't have to be that way! i hope you find a new consulting (or full time gig) that stimulates you intellectually. merry christmas and happy new year.
I've also never come across any particular dogma in the Ruby community -- there are established best practices for formatting code, but individual projects vary widely style and design decisions. Most Ruby codebases I've worked on come with a custom `.rubocop.yml`, and that's it.
Congrats and thanks to all the core devs! :-)
For the cases where you have a tight loop taking up 99% of the actual CPU time it is also relatively easy to hook in C or Rust or whatever. Also, sometimes you hit hardware performance limits regardless of the language you use. We have some streaming download servers written for 99% in Ruby using the libCurl bindings that and they easily manage to fill up the 5 Gbps pipe* per server that AWS gives us.
* You can get 20 Gbps for some instances, but only to other instances in the same group. The biggest to the 'outside' seems to be 5 Gbps.
- Standard Gems 2.5.0 - Default Gems, Bundled Gems // by Jan Lelis, Idiosyncratic Ruby
- 10 New Features in Ruby 2.5 // by Junichi Ito, Ruby programmer @ SonicGarden.jp
- 10 More New Features in Ruby 2.5 // by Tom Lord, Software Developer from London
- Performance Improvements in Ruby 2.5 // by Jesus Castello, Ruby Guides
- yield_self in Ruby 2.5 // by Michał Łomnicki
- Improved stacktrace display in Ruby 2.5 // by Michał Łomnicki
- Ruby 2.5 Series // by Amit Choudhary, Mohit Natoo et al @ BigBinary
http://engineering.appfolio.com/appfolio-engineering/2015/11...
About 5-10% performance improvement by removing all
trace instructions from overall bytecode (instruction
sequences). The trace instruction was added to support
the TracePoint. However, in most cases, TracePoint is
not used and trace instructions are pure overhead.
Instead, now we use a dynamic instrumentation technique.
See [Feature #14104] for more details.Ruby is still one of the most productive languages out there. I just love it. It gives me great joy that 10 years ago I chose Ruby to be the language for my future.
My wish this coming year is to be able to contribute more to the Ruby ecosystem.
Btw I’ve also built something using MRuby this year. The whole ecosystem is just great.
https://bugs.ruby-lang.org/issues/9569
Now to update the "how to generate secure random numbers in various programmming languages" documentation.
e.g.
class FooBar < Foo
prepend_before_filter only: [:create, :destroy] {
request.env["hello.skip_timeout"] = true }
end
was valid in ruby 2.4 but invalid now in 2.5Ruby is a joy to use.
e.backtrace.first lines to e.backtrace.last
Or maybe my favorite which is still good
puts “#{e.message} #{e.backtrace.join(“\n”)}”
Cheers to Matz and all the Ruby contributors :)
This is something I find to be using quite a lot, great to see this.
google-protobuf-3.5.0-universal-darwin requires ruby version < 2.5, >= 2.0, which is incompatible with the current version, ruby 2.5.0p0
[update]
looks like this is resolved by forcing bundler to compile instead of grabbing the precompiled versions.
I worked for a company a few years ago that made security software, with Ruby as a primary language, and this caused no end of frustration...
I forgot where the issue came from (I think it was some issue with bundler or ruby gems), but can I install 2.5 without breaking my set up?
In my daily work (Clojure) I can use different concurrency and typing models than Clojure originally envisioned, via core.async, clojure.spec. This is not some fairy tale or toy/PLT project.
How many languages can fundamentally change themselves without breaking things or getting awkward?
I used said chance, but I try not to disconnect too much from the ruby world as it's such a nice/productive ecosystem.
You never know when your Ruby skills can save the day again!
Ruby is a cluster of inelegant and over concise cludges in the name of expressivity. The fact that it was once most famous for one of the most inelegant hacks - monkey patching - as a core feature speaks to that.
So I totally understand that it’s quick, it’s expressive, and it’s easy to prototype in. Agreed. It’s lost a lot of it’s shine there now but it’s all still true.
But elegant? It’s concise, not elegant.
Just because you can write a monstrosity in Ruby doesn’t make the language itself inelegant.
Ruby, of the many languages I’ve used, has by far the highest potential for code being poetry. You can find solutions that are incredibly simple and understandable due to so much boilerplate being remove from the syntax. Likewise you can write code that’s impressively concise without being inscrutable — I’m continually astonished by how readable Ruby can be.
One exercise in particular sticks out in my mind. Many years back, I implemented the first few dozen Project Euler problems in Ruby. However, I imposed a limitation: each solution had to be under 72 characters (library inclusions are fine), a single logical line, and readable. The end result was surprising at how naturally it ended up working — the solutions ended up being little more than the high-level conceptual approach, translated literally to code. Solutions ended up looking like the following:
(2 ** 1000).digits.sum
(2..10_000).amicable_numbers.sum
1901.to_year.upto(2001.to_year - 1).select {|d| d.mday + d.wday == 1 }.count
Sure, these depended upon injecting new methods into core classes, but who cares? For this problem it led toward incredibly straightforward and readable solutions for these problems. If this were library code I wouldn’t dream of doing it this way, but for application code — why not?I have yet to see any other language with Ruby’s capacity for readable conciseness.
But for example, Ruby's method-based control flow allows for sophisticated ideas to be expressed in a way that's clear but doesn't demand undue attention. A while back I needed to implement a common structure in Python for basically "repeat this operation with increasing sleep times until it succeeds" in the context of a particular library. Every option I could come up with was fairly inelegant, either requiring more attention than it deserved or being excessively oblique or just reading like a neural networks trained on Python, and none of the senior Pythonistas at my work could come up with anything much better. But I could clearly picture how to do it in Ruby, and it wouldn't have had any of those problems there. The extra expressiveness allows it to express the idea elegantly.
It’s certainly problematic when used! But the feature itself is elegant and the opposite of a hack. Disallowing monkey patching requires extra conditions and rules, not less.
Rails also uses minitest with fixtures by default, I migrated to it recently and I really like the simplicity.
allow_any_instance_of(Set).to receive(:member?).and_return(true)
<rest of test code>
Contrast this for example with testing IO monad code in Haskell, where the best practice is to define a new monad 'underneath' your original monad stack, rewrite all your functions signatures to have a type constraint (of your new MonadIO type) and then switch out functions for their mocked equivalent as required by the test. Rspec can do the same switching out on any object or class, without any code required outside the test code. (Although as far as "handle with care" goes, monkeypatching the 'send' method has to score pretty high)Because of its use in scripting on the JVM(e.g. glue code and Gradle builds), Apache Groovy files are usually stored in the file system as text. Each time they're run, they are "compiled" into JVM bytecode. Although you can get pre-compiled .class and .jar files for Groovy, it's not common for people to build large systems with it.
[0] https://github.com/rails/rails/pull/27757 [1] https://github.com/rails/rails/pull/16773
TLDR: not as nice as RSpec but close.
Right, well that probably answers the question about what they thought the magic is.
I’ve never encountered anyone as passionate as @pka suggests. Perhaps POODR is popular where they work but it’s far from universal amongst rubyists.
In Python I imagine you could just do something like this:
from time import sleep
sleep_increment = 1
sleep_time = 0
success = False
while not success:
sleep(sleep_time)
success = try_thing()
sleep_time += sleep_increment def backoff(wait = 5, exponent: 1.5)
yield
rescue BackoffError
sleep(wait)
wait = wait ** exponent
retry
end
backoff { connect_to_a_thing }
This is trivially composable with any other control flow you might want to write in Ruby.Personally I find the Python approach inelegant. Can it be composed? Why am I having to work with low-level looping constructs instead of higher level control flow constructs that map more closely to the task I’m actually trying to accomplish?
Same thing goes for any non-functional looping at this point. Why am I having to care about loop indices, incrementing counters, creating result arrays and inserting items into them, etc.? It’s (almost) 2018 and people are still writing low-level looping logic for the n-billionth time. Worse, people have to read it and parse it for the n-trillionth time to figure out which looping idiom is being used, instead of being able to see at a glance that something is being mapped, selected from, reduced, etc.
def backoff(wait=5, exponent=1.5):
while True:
yield
sleep(wait)
wait = wait ** exponent
for backoff():
connect_to_a_thing()
Here's the question: do you need exponential backoff in more than one place? Because if you don't, bundling all of that doesn't buy you anything and the original works just fine.> This is trivially composable with any other control flow you might want to write in Ruby.
And it is actually trivially composable with other Python control flow, it's just a backoff iterator, you can drive it however you want, or compose it with other iterators (e.g. enumerate() to know which instance you're on, islice to stop after a certain number of tries, …)
(1) might just be a matter of taste -- that 'retry', to me, makes me now have to step back and think "oh, I'm retrying something now? what exactly is being retried here?" Having it all wrapped up in a 'while' loop makes the intent explicit right from the get-go.
(2) I agree is nice. It would be great if you could do this:
with backoff():
connect_to_a_thing()
but you're not allowed to 'yield' twice inside a context manager. However you can get damn close (and fully composable) by wrapping the connection logic and the retry logic in functions: def connect_to_a_thing(url, access_token):
...
def backoff(connector, wait=5, exponent=1.5, *args, **kwargs):
success = False
while not success:
try:
connector(*args, **kwargs)
except BackoffError:
sleep(wait)
wait = wait ** exponent
else:
success = True
backoff(connect_to_a_thing, url, access_token)
Or you could be even more explicit with recursion: def backoff(connector, wait=5, exponent=1.5, *args, **kwargs):
try:
connector(*args, **kwargs)
except BackoffError:
sleep(wait)
backoff(connector, wait ** exponent, exponent, *args, **kwargs)
As for your point about loop indices, Python generally has wonderful support for not worrying about loop indices and counters. I'm also not sure how that applies in this case; you still need to increment the value of 'wait'. Then again... def exponentiate_forever(value, exponent):
while True:
yield value
value = value ** exponent
def backoff(connector, wait=5, exponent=1.5, *args, **kwargs):
for wait in exponentiate_forever(wait, exponent):
try:
connector(*args, **kwargs)
except BackoffError:
sleep(wait)
else:
break
But please don't do that.They also read awfully even with an editor designed for them. They aren't human-first languages. S-expressions are easy for a computer, they are hard for a human. So, yeah, that can be improved, too. "But you can do it with macros"--other people won't, and so you are thus devolved to the minimum set everyone can agree upon, and it's gonna be awful.
And so there is room to grow outside of one's parentheses, too.
I've used Python, C, C++, C#, Java and Pascal extensively. I can safely say Common Lisp allows you to write the most readable code of all languages i've used, and i'd expect this to be the same for most other lisps.
Since they are hugely flexible, they allow you to write code in such a way that the problem and solution are expressed in the most explicit and straightforward way.
Best of all, emacs/Cursive lets you trivially transform a sexpr into a threading form, and back. So one doesn't even have to do much effort for refactoring nested (a(b(c(d calls.
You're transforming a linguistic readability issue into a cultural problem of agreement and that's a waaaay harder problem to solve, IMO. Lisps are cool. But every problem raised to "cultural problem" is so much harder to solve. (When was the last time you saw an indent war in Ruby?)
But I make those 'things' within lisp rather than by exploring new languages. If done sensibly, colleagues will be able to use those custom abstractions too.
This is my experiencie too. S-expressions + macros is an amazingly powerful combination.
Point taken - apparently I mistook the particular echo chamber I happen to be in at that moment for a more general symptom. Glad to hear!
I do hope that your current situation gets better or that you find somewhere that isn't so preoccupied with navel gazing.
I often share it with non-ruby devs because it’s about design much more than it is about ruby.
Here are a couple of talks by the author which examplify her style of thinking and approaching problems.
Besides Sandi Metz, another Rubyist that I rate highly for delivering clear ideas about design is Avdi Grimm. His RubyTapas series quite radically changed my approach to building applications in Ruby.
Observe that programming in Rails doesn't intrinsically require an OO mindset. But when I reached the limits of the framework, knowing a thing or two about building rich OO domain models served me very well and helped avoid anti-patterns.
At work we use cljfmt (similar to gofmt) plus a variety of hacky formatters and conventions. It works for us and I hope to open-source part of our stack at some point!
The experience is similar to that of Rubocop - which btw is the reason why there aren't indent wars (or similar) on Ruby.
Great to decomplect how code is written (however you please), from how it is committed (autoformatted).
All of these allow creating new extension methods of existing types, albeit by three different methods.
I'm assuming that your "2001.to_year - 1" is "the date time for 2001 minus 1 day"
rust (traits)
(pow::<BigInt>(2u8, 1000).digits().sum()
(2..10_000).amicable_numbers().sum()
1901.to_year().upto(2001.to_year() - 1.to_day()).days().iter().filter(|d| d.mday + d.wday == 1).count()
Haskell (type classes) sum . digits $ 2 ^ 1000
sum $ amicable_numbers [2..10000]
count $ filter (\d -> mday d + wday d == 1) [year 1901 .. year 2000 - day 1]
C# (extension methods) BigInteger.Pow(2, 1000).digits().sum()
Enumerable.range(2,10000).amicable_numbers().sum()
1901.ToYear().UpTo(2001.ToYear() - 1.ToDay()).Days().Where(d => d.mday + d.wday == 1).Count()
JavaScript (changing prototypes) bigInt(2).pow(1000).digits().sum()
_.range(2, 10000).amicable_numbers().sum()
1901.to_year().upto(2001.to_year().minus(1)).days().filter(d => d.mday + d.wday === 1).length()I, as a developer reading your code 6 months later, care.
When something fails, it's nearly impossible which of the magic methods were injected by which magic library.
pry> show-source SomeClass.class_method
pry> show-source AnotherClass#instance_method
# List an arbitrary object's class methods, instance methods, methods mixed in by included modules
pry> cd some_object
pry> ls
The runtime knows how to execute your program (it's not random) so everything you want to know is available. there's heaps of good tooling for finding the
method source and docs dynamically
I know, but this is a huge problem with a lot of code I see in the wild because this stuff is (ab)used so widely in Ruby-land.If I have to run code just to see where `Foo.bar` is defined, that makes things... about an order of magnitude harder to understand. I mean, that's really tough thing to do in anything but a trivial codebase.
This is nearly 100% the fault of developers, not the language itself, but I would suspect that most Ruby developers spend a significant amount of time dealing with things like this because it's how the ecosystem rolls.
Determining which method responds to which message is only possible in an instantiated runtime, but that’s true for any late-binding programming environment. Complaining about it tells us more about the complainer than about the language.
If you're writing a library doing things like this is a bad idea (except in very limited circumstances). And to what seems to be every non-Rubyist's surprise, virtually no libraries in practice actually do this sort of thing so there are never problems in practice.
The times I do this sort of thing in my own application code, I put the methods in a module and have a hook that raises an exception if the methods already exist when the module is included. This is the best of both worlds: I can add features that don't exist, but am informed immediately when my app launches if such a method has already been defined.
The iterator is infinite on purpose (it has no reason to be finite).
You'd terminate it from outside, either when the operation succeeds, so the example loop should more properly be something along the lines of:
for _ in backoff():
try:
c = connect_to_a_thing()
break
except ConnectionError:
pass # retry
or you'd use composition to e.g. stop after a set number of tries: for _ in itertools.islice(backoff(), 5):
# do stuff
most likely a combination of both.People who don't use Ruby seem to think this is a huge thing that you run into constantly. It's not. People are for the most part pretty responsible with these things.