• Complain

Jeff Knupp - Writing Idiomatic Python 3

Here you can read online Jeff Knupp - Writing Idiomatic Python 3 full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2016, publisher: CreateSpace, 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.

Jeff Knupp Writing Idiomatic Python 3
  • Book:
    Writing Idiomatic Python 3
  • Author:
  • Publisher:
    CreateSpace
  • Genre:
  • Year:
    2016
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Writing Idiomatic Python 3: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Writing Idiomatic Python 3" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Write. Idiomatic. Code.Get pythonic from the start: concise guide to idiomatic code; best after another text, but suits some brave learners.

Jeff Knupp: author's other books


Who wrote Writing Idiomatic Python 3? Find out the surname, the name of the author of the book and a list of all author's works by series.

Writing Idiomatic Python 3 — 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 "Writing Idiomatic Python 3" 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
Writing Idiomatic Python
Jeff Knupp

Copyright 2013

Writing Idiomatic Python
Dedication

For my girls, Elissa, Alexandra, and Olivia. Thanks for putting up with your husband/daddy living at Starbucks every weekend.

Love, Dad

December, 2013

Preface

Theres a famous old quote about writing maintainable software:

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.--John Woods comp.lang.c++

While Im not usually one for aphorisms, this one strikes a chord with me. Maybe its because Ive spent my professional career writing software at huge companies, but I have yet to inherit code that didnt eventually cause me to curse the original author at some point. Everyone (besides you, of course, dear reader) struggles to write code thats easy to maintain. When Python became popular, many thought that, because of its terseness, it would naturally lead to more maintainable software.

Alas, maintainability is not an emergent property of using an expressive language. Badly written Python code is just as unmaintainable as badly written C++, Perl, Java and all the rest of the languages known for their, ahem, readability. Terse code is not a free lunch.

So what do we do? Resign ourselves to maintaining code we cant understand? Rant on Twitter and The Daily WTF about the awful code we have to work on? What must we do to stop the pain?

Write. Idiomatic. Code.

Its that simple. Idioms in a programming language are a sort of lingua franca to let future readers know exactly what were trying to accomplish. We may document our code extensively, write exhaustive unit tests, and hold code reviews three times a day, but the fact remains: when someone else needs to make changes, the code is king. If that someone is you, all the documentation in the world wont help you understand unreadable code. After all, how can you even be sure the code is doing what the documentation says?

Were usually reading someone elses code because theres a problem. But idiomatic code helps here, too. Even if its wrong, when code is written idiomatically, its far easier to spot bugs. Idiomatic code reduces the cognitive load on the reader. After learning a languages idioms, youll spend less time wondering Wait, why are they using a named tuple there and more time understanding what the code actually does.

After you learn and internalize a languages idioms, reading the code of a like-minded developer feels like speed reading. Youre no longer stopping at every line, trying to figure out what it does while struggling to keep in mind what came before. Instead, youll find yourself almost skimming the code, thinking things like OK, open a file, transform the contents to a sorted list, generate the giant report in a thread-safe way. When you have that level of insight into code someone else wrote, theres no bug you cant fix and no enhancement you cant make.

All of this sounds great, right? Theres only one catch: you have to know and use a languages idioms to benefit. Enter Writing Idiomatic Python. What started as a hasty blog post of idioms (fueled largely by my frustration while fixing the code of experienced developers new to Python) is now a full-fledged eBook.

I hope you find the book useful. It is meant to be a living document, updated in near-real time with corrections, clarifications, and additions. If you find an error in the text or have difficulty deciphering a passage, please feel free to email me at . With their permission, Ill be adding the names of all who contribute bug fixes and clarifications to the appendix.

Cheers,

Jeff Knupp

January, 2013

Change List
3.1 Version 1.1, February 2, 2013
  • New idiom: Use sys.exit in your script to return proper error codes idiom
  • Greatly expanded discussion in Avoid comparing directly to True, False, or None and added mention of comparison to None when checking if optional arguments were set (to match the idiom Avoid using , [], and {} as default parameters to functions.
  • Expanded Use the * operator to represent therest" of a list" idiom expanded with additional cases
  • Fixed page numbering issue causing numbers in table of contents and index not to match the text
  • Fixed various typos and grammatical errors
  • Changed font size and various layout issues (some of which caused text to run off the page
  • Changed preface text
3.2 Version 1.2, February 17, 2013
  • Improved formatting for epub and Kindle versions
  • Fixed various typos and grammatical errors
3.3 Version 1.3, June 16, 2013
  • 3 New Sections: Exceptions, Testing, Documentation
    • These will be expanded in future versions
  • New Idiom: Use a dict as a substitute for a switch...case statement
  • Python 2.7+ New Idiom: Use the function-based version of print
    • Previously, the use of print() as a function in the Python 2.7+ edition code samples was a source of confusion as the import statement enabling it was omitted for brevity
  • Conventions section outlining a number of conventions used in the book. Specifically, those listed were identified by readers as a source of confusion.
  • 11 new idioms and 3 new sections in total
3.4 Version 1.4, November 22, 2013
  • New Idiom: Make use of init.py files to simplify package interfaces
  • New Idiom: Use namedtuples to make tuple-heave code more clear
  • New Idiom: Use properties to future-proof your classes
  • Rewritten Idiom: Avoid , [], and {} as default parameters to functions was rewritten for both correctness and clarity
  • Improved formatting for all versions
  • Fixed various typos and grammatical errors
3.5 Version 1.5, December 13, 2013
  • 20 New Idioms!
    • New idioms have been added across the board in a number of different sections. Many of these are quite basic and thus important idioms to understand.
    • New Idiom: Chain comparisons to make if statements more concise
    • New Idiom: Use if and else as a short ternary operator replacement
    • New Idiom: Learn to treat functions as values
    • New Idiom: Use return to evaluate expressions as well as return values
    • New Idiom: Learn to use keyword arguments properly
    • New Idiom: Make use of appropriate assert methods in unit tests
    • New Idiom: Use a try block to determine if a package is available
    • New Idiom: Use tuples to organize a long list of modules to import
    • New Idiom: Make your Python scripts directly executable
    • New Idiom: Use sys.argv to reference command line parameters
    • New Idiom: Use ord to get the ASCII code of a character and chr to get the character from an ASCII code
    • New Idiom: Make use of negative indices
    • New Idiom: Prefer list comprehensions to the built-in map() and filter() functions
    • New Idiom:
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Writing Idiomatic Python 3»

Look at similar books to Writing Idiomatic Python 3. 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 «Writing Idiomatic Python 3»

Discussion, reviews of the book Writing Idiomatic Python 3 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.