4 ms·
The second SQL-like version is far more readable. There is just less "syntax noise" and it's far more "declarative" by definition. The author stating that the
by cjonas 1y ago
The second SQL-like version is far more readable. There is just less "syntax noise" and it's far more "declarative" by definition.
The author stating that the lambda is "better" because it's less lines is also silly. It's been a while since I've written C#, but pretty sure the SQL-like version can be formatted to a single line as well:
List<Product> GetExclusiveProducts(List<Product> source) =>
(from p in source where p.ProductTitle == "iPhone" orderby p.TypeOfPhone select p).ToList();
- z500 1y agoYou can format it on one line if you want. Please don't do that, though. Personally I prefer the method syntax with one method per line, it reads more linear than the query syntax.
- cjonas 1y agoAgree and disagree. I prefer the second approach, but I wouldn't format either as a single line.
- magicalhippo 1y agoNever understood why a lot of programmers are so obsessed with reducing lines of code at the expense of all else. What's important to me is that I can understand the intent of the code, that I can reason about how that code will be executed at runtime, and that I can easily debug the code if needed. Of course, there's no need to go full enterprise Java. Never go full enterprise Java. But having ten lines of clear code that's easily debuggable and which runtime characteristics is predictable is much better than one dense line that's difficult to untangle, or a few that's hard to predict what will do etc.
- anonymars 1y agoNot to mention it's much easier to put a breakpoint on one of those specific lines
- the_other 1y agoYears ago on the Ruby Rogues podcast, someone mentioned they aim to do just one operation per line. I’ve aimed to do that with ny TS/JS ever since. My files are longer but they’re usually easier to read.
- Kuinox 1y agoOver all, peoples prefer writing with lambda, somes use the SQL-like, but there is a major preference towards lambdas.