Bogdan Doicin
Bogdan Doicin

Reputation: 2416

Why is the Maintainability Index so low in this C# ctor?

I have a simple C# ctor, which initializes some variables:

public RSSSourceData()
{
    RSSVersion = "";
    ChannelTitle = "";
    ChannelLink = "";
    ChannelDescription = "";
    Category = "";
    Copyright = "";
    Language = "";
    PubDate = "";
    ManagingEditor = "";
    FileToProcess = "";
    OnlineSource = "";
}

All the variables are string variables.

When I ran the Code Metric for the entire project, for this ctor I get a Maintainability Index of 57. I expected it to be much higher, because there is nothing so complex that requires too much maintenance work in attributing values to variables.

What am I doing wrong here?

Later edit: the declaration of the class fields is:

   class RSSSourceData
    {
        public string RSSVersion;
        public string ChannelTitle;
        public string ChannelLink;
        public string ChannelDescription; 
        public string Category; 
        public string Copyright;
        public string Language; 
        public string PubDate; 
        public string ManagingEditor; 
        public List<string> NewsTitle = new List<string>(); 
        public List<string> NewsLink = new List<string>(); 
        public List<string> NewsDescription = new List<string>();     
        private string OnlineSource; 
        private string FileToProcess; 
        private List<string> FileContent = new List<string>(); 

(...methods come here)

Upvotes: 1

Views: 261

Answers (2)

qxg
qxg

Reputation: 7036

A quick answer is that it's affected by lines of code.

A long answer is that it's really hard to maintain.

  1. Why this class/ctor should maintain so many states at one time?
  2. Does any property/field depend on previous property/field initialization?
  3. When it gets longer, how could you make sure no missing protperty/field, or duplicated initialization?
  4. Do this class still follow high cohesion?
  5. If it's data contract class, can it be auto generated?

Upvotes: 1

Serg Shevchenko
Serg Shevchenko

Reputation: 765

Fields has been initialized with contsants. In your example they are empty. In common case they will have some values.

So if you need to change initial values you will need to dive into source code.

That is why maintainability is high.

Upvotes: 1

Related Questions