What’s Not To Understand?

178 words.

Consider this post: Syntactical Molasses. The author claims that his test method is “syntactical molasses” which “makes the intention of the code so much more difficult to understand:”

[Test, ExpectedException(typeof(ArgumentNullException))]

public void GetAllFilesMatching_With_NullPath_ThrowsArgumentNullException()

{

foreach (string s in DirectoryWalker.GetAllFilesMatching(null, AlwaysTruePredicate)) { }

}

I don’t mean to sound like an elitest or anything (honest!), but that is about as difficult for me to read and understand as “see Jane run.” I can easily see what the programmer is trying to do there. How is it “syntactic molasses?” What part needs to be easier to understand? You’ve got a test case with a loop enumerating a list of filenames. Maybe it’s just that I’ve been reading C-style syntax for nearly 20 years (ack) and these CodeBetter kids are just getting started in their careers. Or maybe all the hubbub about “natural expressiveness” is designed to make code easier for non-programmers to understand? (But isn’t that what, ahem, comments are for?)

P.S. It’s not at all clear to me from that code why DirectoryWalker.GetAllFilesMatching is superior to .NET’s built-in DirectoryInfo.GetFiles.

Related

This page is a static archival copy of what was originally a WordPress post. It was converted from HTML to Markdown format before being built by Hugo. There may be formatting problems that I haven't addressed yet. There may be problems with missing or mangled images that I haven't fixed yet. There may have been comments on the original post, which I have archived, but I haven't quite worked out how to show them on the new site.

Sorry, new comments are disabled on older posts. This helps reduce spam. Active commenting almost always occurs within a day or two of new posts.