What are the differences between python and lua closures?

Source: Internet
Author: User

In the third and fourth sections, we mainly discuss the precautions in the specific programming and development practices. Compared with the first and second sections, these are more specific and specific to variables. If a novice programmer reads this book, it should be a good choice from here, because it is close to practice and can give people the most direct feeling. Unfortunately, I didn't see this book when I started programming.

Here, variable naming is not arbitrarily defined and emphasizes the meaning of variable expression. The author believes that a reasonable variable naming can enable the program to annotate itself and read it naturally, making it difficult to make mistakes. Variables usually need to be initialized. Although many languages do not force this point, it is easy to forget this point when learning programming; control the scope of variables, and use less global variables; paying close attention to the pointers in the program and dynamically allocating memory, the memory leakage and buffer overflow generated by them have plagued people for decades. Although many papers and tools have been published, the problem persists. In the current development process (Lua language), if you define global variables at a certain location (outside the predefined permitted location), a warning is output, you must change it to a local variable. Regarding the scope, in a language such as python, Lua, or OCaml, a function (closure) can be defined in a function. In this case, the so-called upvalue is generated, which deserves special attention, in addition, different languages have different functions (python and lua closure are different), so remember to program in one language.

When using statements, the book also discussed many aspects, that is, to make the program readable, easy to read, and beautiful. In order to achieve the desired results, the author also proposed some methods, such as the table-driven method, generally, a statement cannot be too long to express too many operations or condition judgments in one breath, and cannot be nested between statements, all statements should be expressed at the same abstract level. Pay attention to the expected normal and illegal paths, avoid statements (such as priority order problems) that are correct but easy to be misunderstood (mainly for people who are not fully familiar with the language, but who can say they are completely familiar with a language ), careful use of goto (Lua does not use goto ). In actual work, it is found that more problems are not the statements themselves, but the abstraction of the problems. Which statements should be organized together into a function, variable naming and statement writing will be much smoother.

These two parts are very practical and operable. They are especially suitable for beginners to read and learn. At the beginning, the habits are easy to develop and change. It is a good habit to accept good habits. The problems involved in these two parts, how the results will determine the final quality of the system, and the perfection of the planning and design will ultimately be reflected in the correct and reliable implementation, as the first-line coding personnel, we must understand it carefully.

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.