-2

I'm just curious if #region is really necessary in C# coding, because I don't think I really need it since I can keep track of everything I do(mostly because the projects are small).

So is it really necessary to learn at all? Good and strong responses to why and why not are very welcome!

  • 2
    Is there really something to "learn" about regions ? – xlecoustillier Nov 13 '14 at 14:06
  • no, if you have clean code there is no need for regions. – Dejan Dakić Nov 13 '14 at 14:06
  • 1
    If you work with more people you will pray for good formatting, clean code, structured regions... – blfuentes Nov 13 '14 at 14:07
  • 3
    Possible duplicate http://stackoverflow.com/questions/169276/is-the-region-directive-really-useful-in-net – Max Brodin Nov 13 '14 at 14:08
  • 1
    It can be collapsed! – NP3 Nov 13 '14 at 14:08
  • 1
    Me thinks you haven't realized how quickly your code can bloat- Reagions are A-mazing, and there is nothing to learn other than how to type it. – Nyra Nov 13 '14 at 14:08
  • Excellent question. And definitely not an opinion. the question is are they necessary. That's a preference. While a preference can be an opinion, it's not necessarily so. It's my preference to not have animals. It doesn't mean I have a poor opinion of them. Too many cranks on here looking for points and not enough willing to just realize that some of us are NEWBS. We need somewhere to learn. – Frank Pytel Nov 13 '14 at 14:16
  • @FrankPytel... What do you mean looking for points? You lose points for flagging something as Opinion, and for downvoting... That sentiment makes no sense... Also, you clearly point out that this is opinion based. "That's a preference." Preference is synonymous with opinion. – Nyra Nov 13 '14 at 14:19
  • @alykins Uhmmm.. No. A preference may be an opinion, but is not necessarily one. An opinion relates to facts or their lack. Does a long walk convey an opinion? Nope. Preference. Are long walks Healthy? Opinion. I was not aware about the point loss downvoting. My apologies. Just gets my goat to see so much of my stuff flagged. I'm a NEWB. I admit it. I'm trying. I really want to learn this stuff. Took college classes. Didn't mean squat. Started surfing and seeing. I'm definitely learning now. Useful code. The stuff I don't understand, I'm sure I will in time with the help of folks here, etc. – Frank Pytel Nov 13 '14 at 14:25
  • @FrankPytel - I'm not saying there isn't an issue with downvotes- I've raised that before- But sorry, my opinion is that you are wrong- A preference is something you like. I prefer to use regions. That is a subjective statement and therefore opinion based. Someone who doesn't like them, would say no. This thread is becoming opinion as well. Either way, my entire point was no one is gaining points by commenting or the one downvote that happened. You don't get points for upvoted comments. – Nyra Nov 13 '14 at 14:53

1 Answers1

3

No, it isn't necessary and some would say that it isn't even useful.

Personally, I'll use regions if it makes sense to group functionality together - related unit tests, for instance is a place that I'll use regions - but I know that folks differ on this opinion.

The whole point with regions is that it is simply a convenience for collapsing an area of code. It doesn't enforce anything, doesn't check that you've not put functions in the wrong place, etc. But it can be helpful in certain circumstances.

itsmatt
  • 31,265
  • 10
  • 100
  • 164
  • 4
    I think the key word in this answer is "opinion" – DavidG Nov 13 '14 at 14:09
  • I also have the same view on this subject. I only use regions to group functions together, I.E a Customer Service Class, composes of get methods for querying, but also entity framework Update Insert Delete methods, i simply group these into 2 regions. – lemunk Nov 13 '14 at 14:09
  • @StevenSmith sounds like a candidate for seperate classes to me! #opinionbased – Gusdor Nov 13 '14 at 14:11
  • yeh reminds me of normalizing data in a DB, like these functions are all services, to the customer, the "Gets" are basically "Selects" and the Insert Delete Update etc, so basically you could attribute them to being SQL calls to the DB, the only difference is update delete and insert are single functions, the gets are based on where clauses. Instead of stripping it out into yet another service, its seems(opinion) that it seems the class should serve as the commands for data retrieval rather than splitting based on the very difference in functions. – lemunk Nov 13 '14 at 14:23
  • Yep, it's a nice convenience, when you fail as a programmer to follow the Single Responsibility Principle. Or to produce clean code in general. – Pierre-Luc Pineault Nov 13 '14 at 14:24
  • I agree to this, I would write as a side note: `It should be a short description of what it does, not what it is.` My POV; regions named `properties`, `methods`, `constructors` should be banished. – Jeroen van Langen Jan 27 '17 at 09:43