Reply to post: Re: Or...

A Reg-reading techie, a high street bank, some iffy production code – and a financial crash

Adam 1

Re: Or...

> Will someone please tell me why I am wrong to say that no-one using a modern language (of a higher level than Assembler or C) needs to explicitly code a loop to sum [attributes of] the elements in an array?

Not a downvoter but ...

I have seen LINQ used in some pretty bad ways. Here are a couple.

Developer not realising that their method was O(n^2). They simply forgot that behind those magic select or first or find methods is a loop.

Another developer didn't realise that a .Any(a => a == 5) on a Hashset may yield the same result as .Contains(5), but the former is O(n) and the latter O(1).

In other cases, a loop which iterates some collection and conditionally yields another object with properties based on the initial collection item can end up with such a convoluted expression that the minute it would have taken any half competent developer to follow the intent now takes 10 minutes to unpack, and even then you're wondering if you missed something subtle.

Another issue is with debugging it can be hard to set breakpoints when your line may represent hundreds of function calls.

Note I never said you should never use them. Just remember that most of the time it doesn't matter if your class is 5 lines longer or 150ns slower, but it does matter if your code becomes difficult to read. Use them, but with appropriate discretion.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon