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

  • Mastering matplotlib
  • Duncan M. McGreggor
  • 305字
  • 2021-07-16 14:11:19

Coding style

The coding style used throughout this book and in the example code conforms to the standards laid out in PEP 8, with one exception. When entering code into an IPython Notebook or providing modules that will be displayed in the notebook, we will not use two lines to separate what would be module-level blocks of code. We will just use one line. This is done to save screen space.

Something that might strike you as different in our code is the use of an extraordinary feature of Python 3—function annotations. The work for this was done in PEP 3107 and was added in the first release of Python 3. The use of types and static analysis in programming, though new to Python, is a boon to the world of software. It saves time in development of a program by catching bugs before they even arise as well as streamlining unit tests. The benefit of this in our particular case, with regard to the examples in this book, is quick, intuitive code clarification. When you look at the functions, you will instantly know what is being passed and returned.

Finally, there is one best practice that we adhere to that is not widely adopted in the Python programming community—functions and methods are kept small in all of our code. If more than one logical thing is happening in a function, we break it into multiple functions and compose as needed. This keeps the code clean and clear, making examples much easier to read. It also makes it much easier to write unit tests without some of the excessive parameterization or awkward, large functions and methods that are often required in unit tests. We hope that this leaves a positive, long-lasting impression on you so that this practice receives wider adoption.

主站蜘蛛池模板: 天津市| 永春县| 崇义县| 油尖旺区| 河曲县| 商南县| 无锡市| 喜德县| 松原市| 黄梅县| 侯马市| 本溪市| 沙田区| 古田县| 晋江市| 郧西县| 荥经县| 墨竹工卡县| 临猗县| 望奎县| 福安市| 房山区| 积石山| 巴青县| 武隆县| 南华县| 华蓥市| 班戈县| 淄博市| 许昌市| 金山区| 桑日县| 河源市| 瑞昌市| 阿克陶县| 视频| 扎鲁特旗| 宜良县| 清徐县| 泗水县| 靖州|