4 ms·
Ruby may not be the cool thing in town it once was, but it remains my preferred language for prototyping ideas - purely because of its elegance and expressivity
by nileshtrivedi 9y ago
Ruby may not be the cool thing in town it once was, but it remains my preferred language for prototyping ideas - purely because of its elegance and expressivity. It truly delivers on its fundamental goal of "developer happiness". A lot of ideas from Ruby have gone to other languages (CoffeeScript, Elixir) and many web frameworks are modelled after Rails.
Congrats and thanks to all the core devs! :-)
- deleted 9y ago[deleted]
- abritinthebay 9y agoSee, expressive I totally get. Absolutely. But elegance? Don’t understand that one. 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.
- chc 9y agoI think there's a lot about its expressiveness that's elegant. You can't pick one inelegant practice and define the entire language by that — nothing would pass that test. 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.
- nerdponx 9y agoWhat would the elegant Ruby version look like, and what was inelegant about the Python version? 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
- stouset 9y agodef 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.
- masklinn 9y agoNothing precludes a similar approach in Python: 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, …)
- nerdponx 9y agoWhat's an example of one of those kludges? "Ruby concise" at least looks elegant, whereas, say, "Perl concise" is hideous.
- stouset 9y agoI’m continually impressed by how understandable golfed Ruby tends to be, especially when compared to Perl. Golfed Perl is completely inscrutable, whereas golfed Ruby is often times no less understandable than a longer version.
- abritinthebay 9y agoI disagree it even looks elegant. Short? Yes. Better than Perl? Sure, but even Perl fans wouldn’t call it a pretty language.
- ouid 9y agoArguing that something isn't elegant is a lost cause.
- stouset 9y agoDisagree 1000%. 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.
- AaronFriel 9y agoAre you familiar with Rust, Haskell, C# or JavaScript? 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()
- chrisseaton 9y agoI don’t think you can call monkey patching inelegant or a hack. Monkey patching is the absence of extra rules - not allowing a method to be defined more than once - and the prescence of consistency - all methods can be redefined. 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.
- rajangdavis 9y agoNot to sidetrack the conversation, but will you be announcing anything regarding the GraalVM? It seems like there is something announced every year, would love to hear the progress from last year
- chrisseaton 9y agoYeah I’ll try to post something to http://mail.openjdk.java.net/mailman/listinfo/graal-dev http://mail.openjdk.java.net/mailman/listinfo/graal-dev