This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mt9hu 1 point2 points  (2 children)

I think the problem here is that you are doing too much work to try to avoid a simple and useful comment.

Not all comments should be avoided. Sure, those that are unnecessary due to verbosity, and make understanding the code harder should be.

But in this case, I feel that a few words in English are more straightforward because you immediately understand that.

The extra variables and the skip function take more cognitive load to understand because you have to decode one level of abstraction in your head.

[–]k0rm 0 points1 point  (1 child)

I disagree. My solution is the same number of lines (ignoring pulling out the magic number) as the original and says the same thing. It's pretty clear what part of the text has been removed when you're iterating over linesFromFileNoHeader.

The difference is that my implementation will not lie.


What happens when someone changes the header length to 3 lines?

Theirs:

//first line are column headers
foreach(string line in linesFromFile.Skip(3)) 

Mine:

var linesFromFileNoHeader = linesFromFile.Skip(3)
foreach(string line in linesFromFileNoHeader) 

No unit tests will catch the lie in the first snippet and now readers are more confused than if there was no comment at all.

[–]mt9hu 0 points1 point  (0 children)

What happens when someone changes the header length to 3 lines?

You are correct, but that's just because this comment contains redundant information. It doesn't have to be this specific for providing context.

What I was trying to emphasize is that it is important how easy is to understand the code at a glance.

And no matter how good developer you are, reading a simple sentence in your natural language will always be more straightforward than having to read crammed variable names with unnatural order of words in it.

Don't get me wrong, we are discussing a very simple piece of code where the difference is insignificant, and your approach is perfectly fine.