Code details refactoring: Please point out my code (4)

Source: Internet
Author: User

This is a piece of code discussed at the code review meeting last week. This code is used to calculate the maximum number of pages based on the specified number of records and page size.

Target code
               ComputePages( totalRecords,        total =      size =       temp = total /       ( }
Code Problems

I didn't notice this code at the beginning of the Code review meeting. But after reading multiple code pages, I found that the "ComputePages" method was redefined multiple times and has the same functionality. It should have been copied and pasted by developers. I originally wanted to talk about this code for copying and pasting, but later I found more problems:

Reconstruction suggestions

If the problem is found, there will be some solutions:

  • For code reuse, you can define this method in a business logic-related class, instead of being dispersed into different classes. However, this article will not discuss this issue in detail;
  • For data type security and data type conversion, we should consider appropriate mathematical methods to solve these problems, rather than rigid programming language specifications;
  • We must be careful when coding the theorem that the denominator cannot be zero! Never be lucky;
  • For business logic problems, we must carefully think about and ponder over the problems to be solved and the possible consequences before coding;
Reconstruction result

To make it easier for everyone to understand, I have pasted some specific ideas and ideas about code refactoring into the code in the form of remarks. You can seriously observe and raise questions.

                         ComputePages( totalRecords,                         (totalRecords < )                          (pageSize < )                         ()Math.Ceiling(totalRecords*/ }
Conclusion

As the saying goes, Details determine success or failure. As a programmer, from the details of the code, we can see the level of a person's programming and the amount of development experience, which also determines your success and failure in a certain sense!

I have published many articles to guide new users from the humanistic perspective. Today, this article also illustrates the impact of humanistic factors on the Quality of programmers!

To do things, be a good person first. Responsible for your code is responsible for yourself, responsible for yourself is responsible for the team, responsible for the team is responsible for the interests of the enterprise, because we are the same team and have the same benefits!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.