Many times I have heard programmers laugh at teammates who wrote slow code. Harsh, self-righteous phrases in the style of "this idiot ran through the collection four times, although it could have been one," and the like. When you hear this, you immediately think - well, everything is on business, why make unnecessary iterations? Why can't you learn a couple of basic things, like how LINQ expressions work in C #, and write normal code? You laugh at incompetent fools until they start laughing at you. And you can believe me - no knowledge in programming will save you from a situation where you unknowingly fancy a quadratic algorithm instead of a linear one.
I don't know if anyone was laughing at my code, but I'm sure - more than once or twice I wrote a solution that was a hundred times slower than it could have been. But in these cases, I deliberately wrote sub-optimal. For example, in C # there is a for loop, and there is a Select collection method (in other languages ββit is more often called map). The loop is faster, but I find the functional approach more aesthetically pleasing - and I use it. I know that there is little data, there will be no bottleneck, and I write code that, in my opinion, is prettier, more readable, and therefore better. There are a lot of such solutions in development - and I choose to write productive code only when I know for sure that otherwise drawdowns will become a problem.
, -, , β . , , , . β LINQ . C# β yield β , , . β β , , . , , β .
- , yield, - . , LINQ . - , , , , . . LINQ β , .
β , . BenchmarkDotNet, Pro .NET Benchmarking, , , , , . , β .
, ? , .
Select β Select. , , , , , , .
, . " " β , . " ". , , .
, , β . . for select, , ? C#, , C# β . C++. . , , β . , , β ** . , .
, . , C#. . β , , β . , .
, . Queue, List β , . , , . β .
, . . β , . , , β , . , .
β β β, β β β , β , . , , , β . , β , , . , .
β . , ", C#, LINQ" , . , . β β β . , "yarn start" . , , . . , β β .
β . , , . β . , , , , , , . . , , . .
β , . , .
There is nothing wrong that you chose prettier, but not faster. And there is no tragedy when you just did not know that your decision was super sub-optimal. The problem starts when you say productivity is bullshit and let individuals do it. No bro. Learning how to speed up code is not the lot of performance nerds, it's part of our job. When your unwillingness to learn complicated things makes your code both slow and ugly, then you have big problems.
Watch my podcast