NickColley / scrambo

Puzzle Scramble Generator
26 stars 5 forks source link

Scramblers should be immutable, or obviously mutable #20

Closed justinj closed 10 years ago

justinj commented 10 years ago

As discussed:

var scrambler = new Scrambo();
var four = scrambler.type("4x4");
var five = scrambler.type("5x5");

Doesn't work as expected, since the notation kind of reads like an immutable chain, but .type is actually a setter on a Scrambo.

Some things I would prefer:

NickColley commented 10 years ago

Is there any resources you have that can better explain what you mean by immutable chain? It was my intention to make it mutable, so you don't have to initialize manually every time. A typical use case would be switching to from 3x3 to 4x4 for example, whereas it wouldnt often be useful to create a new scrambler.

justinj commented 10 years ago

That's fair, if you think the more common use case is simpler with mutation then stick to that if you prefer. I tend to have an aversion to mutative things in general where possible. I was thinking something along the lines of the stuff you would do with _.chain like _.chain([1,2,3]).filter(x => x %2 == 0).map(x => x*x) etc where everything is immutable along the way.

I think my preference is probably that the type of the scrambler never changes once it's created (meaning option 2), but I don't really feel that strongly, do what you prefer.

NickColley commented 10 years ago

Thanks for your reply, I really dig what you're talking about and see where you're coming from now. I think in this case since we're generating data not manipulating it, it might make more sense to keep as is.

This discussion has made me wonder if we could have methods like .length not mutate the scramble and subsequently not have to generate it again, very interesting thanks for bring this up :+1: