Incorrect programming topic-resolve openwnn (4) style issues

Source: Internet
Author: User

Finally, let's talk aboutCodeStyle issues

1. Magic numbers, also known as numerical Constants

In short, there is a digital stamp, and no one knows what this means. This kind of code also causes a problem when the value of the code changes, it cannot be ensured that all relevant code is modified.

There are too many such cases in openwnn, so I will not list them one by one.

The same String constant is also a problem.

Defining constants in this case is not the only way to solve the problem. There are still many better methods, such as splitting categories.

2. Static table

Static block static {} in Java code can execute some fixed value assignment code in advance. However, if this feature is not used properly, it will become a problem in code.

In the romkan codeRomkantable indicates how the entered English letters are converted into Kana.

But after the code is written, it will be crowded together. And the related code is particularly long.

If the conversion code is put in XML, it is much better to load it at startup. In addition, Java imposes restrictions on the code length. If you want to write pinyin into Chinese characters in the same way, the compilation will fail.

The same problem occurs in the turbidity table, semi-Turbidity table, and keyboard switching table.

3. Unicode code

Defasoftsoftkeyboard has a lot of Unicode-written code "\ u3044". Who knows what it means?

These unicode can be stored as real characters in XML files for ease of understanding.

4. Empty catch

Catch must not be empty. If it must be empty, write a comment. In catch, only logs are printed and treated as null.

This is also common in openwnn.

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.