Big talk Design pattern (two code specification, reconstruction) _ Vegetable programming growth

Source: Internet
Author: User
Dahua design Pattern (two code specification, refactoring)

(Continuation of the article)
Big Bird said: "And do not say the topic of the person's meaning, alone in your current code, there are many deficiencies need to improve." Like variable naming, your name is ABCD, the variable does not have any concrete meaning, this is very irregular; Judging branch, you're writing like this, meaning that every condition has to be judged, equal to three times the computer did no work; Data entry validity judgments, etc., if the user entered a character symbol instead of a number. If the divisor, the customer entered 0 what to do. These are areas that can be improved. ”
"Oh, that's right, I have heard the teacher said before, but never cared about, I immediately change, change the end to show you." ”

Class Program {static void Main (string[] args) {try {console.write ("Please enter a number a:");
            String strnumbera = Console.ReadLine ();
            Console.Write ("Please select the operator symbol (+ 、-、 *,/):");
            String stroperate = Console.ReadLine ();
            Console.Write ("Please enter the number B:");
            String strnumberb = Console.ReadLine ();

            String strresult = ""; Switch (stroperate) {case "+": strresult = convert.tostring (Convert.todou
                    BLE (Strnumbera) + convert.todouble (strnumberb));
                Break
                    Case "-": Strresult = convert.tostring (convert.todouble (Strnumbera)-convert.todouble (Strnumberb));
                Break
                    Case "*": Strresult = convert.tostring (convert.todouble (Strnumbera) * convert.todouble (Strnumberb));
                Break Case "/": if (Strnumberb!= "0") strresult = Convert.ToString (convert.todouble (Strnumbera)/convert.todouble (Strnumberb));
                    else strresult = "Divisor cannot be 0";
            Break
            
            } Console.WriteLine ("The result is:" + strresult);


        Console.ReadLine (); The catch (Exception ex) {Console.WriteLine ("Your input is wrong:" + ex.)
        message); }
    }
}

Big Bird: "Ho ho, yes, yes, change quickly." To the current code, the implementation of the calculator is no problem, but this write code is the meaning of the author. ”
Side dishes: "You mean object oriented." ”
Big Bird: "Ha, the vegetable is not the vegetable also." ”

adjourned

Source: http://www.cnblogs.com/cj723/archive/2006/08/30/490094.html

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.