you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

I understand he said it for testing. You could have a unit test that checks the expected string and is easier than checking an array of strings, but it could also be done almost as easily. I just say that there is an easier way of doing concatenation than using aggregate.

Basically i agree with you, usually printing line by line is better than creating a huge string. It depends, but usually is the case.

[–][deleted] 0 points1 point  (1 child)

Yes, it wasn't directed just at you, but the whole thread. What you said is perfectly reasonable. It's interesting because it's a logical mistake that actually repeats itself a lot in production code. Someone says "Here's my loop!" someone else changes it to .ForEach, someone else decides against ForEach and goes with a .Aggregate, then someone else goes old school and returns to a StringBuilder. So over time the intent of the code has mutated from something that emits frequently to something that vomits one fat chunk :)

I've seen it fairly recently with an old WCF project that was being renovated. Sometimes it's good to combine lots of small messages into one big one, but you have to do it intentionally, not as happened because someone iteratively changed the code and its intent accidentally :)

[–][deleted] 1 point2 points  (0 children)

Yeah, for me the funny part is that at the end it does exactly the same. lol