News for hackers. Stuff that matters.
Re:Rust is surprisingly expressive by kybernetikos on Saturday December 28, 2013 @04:30PM (#6976703)
Yes, I took the fact that this was not a global modification of a widely used data type as a given, since to do so would be crazy in any language.

And sure, you can always look up in the type system or (in a less well typed language) the documentation to see what it does. The point of writing clear code is that doing so should be a last resort and not something you force on developers in order to understand what's going on.

Readability is what we're talking about here, and TimeChange.days(2) or new TimeChange(2, Days) are both more readable options than 2.days() because a programmer knows what is happening without querying information that isn't written in front of them.

Re:Rust is surprisingly expressive by pcwalton on Saturday December 28, 2013 @07:06PM (#6977314)
> And sure, you can always look up in the type system or (in a less well typed language) the documentation to see what it does. The point of writing clear code is that doing so should be a last resort and not something you force on developers in order to understand what's going on.

Well, all you have to do in Rust is to look at the imports, since you have to import the trait defining the method at the call site. Because Rust modules never span multiple files, and imports must be at the top of the block that they're used in, that import will always be before the call. There are also no global imports in Rust (at least, without using a deprecated feature flag), so the trait in question is always named explicitly.

Re:Rust is surprisingly expressive by comex on Saturday December 28, 2013 @05:08PM (#6976856)
> Yes, I took the fact that this was not a global modification of a widely used data type as a given, since to do so would be crazy in any language.

Yet this is what Ruby does, AFAIK.

Re:Rust is surprisingly expressive by matthewmacleod on Saturday December 28, 2013 @05:22PM (#6976919)
Yet this is what Ruby does, AFAIK.

Numeric#days is an ActiveSupport method, not core Ruby. But yes, it does patch the behaviour into a core class.

This is a bit of a legacy of Ruby programming, and it's definitely bad to pollute the global namespace. However, I expect we'll see eventual use of Refinements (http://www.rubyinside.com/ruby-refinements-an-overview-of-a-...) now that they are available; this will allow classes to override core methods without affecting other classes out of scope.

Re:Rust is surprisingly expressive by philwelch on Saturday December 28, 2013 @05:28PM (#6976934)
Refinements do a little less than previously advertised three years ago, and as far as language features go I don't think they're worth the performance implications.
Re:Rust is surprisingly expressive by wycats on Saturday December 28, 2013 @04:49PM (#6976784)
This must be a question of aesthetics because the 2.days().from_now() seems perfectly obvious to me. Maybe someone can help me understand why it seems confusing?
Re:Rust is surprisingly expressive by Touche on Saturday December 28, 2013 @05:08PM (#6976866)
It's non-obvious to me what 2.days() returns, that's the problem.
Re:Rust is surprisingly expressive by matthewmacleod on Saturday December 28, 2013 @05:32PM (#6976953)
I don't think that's a problem: avoiding features or fiddling with syntax in order to make the code more accessible to people who are not familiar with the language or its libraries isn't going to gain much in the long run. Languages and libraries should be geared towards long-term developer happiness, rather than a shallow learning curve.

Anyway, I know as close as possible to nothing about Rust. It seems blindingly obvious to me that `2.days()` returns some kind of duration, and `2.days().from_now()` returns some kind of time. So I've looked at the code, and that appears to be correct - `2.days()` returns a `TimeChange`, and `2.days().from_now()` returns a Time. I can't think of any other reasonable interpretation.

Re:Rust is surprisingly expressive by ivanca on Saturday December 28, 2013 @05:43PM (#6976997)
Yeah, you _had_ to look at the code to realize that; when it could have been

     new TimeChange.fromString("2 days from now")
Which would have been more helpful for actual development, not only for a dumbed-down syntax aiming for easier comprehension.