Earlier quoted context omitted.
See, 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 sh…
Disagree 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 co…
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::(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()