> Date: Fri, 18 Oct 2013 10:54:23 -0700
> From: Jeff Petkau <[email protected]>
>
>
>
> On my code (disclaimer: only toy projects to learn Rust so far),  I've been
> pretty happy with a "mut_" prefix for mutable versions.
>
>   newthing = oldthing.push(foo")
>   anything.mut_push(foo")
>
>   x = bagofun.sort()
>   bagosadness.mut_sort()
>
>   etc.
>
> Advantages:
> - consistent meaning with the 'mut' keyword.
> - works with pretty much any name.
> - makes mutable versions just a bit uglier than immutable code.
>
> Disadvantages:
> - If an API is inherently mutable, it gets pretty noisy.
> - A bit ugly, probably turns off newcomers.
> - If the compiler warns on ignoring return values, and mutating methods
> return (), then a convention might be unnecessary.
>
> --Jeff
>
>
What about establishing a convention that mutable methods start with an
uppercase letter while non-mutating methods start with a lowercase letter?
It would be lightweight in terms of character count/looks and at the same
time give mutable methods a slight visual emphasis, which makes sense I
think.

I know this convention is already used by Traits, but when I looked through
some code with the above proposal in mind it would be easy to distinguish
between these two uses of the same convention due to the differing contexts
they're used in.

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

Reply via email to