15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1.7. Comparing <strong>Python</strong><br />

<strong>Python</strong> has been compared with many languages. One reason is that it provides many features found in<br />

other languages. Another reason is that <strong>Python</strong> itself is derived from many other languages, including<br />

ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell and other scripting languages, to name a<br />

few. <strong>Python</strong> is a virtual "greatest hits": van Rossum combined the features he admired most in the other<br />

languages he had studied and brought them together for our programming sanity.<br />

However, more often than not, since <strong>Python</strong> is an interpreted language, you will find that most of the<br />

comparisons are with Perl, Java, Tcl, and JavaScript. Perl is another scripting language that goes well<br />

beyond the realm of the standard shell scripts. Like <strong>Python</strong>, Perl gives you the power of a full<br />

programming language as well as system call access.<br />

Perl's greatest strength is in its string pattern matching ability, providing an extremely powerful regular<br />

expression matching engine. This has pushed Perl to become the de facto language for string text<br />

stream filtering, recognition, and extraction, and it is still the most popular language for developing<br />

Internet applications through Web servers' Common Gateway Interface (CGI). <strong>Python</strong>'s regular<br />

expression engine is based significantly on Perl's.<br />

However, Perl's obscure and overly symbolic syntax is much more difficult to decipher, resulting in a<br />

steep learning curve that inhibits the beginner, frustrating those for whom grasping concepts is impeded<br />

by semantics. This, coupled with Perl's "feature" of providing many ways of accomplishing the same<br />

task, introduces inconsistency and factionization of developers. Finally, all too often the reference book<br />

is required reading to decipher a Perl script that was written just a couple of months back.<br />

<strong>Python</strong> is often compared to Java because of their similar OO nature and syntax. Java's syntax, although<br />

much simpler than C++'s, can still be fairly cumbersome, especially if you want to perform just a small<br />

task. <strong>Python</strong>'s simplicity offers a much more rapid development environment than using just pure Java.<br />

One major evolution in <strong>Python</strong>'s relationship with Java is the development of Jython, a <strong>Python</strong><br />

interpreter written completely in Java. It is now possible to run <strong>Python</strong> programs with only the presence<br />

of a Java VM (virtual machine). We will mention more of Jython's advantages briefly in the following<br />

section, but for now we can tell you that in the Jython scripting environment, you can manipulate Java<br />

objects, Java can interact with <strong>Python</strong> objects, and you have access to your normal Java class libraries<br />

as if Java has always been part of the <strong>Python</strong> environment.<br />

<strong>Python</strong> is now often compared to Ruby as well, due to the popularity of the Rails project. As we<br />

mentioned above, <strong>Python</strong> is a wider mix of multiple programming paradigms. It is not purely OO like<br />

Ruby and does not have Smalltalk-like blocks, perhaps Ruby's most distinguishable feature. <strong>Python</strong> does<br />

have a byte-code interpreter, where Ruby does not. <strong>Python</strong> is perhaps more readable, as Ruby can<br />

really be thought of as more of an OO Perl. With regard to Rails, <strong>Python</strong> has several own Web<br />

application frameworks, such as Django and Turbogears, to name two.<br />

Tcl is another scripting language that shares similarities shares <strong>Python</strong>. Tcl is one of the first truly easyto-use<br />

scripting languages to provide the programmer extensibility as well as system call access. Tcl is<br />

still popular today and perhaps somewhat more restrictive (due to its limited types) than <strong>Python</strong>, but it<br />

shares <strong>Python</strong>'s ability to extend past its original design. More importantly, Tcl is often used with its<br />

graphical toolkit partner, Tk, in developing graphical user interface (GUI) applications. Due to its<br />

popularity, Tk has been ported to Perl (Perl/Tk) and <strong>Python</strong> (Tkinter). Also, it can be argued that<br />

<strong>Python</strong>'s classes, modules, and packages make writing large programs in <strong>Python</strong> more pleasant than<br />

writing them in Tcl.<br />

<strong>Python</strong> has some light functional programming (FP) constructs, which likens it to languages such as Lisp<br />

or Scheme. Although <strong>Python</strong> cannot be considered a traditional functional language, it continues to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!