Clean code ------ Yushan can be reconstructed: ID card number parsing and verification tools (Day 1)

Source: Internet
Author: User

The original Code gave me a good starting point. Yes, these codes are all jade. I just want to think about them again. Even so, the refactoring process is still very cumbersome, and the article may be very long. Every refactoring requires displaying all the code. It is difficult to understand and implement. refactoring is a dynamic process, which is not so easy to present. You need to be patient and take a look. 1-convert to C # code and add the first test. Yes, this is not necessary. It can be said that it is my own reason and it will not be Java. However, you can also think of it as a reconstruction scenario, right? The changed code is no longer put. It is relatively simple. It is related to the difference between C # and Java, leaving a connection to SocialID. cs. However, my test code is very important. Many may criticize my testing framework (Machine. Specification) and Code style. The former, I think we will introduce MSpec and BDD in the future to familiarize everyone with it. The latter can only be applied to everyone. ==> Write the first test code www.2cto.com: when you enter the correct ID card, you should be able to get the correct birthday. [C #] namespace Skight. eLiteWeb. domain. specs {public class when_create_social_id_with_proper_input {private Because of = () => subject = new SocialID ("43010319801120753"); private It should_get_birth_date_correctly = () => subject. getBirthDate (). shouldEqual (new DateTime (1980, 11, 20); private static SocialID subject ;}=> run the first test, failed :) interestingly, after resolving the C # syntax translation, my first test failed.
==> Refactor the original, seemingly identical syntax Substring, but the second parameter has different meanings. The test can streamline this process. [Java] private String getBirthDayPart () {return this. cardNumber. change substring (6, 14);} to [c #] private String getBirthDayPart () {return this. cardNumber. substring (6, 8) ;}=> test again
==> The first iteration ends, rest. well, the results of the phase can be marked as a milestone for a test/behavior. Today is the end of the process. Your support will allow me to continue tomorrow. Oh, Shao et. the last step is indeed the most important step. to our customers (in this case, my customers are other developers, and yes, the customers of senior programmers are other intermediate and junior programmers. Change your mind) the test/function report of is as follows:
 

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.