Tag: coding style

Articles and experiments related to coding style.

RE: C# : Where do you define an enum

In response to a comment on Abhinaba's blog, I argue that verbosity in code is generally preferable, especially when defining enums. While Intellisense can be helpful, it shouldn't dictate design decisions. Enums should ideally be defined within the class they're used, unless they're shared across multiple classes from the outset. This improves code clarity and makes dependencies explicit. For example, separate FileFilter and DirectoryFilter enums within their respective classes are better than generic namespace-level filters.

Read article

RE: C# : Where do you define an enum

This post discusses the best placement for enum declarations in C#. While some argue that defining enums outside the class avoids extra typing, I believe that placing them inside the class improves code clarity, reduces ambiguity, and makes it easier to handle similarly named enums from different classes. IntelliSense helps with the extra typing. The original article argues against this, prioritizing less typing, but I find that less important than clarity and proper scoping.

Read article

Stay in the loop.

I'm trialing a newsletter. Join for monthly insights into web dev, Chrome, and the open web.

alternate_email

Get in touch

Open to chat about Chrome or Web development.

Book a consultation