Code 1-2-3

Source: Internet
Author: User

When I came to an outsourcing company, I felt the pressure to survive. I often worked overtime and had no time to rest. Let alone reading books or doing other interesting things. The first thing to do is sacrifice.CodeQuality. I hope that I can keep my code requirements concise and powerful.

A bug was received last week to modify a message. For a business operation, if there is a receipt proof (receipnumber), the displayed message for the user will be all different, the simplest and most direct implementation:

 
If (string. isnullorempty (this. _ presenter. receiptnumber) {If (utility. showmessagebox (messages. tenancy. tnc059 ). equals (dialogresult. no) return;} else {If (utility. showmessagebox (messages. tenancy. tnc131 ). equals (dialogresult. no) return ;}

This snippets is not awkward. In the code, this snippets is also set in another if... That's ugly in else. I want to shorten the number of lines of code:

 
If (utility. showmessagebox (string. isnullorempty (this. _ presenter. receiptnumber )? Messages. tenancy. tnc131: messages. tenancy. tnc059). Equals (dialogresult. No) return;

However, this code is not expressive enough. I modified it again to enhance the expressiveness.

VaR message = string. isnullorempty (this. _ presenter. receiptnumber )? Messages. tenancy. tnc131: messages. tenancy. tnc059; If (utility. showmessagebox (Message). Equals (dialogresult. No) return;

Now, I am more satisfied.

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.