[rust-dev] Naming conventions for constructors

Gareth Smith garethdanielsmith at gmail.com
Wed Aug 15 09:10:07 PDT 2012


Hi,

I guess this is also an issue when type names are used in non-constructor
functions: e.g. should the to_str method actually be called to_Str, should
to_bytes be called to_Bytes ?

I think the "new" convention looks OK, but it is a bit weird with multiple
constructors in a module because you then have to include the type name in
the function name.

I am curious what the motivation is for changing the naming convention of
types?

Thanks
Gareth

On 15 August 2012 02:24, Brian Anderson <banderson at mozilla.com> wrote:

> On 08/14/2012 06:04 PM, Erick Tryzelaar wrote:
>
>> On Tue, Aug 14, 2012 at 4:35 PM, Brian Anderson <banderson at mozilla.com>
>> wrote:
>>
>>> Hey.
>>>
>>
>> Hello.
>>
>> :)
>>
>>  Then to use it:
>>>
>>>      import my_crate::belt_buckle;
>>>
>>>      let my_belt_buckle = belt_buckle::new();
>>>
>>> You will mostly not import the constructor because it will need to be
>>> disambiguated from all the other 'new's in the world.
>>>
>>
>>
>> This is fine with me, I liked this style back in the pre-typeclass
>> rust. There were two things that bugged me about this style. First,
>> impls made import lines pretty dense, so it was nice to just import
>> one type/impl/fn. Is this still the case with the new min/max classes?
>>
>
> The situation is much better with impls now. Any impls defined in the same
> module as the type are automatically available everywhere. The current
> scheme is nice in that you import `dvec::dvec` and get both the type and
> the constructor.
>
>
>  Second, If I wanted to import anything from the module, I'd have to
>> write:
>>
>> import my_crate::belt_buckle;
>> import my_crate::belt_buckle::**BeltBuckle;
>>
>>
>> Maybe we could add some sugar to combine those two lines into (forgive
>> me if there's already a way to do this):
>>
>> import my_crate::belt_buckle::{., BeltBuckle};
>>
>>
> Something like this does seem appropriate.
>
>
> ______________________________**_________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120815/983759e9/attachment.html>


More information about the Rust-dev mailing list