5 ms·
>languages get by with a more readable I'd love to see how you think the kotlin (or java) version of the following would be more 'readable' var result =
by runT1ME 11y ago
>languages get by with a more readable
I'd love to see how you think the kotlin (or java) version of the following would be more 'readable'
var result =
from a in taska
from b in taskb
from c in taskc(b) where c.Contains("blah")
select c + a;
- mythz 11y agoAgain you're just cherry picking a rarely used niche example that benefits from a SQL-like cross join, that you couldn't even map to a real-world example. What's the point, to show it has terse syntax for rare use-cases? Whilst the code is terse it's also deceptive as it's not obvious it's performing a cross-join over multiple collections - so even in this case I'd prefer using a nested maps which IMO is more readable as it's clearer what's actually happening. Readability != terseness, it's clarity of intent.
- runT1ME 11y ago>Whilst the code is terse it's also deceptive as it's not obvious it's performing a cross-join over multiple collections - so even in this case I'd prefer using a nested maps which IMO is more readable as it's clearer what's actually happening. Readability != terseness, it's clarity of intent. It has nothing to do with SQL cross joins across multiple collections. LINQ is useful for things that aren't even collections! In my example I was using them on a Task<T> to represent an asynchronous computation. This is common code we would write in a large C# application I was on at my previous job.
- ufmace 11y agoIt's not exactly helping your case that it isn't at all clear what that sample is actually doing and what kind of practical task it might be used for. I've been doing C# for years, use and enjoy Linq, and I can't remember the last time I touched the comprehension syntax. IIRC, it does make a few relatively obscure things easier than they would be with method and lambda syntax, while there are a few different obscure things that are easier without it. On balance, I lean against it as being yet another sub-language for you and the rest of your team to learn and understand what it's really doing under the hood.
- random314 11y agoThe sample is not clear?! How would you write the same asynchronous code in C# without the LINQ syntax? Can you give an example? All the code does is get a from async taska, b from async task b, feed the result of b into task c to get c, and if c contains blah return c+a asynchronously.
- ufmace 11y agoIf you understand it, then exactly what are the return types of these tasks and the types of a, b, and c? Are they single objects or IEnumerables? If they are enumerable, then what exactly does c + a do? It is creating a new enuerable of every a added to every c, like a SQL cross join? If it is a single object, then what exactly does the where clause do? What does it return if c does not contain blah, and what becomes of a in that case? Does it get returned, added to null, disappear into the ether, or does it figure out that it doesn't need it, and never actually evaluate taska? What happens if taska modified some other state somewhere? For that matter, if it's figuring that out, that would control the order that the tasks are evaluated in. What is that, exactly? Is taska run at the same time as taskb, or does it wait to see if there is actually a c to add to it's result? Or maybe it gets evaluated before or after taskb, or at the same time. That stuff matters. I'd rather make it clear at a glance what's going on than write something super short and clever that nobody can figure out the details of.
- runT1ME 11y agohttp://mikehadlow.blogspot.co.uk/2011/01/monads-in-c1-introduction.html http://mikehadlow.blogspot.co.uk/2011/01/monads-in-c1-introd...