Regions

Oct 6, 2010 at 6:09 AM

How does the team feel about regions? I hate 'em and would like to see them gone. Yeah, I'm pretty blunt.

  • Serve no real purpose IMHO. Basically ;)
  • Make the code more effort to read/review. Hover over a region and it only shows a portion of the code so you have to expand the region to see what the code is about.
  • If you don't remember to put some code in some named region (because it should be there by naming standard) it's a bunch of work to keep it maintained.
  • Don't agree that it makes the code "more compact". I should be able to see the code easily no matter what and if there's anything more than a screen of code it's time to refactor anyways
Oct 6, 2010 at 12:34 PM

Never mind, I found this in our guidelines:

  • Regions (#region) are not used.

Shows how closely I paid attention to them. There are many files with regions in them so just a note for people if you can nuke them on any files before you issue a pull request or commit. Here's an IDE macro I created (based on something Kyle Baley wrote after I got peeved at the team using regions a few years back).

Sub ClearRegions()
    With DTE.Find
        Dim saveTarget As vsFindTarget = .Target
        Dim saveMatchCase As Boolean = .MatchCase
        Dim saveMatchWholeWord As Boolean = .MatchWholeWord
        Dim saveMatchInHiddenText As Boolean = .MatchInHiddenText
        Dim savePatternSyntax As vsFindPatternSyntax = .PatternSyntax

        .Action = vsFindAction.vsFindActionReplaceAll
        .FindWhat = "^:b*\#region.*\n"
        .ReplaceWith = ""
        .Target = vsFindTarget.vsFindTargetCurrentDocument
        .MatchCase = False
        .MatchWholeWord = False
        .MatchInHiddenText = True
        .PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
        .ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        .Action = vsFindAction.vsFindActionReplaceAll

        .Execute()

        .FindWhat = "^:b*\#endregion.*\n"
        .ReplaceWith = ""
        .Target = vsFindTarget.vsFindTargetCurrentDocument
        .MatchCase = False
        .MatchWholeWord = False
        .MatchInHiddenText = True
        .PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
        .ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        .Action = vsFindAction.vsFindActionReplaceAll

        .Execute()

        .Target = saveTarget
        .MatchCase = saveMatchCase
        .MatchWholeWord = saveMatchWholeWord
        .MatchInHiddenText = saveMatchInHiddenText
        .PatternSyntax = savePatternSyntax
    End With
End Sub

Oct 6, 2010 at 3:33 PM

hmm, it seems like we have many odd guidelines here. Region may cause troubles to people who *read*code, but is extremely convenient for those who *writes* code. Having regions allow me to collapse a big chunk of code which I may not be interested in at a particular time, and therefore it reduces the amount of scrolling I have to do.

There is a setting in VS which enables you to automatically expand all regions when a new file is open. Does that work for you?

Oct 6, 2010 at 3:35 PM

I'll go with the collective as far as a decision is. The VS "features" of expanding or collapsing regions is nice if you want to use regions, I just don't subscribe to your statement that it's convenient for people who write code. I don't think it is.

Oct 6, 2010 at 3:44 PM
Yeah, I am not a fan of regions at all.

If you have a 'big' chunk of code that you want to add, I would identify that code for refactoring, rather than hide it.

Small Classes and Small Methods FTW

-d

On Wed, Oct 6, 2010 at 10:35 AM, bsimser <notifications@codeplex.com> wrote:

From: bsimser

I'll go with the collective as far as a decision is. The VS "features" of expanding or collapsing regions is nice if you want to use regions, I just don't subscribe to your statement that it's convenient for people who write code. I don't think it is.

Read the full discussion online.

To add a post to this discussion, reply to this email (nupack@discussions.codeplex.com)

To start a new discussion for this project, email nupack@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Developer
Oct 6, 2010 at 4:23 PM
Edited Oct 6, 2010 at 4:24 PM

fail, no regions :). We have to bug to clean up the code base that doesn't follow th guidelines and if the guidelines. Expect going forward that this will all be fixed. 

Oct 6, 2010 at 4:31 PM
drusellers wrote:

If you have a 'big' chunk of code that you want to add, I would identify that code for refactoring, rather than hide it.

Small Classes and Small Methods FTW

 It's not always that clear cut. If you are writing a WPF/Silverlight control and you declare at least 5 dependency properties (which is a very normal thing to do), it will be at least 50 lines long. And most of time, you will never need to touch those properties again. So it makes no sense to keep scrolling past those properties every time.

Anyway, it's not the end of the world without regions. I can totally live with that.

Oct 6, 2010 at 5:27 PM
Maybe its ok in WPF control then. ??? :/

I am getting ready to leave for a very long flight next week and will pull the source and spend some time reviewing it. so that i can provide more context sensitive thoughts.

Thanks again everyone!!

-d

On Wed, Oct 6, 2010 at 11:31 AM, dotnetjunky <notifications@codeplex.com> wrote:

From: dotnetjunky

drusellers wrote:

If you have a 'big' chunk of code that you want to add, I would identify that code for refactoring, rather than hide it.

Small Classes and Small Methods FTW

 It's not always that clear cut. If you are writing a WPF/Silverlight control and you declare at least 5 dependency properties (which is a very normal thing to do), it will be at least 50 lines long. And most of time, you will never need to touch those properties again. So it makes no sense to keep scrolling past those properties every time.

Anyway, it's not the end of the world without regions. I can totally live with that.

Read the full discussion online.

To add a post to this discussion, reply to this email (nupack@discussions.codeplex.com)

To start a new discussion for this project, email nupack@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Oct 6, 2010 at 5:51 PM

I’m ok with making the exception in that one case since it’s out of our control.