Bits 'n Widgets
Thoughts on real-world, practical, common-sense approaches to Agile software development using Scrum and XP
Friday, July 18, 2008
« Artifact, Cause, and Resolution
|
Main
|
Agile Beer Night is Aug. 21 »
#region is a Code Smell.
I have heard a lot of discussion lately about the use of the "#region" directive in C#. There are various camps (some religious) on this topic, so let me throw in my twopence.
Many developers like to use regions to collapse sections of the code because it makes it easier for them to focus on a particular section. That's nice.
If there is that much code in a single file (which *should* be only ONE class), then there is probably too much code in that class. Class design should be focused on one specific thing. According to good OO principles, classes should be autonomous, and do one specific thing. Classes should be intelligent groupings for functionality relating to a specific, focused purpose. The use of the region to group code bits together in a file is a good indication that there is probably too much code.
Simplicity is a highly desired principle in software development. It's the simplest thing that gets the kudos, not the most complicated. Developers who try to write complex, convoluted code so that they can look good to their peers are really doing the opposite. Added complexity is very costly, in time for other people to understand it, debug it, and maintain it.
Here are some ways to determine some code smells in this area.
Do methods have more than 25 lines of code? If so they are probably too big - this is a code smell.
Do classes have more than 12 methods? If so, this may be another code smell. Classes that have lots of methods probably are doing too much. See if they can be broken out into more focused pieces.
Are there more than 3 constructors? Sometimes a lot of constructors could be a code smell indicating using a class for different things in different places.
Anyone else have any metrics that they use? Please respond with comments below.
These kinds of things should be completely discussed on a team, and woven into working agreements, and coding standards guidelines. Teams that work within these are the most productive because everyone is on the same page and playing by the same set of rules. If your team doesn't have a guideline for these kinds of things, I would encourage you to write one up today and get input from your team.
Design
|
Team
Friday, July 18, 2008 8:19:59 AM (Pacific Standard Time, UTC-08:00)
Disclaimer
|
Comments [0]
|
Trackback
Related posts:
Pair Programming - A Guideline
Preferences User Story
Automated Acceptance Tests - Who Should Write Them, Dev or QA?
Become a Certified Agile Developer!
Agile Software Design, Refactoring, and Warts
Truck Count
Comments are closed.
On this page....
Archives
<
November 2008
>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
October, 2008 (1)
September, 2008 (4)
August, 2008 (4)
July, 2008 (4)
June, 2008 (2)
May, 2008 (7)
April, 2008 (3)
March, 2008 (1)
Total Posts: 25
This Year: 25
This Month: 0
This Week: 0
Comments: 7
Search
Navigation
Agile FAQ
Agile Alliance
Agile Manifesto
Extreme Programming
Test Driven Developer
Test Driven Development, Defined (Wikipedia)
Test Driven Design
Test-Driven.com - Agile development tools
NUnit
Book: Test-Driven Development in Microsoft .NET
CodeProject - Advanced Unit Testing: Unit Test Patterns
John Boal's Personal Blog
John Boal's Agile Development Blog
Tags
ABN (3)
Acceptance Testing (2)
bugs (2)
Design (3)
DSL (1)
Refactoring (1)
scrum (8)
Security (2)
source control (1)
TDD (3)
Team (9)
testing (5)
User Interface (1)
Categories
ABN
Acceptance Testing
bugs
Design
DSL
Refactoring
scrum
Security
source control
TDD
Team
testing
User Interface
Blogroll
#2782
Ade Miller's Tech Blog
Agile Development
Mitch Lacey's Agile Development Blog
Agile FAQ
Frequently Asked Agile Questions - Vibhu's Blog
Espresso Fueled Agile Development
Mike Puleio's Blog
Geek Noise
Noise de Peter Provost
About
© Copyright 2008, John E. Boal
E-mail
Sign In