Skip to main content
Code Review

Return to Answer

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

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

@Jamal's idea in the comments idea in the comments about calling Print() ToString() instead is probably a better idea though. Like @BenAaronson pointed out, different implementations would require a lot of this duplicated logic different implementations would require a lot of this duplicated logic.

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

@Jamal's idea in the comments about calling Print() ToString() instead is probably a better idea though. Like @BenAaronson pointed out, different implementations would require a lot of this duplicated logic.

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

@Jamal's idea in the comments about calling Print() ToString() instead is probably a better idea though. Like @BenAaronson pointed out, different implementations would require a lot of this duplicated logic.

added 490 characters in body
Source Link
RubberDuck
  • 31.1k
  • 6
  • 73
  • 176

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

@Jamal's idea in the comments about calling Print()ToString() instead is probably a better idea though. Like @BenAaronson pointed out, different implementations would require a lot of this duplicated logic .

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

@Jamal's idea in the comments about calling Print()ToString() instead is probably a better idea though. Like @BenAaronson pointed out, different implementations would require a lot of this duplicated logic .

added 99 characters in body
Source Link
RubberDuck
  • 31.1k
  • 6
  • 73
  • 176

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

I know this is an old post, but it got bumped and I noticed this oddness:

 public string Print(int number)
 {
 if (fizzChecker.IsFizz(number) && buzzChecker.IsBuzz(number))
 {
 return "FizzBuzz";
 }
 if (fizzChecker.IsFizz(number))
 {
 return "Fizz";
 }
 if(buzzChecker.IsBuzz(number))
 {
 return "Buzz";
 }
 return number.ToString();
 }
}

I would expect a function named "Print" to print something (Probably to standard output), not return a string. Considering you have an interface for the printer, and you're printing to the Console, I would say that FizzBuzzPrinter should output directly to console. That way you can avoid doing this.

Console.WriteLine(fizzBuzzPrinter.Print(i));

And replace it with:

fizzBuzzPrinter.Print(i);

Different implementations of IFizzBuzzPrinter could Print to different outputs as necessary.

Source Link
RubberDuck
  • 31.1k
  • 6
  • 73
  • 176
Loading
lang-cs

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