Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

DRY Code

##DRY Code ThereThere is a programming principle called the Don't Repeat Yourself Principle sometimes referred to as DRY code. If you find yourself repeating the same code multiple times it is better to encapsulate it in a function. If it is possible to loop through the code that can reduce repetition as well.

This code repeats many times with minor variations:

 int ABx5 = Math.Max(arr[2, 0], arr[1, 0]);
 int ABy5 = Math.Max(arr[2, 1], arr[1, 1]);
 int ABx6 = Math.Min(arr[2, 2], arr[1, 2]);
 int ABy6 = Math.Min(arr[2, 3], arr[1, 3]);

It might be better to create a function that performs this.

Complexity

##Complexity TheThe function FindPoints() is too complex (does too much). All software design methods include breaking the problem into smaller and smaller pieces until the problem is very easy to solve. Smaller functions are easier to read, write, debug and maintain.

There is a programming principle called the Single Responsibility Principle that applies here. The Single Responsibility Principle states:

that every module, class, or function should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by that module, class or function.

In addition to the possible function mentioned above in the DRY Code section, it might be better to add a function that only gets the input and creates the arrays, a function that finds the overlap of the rectangles and a function that calculates the area of each rectangle.

Variable Names

##Variable Names FromFrom the problem description, it is not clear why there are any variable names related to money or compensation, which means that the variables that refer to this are unclear. The variable name T may come from the original problem description on the website, but it isn't clear here either.

##DRY Code There is a programming principle called the Don't Repeat Yourself Principle sometimes referred to as DRY code. If you find yourself repeating the same code multiple times it is better to encapsulate it in a function. If it is possible to loop through the code that can reduce repetition as well.

This code repeats many times with minor variations:

 int ABx5 = Math.Max(arr[2, 0], arr[1, 0]);
 int ABy5 = Math.Max(arr[2, 1], arr[1, 1]);
 int ABx6 = Math.Min(arr[2, 2], arr[1, 2]);
 int ABy6 = Math.Min(arr[2, 3], arr[1, 3]);

It might be better to create a function that performs this.

##Complexity The function FindPoints() is too complex (does too much). All software design methods include breaking the problem into smaller and smaller pieces until the problem is very easy to solve. Smaller functions are easier to read, write, debug and maintain.

There is a programming principle called the Single Responsibility Principle that applies here. The Single Responsibility Principle states:

that every module, class, or function should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by that module, class or function.

In addition to the possible function mentioned above in the DRY Code section, it might be better to add a function that only gets the input and creates the arrays, a function that finds the overlap of the rectangles and a function that calculates the area of each rectangle.

##Variable Names From the problem description, it is not clear why there are any variable names related to money or compensation, which means that the variables that refer to this are unclear. The variable name T may come from the original problem description on the website, but it isn't clear here either.

DRY Code

There is a programming principle called the Don't Repeat Yourself Principle sometimes referred to as DRY code. If you find yourself repeating the same code multiple times it is better to encapsulate it in a function. If it is possible to loop through the code that can reduce repetition as well.

This code repeats many times with minor variations:

 int ABx5 = Math.Max(arr[2, 0], arr[1, 0]);
 int ABy5 = Math.Max(arr[2, 1], arr[1, 1]);
 int ABx6 = Math.Min(arr[2, 2], arr[1, 2]);
 int ABy6 = Math.Min(arr[2, 3], arr[1, 3]);

It might be better to create a function that performs this.

Complexity

The function FindPoints() is too complex (does too much). All software design methods include breaking the problem into smaller and smaller pieces until the problem is very easy to solve. Smaller functions are easier to read, write, debug and maintain.

There is a programming principle called the Single Responsibility Principle that applies here. The Single Responsibility Principle states:

that every module, class, or function should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by that module, class or function.

In addition to the possible function mentioned above in the DRY Code section, it might be better to add a function that only gets the input and creates the arrays, a function that finds the overlap of the rectangles and a function that calculates the area of each rectangle.

Variable Names

From the problem description, it is not clear why there are any variable names related to money or compensation, which means that the variables that refer to this are unclear. The variable name T may come from the original problem description on the website, but it isn't clear here either.

Source Link
pacmaninbw
  • 26.1k
  • 13
  • 47
  • 114

##DRY Code There is a programming principle called the Don't Repeat Yourself Principle sometimes referred to as DRY code. If you find yourself repeating the same code multiple times it is better to encapsulate it in a function. If it is possible to loop through the code that can reduce repetition as well.

This code repeats many times with minor variations:

 int ABx5 = Math.Max(arr[2, 0], arr[1, 0]);
 int ABy5 = Math.Max(arr[2, 1], arr[1, 1]);
 int ABx6 = Math.Min(arr[2, 2], arr[1, 2]);
 int ABy6 = Math.Min(arr[2, 3], arr[1, 3]);

It might be better to create a function that performs this.

##Complexity The function FindPoints() is too complex (does too much). All software design methods include breaking the problem into smaller and smaller pieces until the problem is very easy to solve. Smaller functions are easier to read, write, debug and maintain.

There is a programming principle called the Single Responsibility Principle that applies here. The Single Responsibility Principle states:

that every module, class, or function should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by that module, class or function.

In addition to the possible function mentioned above in the DRY Code section, it might be better to add a function that only gets the input and creates the arrays, a function that finds the overlap of the rectangles and a function that calculates the area of each rectangle.

##Variable Names From the problem description, it is not clear why there are any variable names related to money or compensation, which means that the variables that refer to this are unclear. The variable name T may come from the original problem description on the website, but it isn't clear here either.

lang-cs

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