Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

    This class doesn't need the whole config file.

    There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  2. GetConfigSection isn't a very nice way to access the configuration.

    It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info .

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info .


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info .


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

    There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  2. GetConfigSection isn't a very nice way to access the configuration.

    It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info .


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info See here for more info.


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info.


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info.


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

Removed the redundant String.Format around the C# 6 interpolation
Source Link
t3chb0t
  • 44.6k
  • 9
  • 84
  • 190

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info.


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = String.Format($"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ");";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info.


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = String.Format($"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ");

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

I love that you're storing the interval in a config, but there's some issues with your implementation of that.

  1. This class doesn't need the whole config file.

There's no reason for this class to have knowledge of the entire configuration and how to access it. It only needs to know what the interval should be. I'd change your constructor so that you're just passing the interval.

  1. GetConfigSection isn't a very nice way to access the configuration.

It relies on a string key and string keys are very easy to misspell. It's much preferable to access these through the strong typing option that Settings.Default provides. See here for more info.


Lastly, this block looks like a wonderful place to extract a method and use String.Format

string days = Uptime.Days + " day" + (Uptime.Days != 1 ? "s" : "") + ", ";
string hours = Uptime.Hours + " hour" + (Uptime.Hours != 1 ? "s" : "") + ", and ";
string mins = Uptime.Minutes + " min" + (Uptime.Minutes != 1 ? "s" : "");
string UptimeString = days + hours + mins;

For example:

string days = String.Format("{0} day{1} , ", Uptime.Days, (Uptime.Days != 1 ? "s" : ""));

Or, even better, but only if you're using C# 6

string days = $"{Uptime.Days} day{(Uptime.Days != 1 ? "s" : "")} , ";

Once you do this for all 3, you'll see pretty quickly your opportunity to extract a method.

added some syntax that was missing
Source Link
Malachi
  • 29k
  • 11
  • 86
  • 188
Loading
added 342 characters in body
Source Link
RubberDuck
  • 31.1k
  • 6
  • 73
  • 176
Loading
Source Link
RubberDuck
  • 31.1k
  • 6
  • 73
  • 176
Loading
lang-cs

AltStyle によって変換されたページ (->オリジナル) /