• Complain

Kristian Rother - Pro Python Best Practices: Debugging, Testing and Maintenance

Here you can read online Kristian 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, 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.

Kristian 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
  • 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.What Youll Learn Learn common debugging techniques that help you find and eliminate errors Gain techniques to detect bugs more easily Learn techniques to keep your project under controlWho This Book Is ForExperienced Python coders from web development, big data, and more.

Kristian 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.