• Complain

Rother - Pro Python best practices: debugging, testing and maintenance

Here you can read online Rother - Pro Python best practices: debugging, testing and maintenance full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: Berkeley;CA;United States, year: 2017, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Rother Pro Python best practices: debugging, testing and maintenance
  • Book:
    Pro Python best practices: debugging, testing and maintenance
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2017
  • City:
    Berkeley;CA;United States
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Pro Python best practices: debugging, testing and maintenance: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Pro Python best practices: debugging, testing and maintenance" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Learn software engineering and coding best practices to write Python code right and error free. In this book youll see how to properly debug, organize, test, and maintain your code, all of which leads to better, more efficient coding. Software engineering is difficult. Programs of any substantial length are inherently prone to errors of all kinds. The development cycle is full of traps unknown to the apprentice developer. Yet, in Python textbooks little attention is paid to this aspect of getting your code to run. At most, there is a chapter on debugging or unit testing in your average basic Python book. However, the proportion of time spent on getting your code to run is much higher in the real world. Pro Python Best Practices aims to solve this problem. You will: Learn common debugging techniques that help you find and eliminate errors Gain techniques to detect bugs more easily ver best= practices= to= prevent= bugscarry= out= automated= testing= discover= problems= faster Use best practices to maintain a project over a long time Learn techniques to keep your project under control.;Chapter 2: Exceptions in PythonExceptions Are Defects We Know About; Reading the Code; SyntaxError; Best Practices for Debugging SyntaxErrors; Examining the Error Message; The Error Type; The Error Description; The Traceback; Deduction; Catching Exceptions; Best Practices for Debugging IOErrors; Errors and Defects; Where Do Defects Come From?; The Correct Code; Best Practices; Chapter 3: Semantic Errors in Python; Comparing Expected and Factual Output; Defects; Defects in Variable Assignments; Multiple Initialization; Accidental Assignment; Accidental Comparison.;Overview of IPython CommandsExploring Namespaces; Exploring Namespaces with dir(); Exploring Namespaces of Objects; Exploring Attributes in a Python Program; Alternatives to dir in IPython; Namespace Mechanics; Python Uses Namespaces for Its Own Functions; Modifying a Namespace; Namespaces and Local Scope; Namespaces Are a Core Feature of Python; Using Self-Documenting Objects; Accessing Docstrings with help(); Object Summaries in IPython; Analyzing Object Types; Checking Object Identity; Checking Instances and Subclasses; Practical Use of Introspection; Finding Typos with Introspection.;Explain the Problem to Someone ElsePair Programming; Code Reviews; Reading; Cleaning Up; The Scientific Method and Other Best Practices; Best Practices; Chapter 5: Debugging with print Statements; Diagnose Whether Code Was Executed; Print the Content of Variables; Pretty-Printing Data Structures; Simplify Input Data; Start with Minimal Input; Gradually Add More Input Data; Switching print Output On and Off; Complete Code; Pros and Cons of Using print Statements; Best Practices; Chapter 6: Debugging with Introspection Functions; Explorative Coding in IPython; Exploring Files and Directories.;At a Glance; Contents; About the Author; About the Technical Reviewer; Acknowledgments; Preface; Chapter 1: Introduction; A Lesson in Humility; The Case for Best Practices in Python; The Origin of Best Practices; Hacking; Software Engineering; Agile; Software Craftsmanship; Who This Book Is For; What This Book Is About; Part 1: Debugging; Part 2: Automated Testing; Part 3: Maintenance; Further Benefits; The MazeRun Game; How to Use This Book?; Install Python 3; Install the Pygame Library; Install a Text Editor; Download the Source Code Examples; Part I: Debugging.;Wrong Variables in an ExpressionSwapped Literals in Expression; Defects in Indexing; Creating Wrong Indices; Using Wrong Indices; Defects in Control Flow Statements; Defects in Boolean Expressions; Defects with Indentation; Defects in Using Functions; Omitting a Function Call; Missing Return Statement; Not Storing the Return Value; Error Propagation; Best Practices; Chapter 4: Debugging with the Scientific Method; Applying the Scientific Method; Reproducing the Error; Automating the Error; Isolating the Defect; The Strip-Down Strategy; The Binary Search Strategy; Getting Help; Taking a Break.

Rother: author's other books


Who wrote Pro Python best practices: debugging, testing and maintenance? Find out the surname, the name of the author of the book and a list of all author's works by series.

Pro Python best practices: debugging, testing and maintenance — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Pro Python best practices: debugging, testing and maintenance" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Kristian Rother 2017
Kristian Rother Pro Python Best Practices 10.1007/978-1-4842-2241-6_1
1. Introduction
Kristian Rother 1
(1)
Berlin, Germany
A Lesson in Humility
I started writing my first computer game when I was 16. It was a puzzle game where you had to move bricks and make them disappear. A couple of friends joined the project, and soon the game featured a detailed concept, graphics, levels, and even a penguin mascot (the Linux mascot was yet to be invented). Only the program had to be written. At that time, I was coding in the assembler language on a C64 computer. At first, programming was easy. In juvenile audacity I was convinced that programming meant throwing enough brain at writing code, until it worked. I had already written many small programs like this and everything had worked fine. But soon, programming the graphics and game mechanics turned out to be more difficult than I had thought. I was spending days trying to get small improvements to work, with little or no progress. My programming workflow was
  1. Turn on the computer
  2. Load the compiler
  3. Load the program
  4. Write a few lines of code
  5. Run the program
  6. Frequently, the program would crash and take down the operating system
  7. Switch off the computer and return to step 1
Effectively, I was spending not more than a rough 10% of my time actually working on the code. It is not surprising that development slowed down and soon came to a halt completely. At the moment, the project is 23 years late. It took me very long to figure out what had happened. Any mentor (an experienced programmer or an older version of myself) would have insisted on finding a shortcut from step 5 to step 4. Such shortcuts existed at the time in the form of a cartridge you plugged into the back of the computer. Finding these shortcuts is not a trivial matter. Yet they make all the difference. We will call these shortcuts Best Practices .
The Case for Best Practices in Python
Today, 23 years later, we have Python , a language that makes many things easier. We dont have to restart the computer when the program contains an error. We have libraries like Pygame that help us to create nicer and faster graphics with very little code. Do we still need Best Practices for writing Python code? Although you will anticipate my point of view from the title of this book, I would like to start with a simple example that explains why it is still worth to think about Best Practices in Python. Suppose we want to create graphics for our own small game using Python and Pygame . As a proof of concept, we will load two images, one with a level and one with the player figure, and combine them to a single image (Figure ). The functions in the Pygame library do most of the work. To combine the images and save them to a new file, only five lines of code are needed:
Figure 1-1 Two images to be combined with Pygame from pygame import image - photo 1
Figure 1-1.
Two images to be combined with Pygame
from pygame import image, Rect
maze = image.load(maze.png)
player = image.load(player.png)
maze.blit(player, Rect((32, 32, 64, 64)), Rect((0, 0, 32, 32)))
image.save(maze, merged.png)
At first sight, the program looks dead simple. What is more, it works correctly and produces a merged image. The program is too short to fail or is it? I took the time to enumerate ways in which this five-line program might fail:
  • A typo in the program terminates Python with a SyntaxError
  • Pygame is not installed, so Python exits with an ImportError
  • An incompatible version of Pygame is installed, so Python terminates with an Exception
  • One of the image files does not exist, so Python exits with an IOError
  • There is no write permission for the output image, so Python terminates with an IOError
  • One of the image files is corrupted, so Python terminates with an Exception
  • One of the image files is distorted, so the output image will be distorted as well
  • The program is incompatible with Python 3, so users are dependent on Python 2
  • Generating the image is too slow, so the game becomes unplayable
  • Image transparency is not handled correctly, so artifacts appear in the output image
  • A wrong output file name is given, so an important file is overwritten
  • Pygame contains malicious code, so system security becomes compromised
  • The program is distributed with unlicensed images, so the authors have IP lawyers at their neck
  • The program does not run on mobile phones, so nobody wants to use it
  • There is no documentation, so potential users are unable to install or use the program
I am sure you can find even more potential problems. Even in a five-line program, many more than five things can go wrong. We can be sure that even more things can go wrong in a long program. When we look at the list of problems more closely, we see that some of the problems are clearly connected to the code itself (e.g., the wrong import). Others, like the lack of documentation or the legal issues) have nothing to do with the code itself, yet they have severe consequences.
Conclusion
Some problems in programming can be solved by programming. Other problems in programming cannot be solved by programming. As programmers, we are responsible for both.
No matter what the problem is, we, the programmers, and our users will have to live with the consequences. I am frequently using my own five-line Python programs for small tasks (e.g., merging PDFs or shrinking digital camera images). As the only user, I can easily change the code or rewrite the program completely. But if we want to write bigger programs, programs with more users, and cooperate with other programmers, we need to prevent our projects from coming to a standstill. We need to prevent running into too many problems at the same time. We need techniques that keeps our program healthy and easy to work with. The premise of this book is to introduce you to established techniques or Best Practices to write better Python programs.
The Origin of Best Practices
How can we create well-written programs that solve or avoid the previously described problems? There are several schools of thought that have put a lot of energy into the subject. Here, we will explore whether they help us (see Figure ).
Figure 1-2 Building a house as a metaphor for building software Upper left - photo 2
Figure 1-2.
Building a house as a metaphor for building software. Upper left: Hacking, love for the challenge of overcoming technical limitations. Upper right: Software engineering, a systematic approach found in large projects. Lower left: Agile, fast, iterative development. Note that the product is inhabited by the end user while development goes on. Lower right: Software craftsmanship, focusing on doing things right using a set of established tools.
Hacking
According to Richard Stallman, hackers have love of excellence and programming in common ( Hackers: Wizards of the Electronic Age, 1985, TV documentary). They enjoy the creative challenging to overcome technical limitations and achieve things not thought possible before. People who are good at hacking are indispensable in todays technology-driven society. Hacking is a key skill, and we need people who are good at it. Without doubt, hacking is a useful skill in programming. Python is an excellent language to hack things in.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Pro Python best practices: debugging, testing and maintenance»

Look at similar books to Pro Python best practices: debugging, testing and maintenance. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Pro Python best practices: debugging, testing and maintenance»

Discussion, reviews of the book Pro Python best practices: debugging, testing and maintenance and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.