On Sat, Feb 2, 2013 at 12:49 PM, Tommy M. McGuire <mcgu...@crsr.net> wrote:
> Is this a good place to request comments on a (really horrible) first
> Rust program?
>

Certainly!

> https://github.com/tmmcguire/rust-toys/blob/master/mk_anadict.rs
>
> For inspiration (and because I have no actual creativity of my own), I
> picked up
> http://www.jeffknupp.com/blog/2013/01/04/creating-and-optimizing-a-letterpress-cheating-program-in-python/,
> which is basically an anagram solution generator; this first program
> generates a text dictionary of letter sequences to words, one mapping
> per line.
>
> I'm using Rust 0.5.
>
> * I used std::map::HashMap, although I have since read that LinerMap is
> more idiomatic?

I wouldn't worry about that at first while learning. HashMap will be
removed eventually, though (I think).

>
> * I saw a suggestion to use @~str since ~str's seem to be better
> supported, library-wise, and I saw a suggestion to use @~str to avoid
> the copying warnings for bare ~str's.

I guess that's probably the best you can do right now, yes. Though as
an exercise, it might be fun to see if you can change the @~strs to
~strs now that your code works. On the other hand, storing strings in
a map is probably one of those cases where not using @strs will be
painful. As you alluded to, though, some library functions only work
with ~str so @~str may be easier than @str right now. We really need
to work on that... (this part certainly isn't your fault!)

>
> * After playing some more, I think read_lines is kind of silly.
>
> * For no readily apparent reason, I used @[] quite a bit. Should there
> be any special preferences for ~[]?
>

No, at least not until you're writing code with multiple tasks or
where you care about performance. It's fine to start with @[] and then
change to ~[] as needed. As with @str, there's less library support
for @[], but that's another thing we need to work on.

There are a few places where you call a function like
str::len(**line), where line.len() would be more idiomatic (and
because of auto-dereference, you're saved from writing the asterisks).
I'll let others point out other nits :-)

Cheers,
Tim

-- 
Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt
"Too much to carry, too much to let go
Time goes fast, learning goes slow." -- Bruce Cockburn
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to