5 ms·
I humbly disagree - in the C# code I can pass an IQueryable and reuse the same code to make an SQL query, or a RavenDB query, or an XML query and it works just
by inglor 12y ago
I humbly disagree - in the C# code I can pass an IQueryable and reuse the same code to make an SQL query, or a RavenDB query, or an XML query and it works just the same - there is a unified way to access data in the language.
As for your query:
```
var admins = users.Where(u => u.IsAdmin()).Select(u => u.Name);
var stars = admins.Select(name => name + "*");
```
Like you said, you don't get paid per line feed - it's ok to have multiple lines and you can keep the nice syntax. It's ok to not like complicated code - no one likes complicated code - which is why I don't like for loops - I don't _care_ how something is iterated I just want to map every object.
- NateDad 12y agoWell, so, that's actually not doing the right thing. You just changed the names in the list of strings that holds admin names, but not the names on the user objects themselves. Even if the first half were returning the users themselves to the admins list, you're still iterating over the list twice. This is yet another reason why the for loop is good - it makes it more clear what is actually going on. This is your code in for loops: var admins []string for _, u := range users { if u.IsAdmin() { admins = append(admins, u.Name) } } for i := range admins { admins[i] = admins[i] + "*" } The problem with the fancy syntax is that it makes it too easy to write suboptimal code that you'd never write if you were writing plain old for loops, like the above.
- frowaway001 12y ago> you're still iterating over the list twice There is nothing about higher-order operations that would require developers to implement xs.map(...).map(...).map(...) or xs.Select(...).Select(...).Select(...) or whatever as multiple traversals over the data structure. > The problem with the fancy syntax is that it makes it too easy to write suboptimal code that you'd never write if you were writing plain old for loops, like the above. Maybe Google should just invest in hiring better people? I know it's getting increasingly harder to find people who still haven't evolved from the 1960ies mindset, but still ...