官术网_书友最值得收藏!

Chapter 2. Syntax Best Practices – below the Class Level

The ability to write an efficient syntax comes naturally with time. If you take a look back at your first program, you will probably agree with this. The right syntax will appear to your eyes as a good-looking piece of code, and the wrong syntax as something disturbing.

Besides the algorithms that are implemented and the architectural design for your program, taking great care over how it is written weighs heavily on how it will evolve. Many programs are ditched and rewritten from scratch because of their obtuse syntax, unclear APIs, or unconventional standards.

But Python has evolved a lot in the last few years. So, if you were kidnapped for a while by your neighbor (a jealous guy from the local Ruby developers user group) and kept away from the news, you will probably be astonished by its new features. From the earliest version to the current one (3.5 at this time), a lot of enhancements have been made to make the language clearer, cleaner, and easier to write. Python basics have not changed drastically, but the tools to play with them are now a lot more ergonomic.

This chapter presents the most important elements of modern syntax and tips on their usage:

  • List comprehensions
  • Iterators and generators
  • Descriptors and properties
  • Decorators
  • with and contextlib

The code performance tips for speed improvement or memory usage are covered in Chapter 11, Optimization – General Principles and Profiling Techniques, and Chapter 12, Optimization – Some Powerful Techniques.

主站蜘蛛池模板: 钟山县| 聂荣县| 彩票| 高邮市| 四川省| 商洛市| 安徽省| 四平市| 浦江县| 英超| 察哈| 大埔县| 舟曲县| 青岛市| 博白县| 大同县| 新野县| 怀来县| 安宁市| 亳州市| 贵港市| 花莲市| 大洼县| 龙岩市| 宣汉县| 布拖县| 隆昌县| 崇文区| 额济纳旗| 昭平县| 玉林市| 云安县| 峨山| 栾川县| 永仁县| 潮安县| 台湾省| 宝山区| 肇源县| 贵德县| 滁州市|