On Sat, Aug 04, 2012 at 12:15:51PM -0700, Graydon Hoare wrote:
> On 02/08/2012 12:51 PM, Emmanuel Surleau wrote:
> >Hi,
> >
> >I'm new to rust, and I'm struggling to find an elegant way to work with 
> >default
> >parameters.
> 
> We don't have explicit support for it yet. Nor named params,
> varargs, or generalized overloading (we only allow overloading via
> traits).
> 
> There is room in the syntax and semantics for this in the future,
> but I agree with Patrick that running experiments on combining such
> features is past scope for the "stabilize for 1.0" roadmap; we
> already have a _very_ full plate and have been trying to get the
> language to stop moving for two years now. It's slowing but we're
> trying to cut-in-order-to-ship pretty aggressively. This subset of
> features is comparatively non-essential (lots of language lack it)
> and can be worked around several ways, as people have suggested:
> 
>   1. pass option<foo> and the callers can say 'none' for defaults.
>   2. make a separate default-passing fn
>   3. use a method-chaining "fluent interface" approach if you want
>      the type system to help you enforce that only certain combinations
>      of arguments are legit
>   4. use a macro
>   5. overload via traits
> 
> If none of these fit the bill, well, we might explore the space we
> left open for this in the future. I won't close a bug on it or
> anything, it's a legit feature. Just not one I'm going to want to
> pull into the language this time around.

Option 1 is an issue when dealing with larger data structures, you're going to
end up with things like fn(1,2,3,none,none,4). I guess I'll go with method
chaining for now, as it seems the cleanest solution.

Let me add a side note to say I truly appreciate the depth and open-mindedness
of the answers I have gotten. I am also sympathetic to your argument concerning
the stabilization of the language. I'm definitely looking forward to rust 1.0.

Cheers,

Emm
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to