Click here to Skip to main content
15,886,919 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch9-Feb-21 1:14
mvahoney the codewitch9-Feb-21 1:14 
GeneralRe: Unpopular opinions: LINQ Pin
afigegoznaet9-Feb-21 1:21
professionalafigegoznaet9-Feb-21 1:21 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch9-Feb-21 1:37
mvahoney the codewitch9-Feb-21 1:37 
GeneralRe: Unpopular opinions: LINQ Pin
afigegoznaet9-Feb-21 1:43
professionalafigegoznaet9-Feb-21 1:43 
GeneralRe: Unpopular opinions: LINQ Pin
harold aptroot8-Feb-21 8:41
harold aptroot8-Feb-21 8:41 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch8-Feb-21 9:15
mvahoney the codewitch8-Feb-21 9:15 
GeneralRe: Unpopular opinions: LINQ Pin
Gerry Schmitz8-Feb-21 9:39
mveGerry Schmitz8-Feb-21 9:39 
GeneralRe: Unpopular opinions: LINQ Pin
Sander Rossel8-Feb-21 9:42
professionalSander Rossel8-Feb-21 9:42 
honey the codewitch wrote:
It creates too many objects too quickly
Can you elaborate?
As far as I know you have an extra enumerator per operation, so for example:
C#
foreach (var whatever in whatevers)
{
    if (whatever.IsValid)
    {
        filtered.Add(whatever);
    }
}
Has one enumerator, while
C#
var filtered = whatevers.Where(x => x.IsValid).ToList();
has two enumerators (the Where will call "the original" enumerator, while the ToList will call the WhereEnumerator).
Other than that it's the same except that the LINQ example has an extra anonymous function (which isn't anonymous after compilation) and an extra function call for each iteration, but if the where clause is complicated enough you may do this in example 1 too.
That's hardly a performance penalty, but you just won 7 lines of code and made it more readable to boot.
The readability further increases when you do stuff like
C#
whatevers.Where(x => x.IsValid)
    .Select(x => new { Name = x.Name, Age = x.Age })
    .OrderBy(x => x.Name)
    .Take(10)
    .ToList()
at the expense of three extra enumerators.
Object instantiation is cheap, or so I've been told.

You also missed one, LINQ to Entities (or LINQ to SQL), which is also LINQ, but won't enumerate at all because the entire structure is compiled to an object structure and parsed into SQL.
Let's not talk about the performance implications on that one Big Grin | :-D
For most operations it's not significantly slower though, while it saves a ton of time of SQL development and makes your database connection strong typed meaning less bugs, etc.
The extra milliseconds the user is waiting is won back in hours of development time Big Grin | :-D

GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch8-Feb-21 9:49
mvahoney the codewitch8-Feb-21 9:49 
GeneralRe: Unpopular opinions: LINQ Pin
Sander Rossel8-Feb-21 10:21
professionalSander Rossel8-Feb-21 10:21 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch8-Feb-21 13:13
mvahoney the codewitch8-Feb-21 13:13 
GeneralRe: Unpopular opinions: LINQ Pin
Sander Rossel8-Feb-21 22:21
professionalSander Rossel8-Feb-21 22:21 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch9-Feb-21 1:00
mvahoney the codewitch9-Feb-21 1:00 
GeneralRe: Unpopular opinions: LINQ Pin
Sander Rossel9-Feb-21 2:08
professionalSander Rossel9-Feb-21 2:08 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch9-Feb-21 2:14
mvahoney the codewitch9-Feb-21 2:14 
GeneralRe: Unpopular opinions: LINQ Pin
Sander Rossel10-Feb-21 0:08
professionalSander Rossel10-Feb-21 0:08 
GeneralRe: Unpopular opinions: LINQ Pin
r_hyde8-Feb-21 12:24
r_hyde8-Feb-21 12:24 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch8-Feb-21 14:27
mvahoney the codewitch8-Feb-21 14:27 
GeneralRe: Unpopular opinions: LINQ Pin
Super Lloyd8-Feb-21 13:32
Super Lloyd8-Feb-21 13:32 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch8-Feb-21 14:21
mvahoney the codewitch8-Feb-21 14:21 
GeneralRe: Unpopular opinions: LINQ Pin
Super Lloyd8-Feb-21 14:31
Super Lloyd8-Feb-21 14:31 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch8-Feb-21 14:41
mvahoney the codewitch8-Feb-21 14:41 
GeneralRe: Unpopular opinions: LINQ Pin
Kiriander8-Feb-21 20:26
Kiriander8-Feb-21 20:26 
GeneralRe: Unpopular opinions: LINQ Pin
honey the codewitch9-Feb-21 1:06
mvahoney the codewitch9-Feb-21 1:06 
GeneralRe: Unpopular opinions: LINQ Pin
Kiriander23-Feb-21 22:52
Kiriander23-Feb-21 22:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.