-2

I am separating one of my method extension classes (i.e., StringExtensions) into regions, as has become confusing and it's difficult to see the wood for the trees. I have grouped the methods into four regions, as follows:

Identification: Usually associated with the verb to be, e.g., Is, Has, etc., and returns a Boolean. These are mainly used in validation.

Selection: Filters from a collection passed in or replaces what is passed in with empty or null, with no other manipulation

Conversion: Different type is returned to the one entered, without any manipulation or calculation.

Substitution: Returns a manipulation or calculation of what is passed, where the manipulation involves more than replacing with an empty string or null.

I've looked around and found little on the subject. So, I was wondering if there is an already existing concept of grouping methods, as these work for most cases but aren't mutually exclusive. Please could you suggest mutually exclusive groups for String Extension methods?

EDIT: I don't want to subdivide separate namespaces or classes as this extension method class is already used by many applications and would introduce breaking changes.

Phil C
  • 1,956
  • 1
  • 18
  • 34
  • Honestly I still have no idea what you mean. Are you literally referring to "regions" as in the `#region`directive? Or in some colloquial sense? And what do you mean by "mutually exclusive?" You can only have one method with a particular signature. Is this for source code management, for shortening the intellisense list, for deployment purposes, what? Please explain your need in technical terms, or provide an example. – John Wu Mar 27 '18 at 07:32
  • Yes, code regions using #region directive - Sorry, I shouldn't need to explain mutual exclusivity. In short, each method should fit into one group only. In my example, there are four groups. Each method should fit into one only. However, there are methods that could fit into more than one of my categories. For example, should "SplitLines" go into Selections or Conversions. The fact that a method can fit into more than one category implies that my categories are not mutually exclusive of one another. I want a set of categories that are mutually exclusive. – Phil C Mar 27 '18 at 07:45
  • The only guaranteed way of coming up with a set of mutually exclusive terms is to have one region per method group and give the region the same name as that method group. Anything else will inherently lead to more than one name that a method could belong to. – David Arno Mar 27 '18 at 08:03
  • Again, please use technical terms. What do you mean "fit"? A c# `#region` can be pretty much unlimited in size. Are you asking us what region *names* would comprise four orthogonal logical groups? Without seeing the list of methods or knowing what they do? Are you asking for a naming *convention*? – John Wu Mar 27 '18 at 08:19
  • Related: https://softwareengineering.stackexchange.com/questions/53086/are-regions-an-antipattern-or-code-smell – nvoigt Mar 27 '18 at 10:21

1 Answers1

3

I am separating one of my method extension classes (i.e., StringExtensions) into regions...

Please don't do that. If your class has got so big that you need to consider using regions, then break up the class instead.

You have already identified good names for those classes:

StringIdentificationExtensions
StringSelectionExtensions
StringConversionExtensions
StringSubstitutionExtensions

Those names and descriptions make sense and there is no established standard that "overrules" you, so go with these classes as a starting point at least.

David Arno
  • 38,972
  • 9
  • 88
  • 121
  • This wasn't what I was after, as I don't want to subdivide namespaces as these are already used by many applications and would introduce breaking changes... But you say there is no standard that you know of? – Phil C Mar 27 '18 at 06:21
  • @CarneyCode, I didn't mention namespaces. Keep those new classes in the same namespace and it will not be a breaking change as extension methods are referenced via a namespace, not the class name. – David Arno Mar 27 '18 at 06:23
  • You're right; you didn't and I read it that way BUT splitting the class into several classes of differing names would cause breaking changes. – Phil C Mar 27 '18 at 06:30
  • @CarneyCode, then up the major version number (you are using semantic versioning, aren't you?) and move on. – David Arno Mar 27 '18 at 06:33
  • Yes, I am but that isn't something I want to do anytime soon. Regions are sufficient for our purposes here. I'm surprised that there isn't an existing standard to make such categories mutually exclusive... I'll see if anyone else had read anything about. Meanwhile, thanks for your input. – Phil C Mar 27 '18 at 06:36