Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider renaming Query methods #301

Open
fatcerberus opened this issue May 4, 2019 · 1 comment
Open

Consider renaming Query methods #301

fatcerberus opened this issue May 4, 2019 · 1 comment

Comments

@fatcerberus
Copy link
Member

This would be a breaking change to the Sphere Runtime and so couldn't happen until 6.0. It might be nice though to use the idiomatic JavaScript names for the common operations (filter, map, flatMap, etc.) instead of the LINQ names, to lower the learning curve for people already familiar with the usual array operations.

@fatcerberus
Copy link
Member Author

fatcerberus commented May 10, 2019

I experimented with using the JS names, but I didn't like it; it made chains look really weird. The LINQ names read back much more naturally when linked in a chain:

// from someArray, where 'n is even', select 'n squared', aggregate using addition
let sumOfEvenSquares = from(someArray)
    .where(n => n % 2 === 0)
    .select(n => n ** 2)
    .aggregate((a, n) => a + n);

// how even do we read this?
// from someArray, filtered by 'n is even', map to 'n squared', reduce to addition
// ...yeah, that's understandable (eventually) but doesn't really flow well
let sumOfEvenSquares = from(someArray)
    .filter(n => n % 2 === 0)
    .map(n => n ** 2)
    .reduce((a, n) => a + n);

Long story short, I decided to keep the LINQ names and renamed the few that weren't consistent. The only change I ultimately made to LINQ nomenclature was to call SelectMany, over instead. I always found SelectMany, while obvious as far as what it does, to break the natural narrative flow of a LINQ method chain. Plus it doesn't necessarily have to choose more than one item anyway, so it's a bit misleading too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant