Book Review: Core Python Applications Programming, 3rd Ed.
thatpythonguy writes "Core Python Application Programming is the latest addition to a growing corpus of literature serving a growing number of Python programmers and engineers. This Prentice Hall book of 800+ pages covers some traditional areas and touches upon some new ones. I typically do not spend much time speaking about the author of the books that I review; however, this occasion warrants an exception. And it is not because Wesley Chun used Python over a decade ago to build the address book and spell-checker for Yahoo! Mail nor is it because he holds a minor degree in music from UC Berkeley in classical piano. Rather, it is because he is both an engineer and an instructor. In other words, he was not pulled from his geek duties and asked to become a pseudo-writer; he already does that for his consulting practice, authoring (or co-authoring) several books and articles on Python (including "Python Web Development with Django") as well as starring in his own training video (entitled "Python Fundamentals"). The result of that experience is a writing style that is technically sound, yet accessible." Keep reading for the rest of Ahmed's review.
Core Python Applications Programming
author
Wesley J. Chun
pages
888
publisher
Prentice Hall
rating
8/10
reviewer
Ahmed Al-Saadi
ISBN
978-0132678209
summary
Python application programming for intermediate python engineers
The book followed the normal evolutionary path of other books in its class. It started out as the second part of "Core Python Programming" and ended up being split into its own volume in its third edition. The first part became "Core Python Language Fundamentals" which covers the core language. This volume covers the natural successor topics of "now what?" that the first raises: the use of Python in various applications. It is for this reason that the book recommends that the reader be an intermediate Python programmer. I think "intermediate" here refers to anyone who has read an introductory book or followed a tutorial on the core language.
The book covers the two main lines of python development: 2.x and 3.x. Despite the slow adoption of the 3.x line due to its backward incompatibility, there are already popular third-party libraries that have been ported to that line and that occurrence will only increase moving forward. Chun does a very good job balancing the two by providing concurrent examples (i.e., code snippets) in both flavours. He also has numerous references and side notes indicating that certain features/libraries are only available for certain versions of the language.
There are three parts to the book: General Application Topics, Web Development, Supplemental/Experimental. The first includes the usual dosage of general chapters including regular expressions (regex), network programming (including an intro to the Twisted framework), Internet client programming, threading and multi-processing, GUI, and databases (including a taste of NoSQL). It is peculiar that it also includes chapters on Microsoft Office programming and writing Python extensions which are not general in my opinion. It is probably because these two chapters do not fit anywhere else! The second part is probably the core of Chun's own experience as he is a self-described "web guy". He certainly goes into details in that domain covering web clients/servers (yes, he writes a small web server!), general web programming (i.e., CGI and WSGI), the Django framework, cloud computing (mostly Google App Engine; GAE), and web services. Finally, the last part has two chapters on text processing and miscellaneous topics (basically, Jython and Google+). I find the naming of the text processing chapter rather poor given that it is about processing comma-separated values (CSV), JavaScript Object Notation (JSON), and Extensible Markup Language (XML). Arguably, "text processing" is more descriptive of regex, transcoding, and Unicode! Two appendices at the end of the book provide some background and a guide to Python 3.x migration.
Chun spends some time delving into a problem domain in addition to providing the Python solution. For example, he describes the regular expression syntax in detail and spends time explaining the client-server architecture using real-life analogies to drive his points home. His code examples are well-structured, object-oriented solutions that range from the demonstrative to the practical. For example, in the Django chapter, he builds a practical Twitter application that uses third-party libraries and some advanced features. However, do not expect a cookbook-style coverage nor production-ready code from a book of this nature. Do expect many exercises with partial solutions at the end of the book.
I find Chun's approach to be pedagogically sound. His ideas flow logically from one to the next, incrementally building a story-like chain of problems and Python solutions. He highlights architectural patterns that are shared by disparate problem domains (e.g., the event-driven nature of SocketServer and Tkinter), leading to a better understanding of both. However, he does leave out many topics from his coverage for applications in compression, cryptography, and date handling (among others). Maybe he considers these to be ancillary or simple enough to be looked up in Python's own standard library documentation. Also, as a Developer Advocate for Google, it is not surprising to see him cover the GAE in depth. Specifically, I think for anyone who is interested in running Django on the GAE, he can be an excellent (and accessible, by his own admission) resource. Google him (no pun intended!) to see his presentation on "porting" Django applications to the GAE.
Finally, the book is aesthetically type-set and is well-structured. I think that it has a wealth of well-written information that cover key areas of Python application development that will be useful to a broad spectrum of readers.
Ahmed Al-Saadi is a software consultant based in Montreal, Canada. He mainly speaks Python, Erlang, and Objective-C these days.
You can purchase Core Python Applications Programming, 3rd ed from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
The book covers the two main lines of python development: 2.x and 3.x. Despite the slow adoption of the 3.x line due to its backward incompatibility, there are already popular third-party libraries that have been ported to that line and that occurrence will only increase moving forward. Chun does a very good job balancing the two by providing concurrent examples (i.e., code snippets) in both flavours. He also has numerous references and side notes indicating that certain features/libraries are only available for certain versions of the language.
There are three parts to the book: General Application Topics, Web Development, Supplemental/Experimental. The first includes the usual dosage of general chapters including regular expressions (regex), network programming (including an intro to the Twisted framework), Internet client programming, threading and multi-processing, GUI, and databases (including a taste of NoSQL). It is peculiar that it also includes chapters on Microsoft Office programming and writing Python extensions which are not general in my opinion. It is probably because these two chapters do not fit anywhere else! The second part is probably the core of Chun's own experience as he is a self-described "web guy". He certainly goes into details in that domain covering web clients/servers (yes, he writes a small web server!), general web programming (i.e., CGI and WSGI), the Django framework, cloud computing (mostly Google App Engine; GAE), and web services. Finally, the last part has two chapters on text processing and miscellaneous topics (basically, Jython and Google+). I find the naming of the text processing chapter rather poor given that it is about processing comma-separated values (CSV), JavaScript Object Notation (JSON), and Extensible Markup Language (XML). Arguably, "text processing" is more descriptive of regex, transcoding, and Unicode! Two appendices at the end of the book provide some background and a guide to Python 3.x migration.
Chun spends some time delving into a problem domain in addition to providing the Python solution. For example, he describes the regular expression syntax in detail and spends time explaining the client-server architecture using real-life analogies to drive his points home. His code examples are well-structured, object-oriented solutions that range from the demonstrative to the practical. For example, in the Django chapter, he builds a practical Twitter application that uses third-party libraries and some advanced features. However, do not expect a cookbook-style coverage nor production-ready code from a book of this nature. Do expect many exercises with partial solutions at the end of the book.
I find Chun's approach to be pedagogically sound. His ideas flow logically from one to the next, incrementally building a story-like chain of problems and Python solutions. He highlights architectural patterns that are shared by disparate problem domains (e.g., the event-driven nature of SocketServer and Tkinter), leading to a better understanding of both. However, he does leave out many topics from his coverage for applications in compression, cryptography, and date handling (among others). Maybe he considers these to be ancillary or simple enough to be looked up in Python's own standard library documentation. Also, as a Developer Advocate for Google, it is not surprising to see him cover the GAE in depth. Specifically, I think for anyone who is interested in running Django on the GAE, he can be an excellent (and accessible, by his own admission) resource. Google him (no pun intended!) to see his presentation on "porting" Django applications to the GAE.
Finally, the book is aesthetically type-set and is well-structured. I think that it has a wealth of well-written information that cover key areas of Python application development that will be useful to a broad spectrum of readers.
Ahmed Al-Saadi is a software consultant based in Montreal, Canada. He mainly speaks Python, Erlang, and Objective-C these days.
You can purchase Core Python Applications Programming, 3rd ed from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
I am myself familiar with PHP but not Python. What's so good about Python and why should one choose to use it?
Let's take for example PHP's comprehensive library that is usable without any downloads and external includes. It's one of the things I love about PHP. Python seems to miss that.
Another thing I don't like about Python is the use of TABS and white space as code block separators. Really? Why??
I'm sure Python can be great language but the style and some parts of it really put me away from it. This book might be well-structured, but IMHO Python itself isn't.
A homo sapiens? Can't argue with that...
Wow, is there anything Samuel L. Jackson can't do?
How is it core Python programming when it's 800 pages?
Another case of publishers coming up with one keyword and then using it for every single book they put out.
-Unleashed
-In 24 hours
-In 30 days
-Pragmatic
I'm not a lawyer, but I play one on the Internet. Blog
Why do you need an editor designed for Python? I write Python in gedit and vim reasonably often. Last time I checked both of those programs support both tabs and spaces, with no external support or plugins required...
Shouldn't it be object-oriented?
Especially this part, "...covering web clients/servers (yes, he writes a small web server!), general web programming (i.e., CGI and WSGI), the Django framework, cloud computing (mostly Google App Engine; GAE), and web services."
I'm assuming the chapters are written so that you can "jump-in" without having to follow up the preceding material. I only question this point because the reviewer states: "His ideas flow logically from one to the next, incrementally building a story-like chain of problems and Python solutions."
PS: I don't reply to ACs.
I'll wait for the Cliff's Notes version, thank you.
The only two things that really bother me about python are:
1) after 25 years they still refuse to add a switch/case statement (makes writing FSMs harder)
2) there is no gaurantee that a destructor is ever called, thus you cannot implement a RAII pattern with objects
As for white-space delimiting, don't knock it till you try it. Just use a good editor (eg emacs, or other smart editor). Once you get used to it, it's actually very easy on the eyes sans having extra delimiters (curly braces, semicolons, etc.) and winds up saving typing to boot.
The libraries are pretty great. The documentation could be organized better, but on the hole is fairly complete.
The community is for the most part very responsive in #irc to questions. (Just don't offend them or get obstinate about doing it a non-python way...after all the help they provide is *free*).
".hturT .omoh eguh a er'uoy nohtyP esu uoy fI" - by Anonymous Coward ANOTHER "ne'er-do-well" /. OFF-TOPIC TROLL on Monday July 30, @04:22PM (#40821797)
"???"
Uhm... Could we get a translation of that illogical ad hominem attack failed attempt @ "troll-speak/trolllanguage" of yours, please?
---
* You're just TROLL "noise", nothing more... See subject-line above, & "Rinse, Lather, & Repeat"!
APK
P.S.=> ("ReVeRsE-PsYcHoLoGy", for trolls - Courtesy of this python code by "yours truly" in less than 1 second flat):
---
#TrollTalkComReversePsychologyKiller.py (Ver #2 by APK)
def reverse(s):
try:
trollstring = ""
for apksays in s:
trollstring = apksays + trollstring
except:
print("error/abend in reverse function")
return trollstring
s = ""
print reverse(s)
try:
s = "Insert whatever 'trollspeak/trolllanguage' gibberish occurs here..."
s = reverse(s)
print(s)
except Exception as e:
print(e)
---
(Yes, for the "purists" among you, I could do this via a single line print statement in Python, but to myself, that's merely using a native function - NOT truly "coding" so... there you are (Python's NOT a "primary language" for me, just one I dabbled with a year or two ago for a few months...))
... apk
lets me choose my own block delimiter I will consider it, until then it sucks ditch water and is not worthy of even the most banal task.
Hey KID! Yeah you, get the fuck off my lawn!
This is a pretty good review, but I could've done without all the gushing praise for the author and his accomplishments large and small (he studied piano! he has his own consulting business! he wrote a small web server!).
The only two things that really bother me about python are:
1) after 25 years they still refuse to add a switch/case statement (makes writing FSMs harder)
2) there is no gaurantee that a destructor is ever called, thus you cannot implement a RAII pattern with objects
Switch/case has always been a bit of a funky construct. LISP's cond was just a general form of if/then/else'. C's switch was pretty tied to C's eq style equality (and was a fun hotspot for compiler writers.) C++'s switch is just an artifact from C that must ignore C++'s attempts to generalize equality. Fortran's computed goto is best described as "interesting." I'm not sure what Python could provide in this space that would be a significant benefit.
RAII is also a bit funky. The best garbage collector is often "do not do GC, assume the program will terminate before you run out of memory." Tying RA to GC is a pretty significant language design choice that, as you note, affects the patterns a programmer will use. At my current gig, we make design choices like this (auto-terminate and restart processes that exceed a memlimit,) but I'd hate the language we use (and we use Python) to have its own views of resource management based on memory.
Well, why not simply decouple the two operations--they already did so for instantiation: __new__() and __init__(), why not separate the converse with __deinit__() and __del__()?
Then when you call "del foo" in code, you are invoking __deinit__() destruction, freeing resources, etc, but leaving the GC free to call __del__() when or if it sees fit.
That's the real pattern RAII wants anyways--tying resources to the semantically-meaningful life of the object, not the life of the object in memory (since that is non-deterministic/varies by GC algorithm).
As for switch/case, either add that, or goto. There *are* use cases where it makes coding cleaner/easier to read--which is one of the underlying points to python, isn't it?
And a 3rd item: if you're not gonna have goto, then at least allow break to accept a parameter to know how many levels to break out of... having to manage and test extra flags just to exit out of multiple-nested blocks at once is much less readable.
Well, why not simply decouple the two operations--they already did so for instantiation: __new__() and __init__(), why not separate the converse with __deinit__() and __del__()?
Then when you call "del foo" in code, you are invoking __deinit__() destruction, freeing resources, etc, but leaving the GC free to call __del__() when or if it sees fit.
That's the real pattern RAII wants anyways--tying resources to the semantically-meaningful life of the object, not the life of the object in memory (since that is non-deterministic/varies by GC algorithm).
You might be right. I've never liked Python''s new/init stuff.
As for switch/case, either add that, or goto. There *are* use cases where it makes coding cleaner/easier to read--which is one of the underlying points to python, isn't it?
A use case, or even infinite use cases, does not mean it is a good idea. Even a use case in which some snippet is objectively easy to read. This is basic language design. If you add a new entity to your language, you and your users have to understand what it is.
Take, for example, the target (label) of your proposed goto statement. Is it a marker in a block of text? If so, how does it interact with try/catch/finally? Is it a first class object? Is so, can I pass it do another function and do a LISP non-local goto? Can I return it from a function?
Whatever rules you pick, have you really made things easier to read or more complex?
IIRC, Erik Naggum had some interesting posts on this topic.
And a 3rd item: if you're not gonna have goto, then at least allow break to accept a parameter to know how many levels to break out of... having to manage and test extra flags just to exit out of multiple-nested blocks at once is much less readable.
Again, you can express some things more concisely, but at what cost to others reading your code? "break 9 levels" helps no one. "break 2 levels" might be better expressed as a subfunction within a simple return.
People can write amazing bad code using simple 1-level constructs like 'if' and 'break.' It should not be surprising that giving them power tools like 'multi-if' and 'multi-level-break' just lets them write worse code and get even more confused by the good code they happen to see.
If you're feeling *particularly* devious, you can use a little-known Python feature called "for-else" (also "while-else") which allows you to tag "else" clauses onto for loops. Such a clause executes only if the loop runs to completion 'naturally' (i.e. if no break or exception happens within the loop block).
As a relatively obscure language feature, using it might make your code harder to read. It can help make a multilevel break (chained "else: continue; break" snippets at the end of loops), and reduces the number of flag tests and sentinels you need to do (e.g. a linear search, wherein the "else" case simply contains the if-not-found logic).
There are other alternatives to multi-level break: exceptions can break out of any number of loops until they reach an appropriate handler block, and function returns can always break out of any loop up to the top of the function.
As for switch/case: In C, they were basically a thin wrapper around jump tables for most switches (e.g. enums, small integers, duff's device, etc.). Python's preferred alternatives are key-value dictionaries (hashtables) or if/elif cascades. The former is very easy to setup and manipulate in Python (e.g. {1: 'spam', 2: 'eggs', 3: 'ham'}), unlike in C or C++. The latter is far more flexible than switch/case (e.g. being able to test ranges of values with "A <= x <= B" queries, test for multiple values with "x in (A, B, C)", or do arbitrary tests like "x.isspace()"), while avoiding the complexity of an entirely new language construct.
Finally, goto exists in Python as a third-party module. Go ahead, try it: it really works!
1) A switch in python is implemented using a dictionary
2) RAII is done through context managers ( http://docs.python.org/reference/datamodel.html#context-managers )