05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Python possesses a number of features that differentiate itself from Perl. First, Python was<br />

designed as an object-oriented scripting language (Perl gained reasonable object-oriented capabilities<br />

in version 5; however, on a whole Perl is still used very much as a functional<br />

programming language). Second, unlike Perl, the style of writing scripts is very strict. Proper<br />

indentation of code, whitespace, and line breaks have specific, essential meaning to Python. This<br />

often makes existing Python code much easier to understand than most Perl code, but dictating<br />

a strict style has also caused a few issues through Pythons evolution (and of course has caused a<br />

few “free thinking” individuals to shun the language).<br />

Python has been around on the <strong>Mac</strong> for a while (beginning with <strong>Mac</strong>Python even before<br />

<strong>OS</strong> X). Today, like Perl, it’s a standard part of Darwin. Unlike Perl, Python is developed as a<br />

framework, rather than a traditional Darwin application. This makes Python available for<br />

Cocoa programming as well as Darwin development right out of the box.<br />

Learning Python is fairly easy with lots of books and online tutorials available. One of the<br />

best places to start is the Python tutorial at http://docs.python.org/tut/. One nice part about<br />

learning Python is that it comes with its own interactive interpreter, which will start when you<br />

type python at the command line without arguments. Not only is this a great tool for learning the<br />

language, but it can be very handy for unleashing the power of Python for common tasks. We use<br />

the Python interpreter all the time as a calculator (we find it much faster and more flexible to<br />

use than the GUI calculator for most things). A session with the Python interpreter could look<br />

like this:<br />

<strong>Leopard</strong>:~ scott$ Python<br />

Python 2.5.1 (r251:54863, Jun 4 2007, 18:21:31)<br />

[GCC 4.0.1 (Apple Inc. build 5450)] on darwin<br />

Type "help", "copyright", "credits" or "license" for more information.<br />

>>> x=2<br />

>>> for y in range(11):<br />

... y*x<br />

...<br />

0<br />

2<br />

4<br />

6<br />

8<br />

10<br />

12<br />

14<br />

16<br />

18<br />

20<br />

>>><br />

As you may devise from this, you can accomplish a lot of stuff with very little code. Once a<br />

programmer learns the nuances of Python, they generally find themselves creating code at a significantly<br />

faster pace than with most other languages.<br />

Ruby<br />

CHAPTER 19 EXTENDING THE POWER OF DARWIN 341<br />

Ruby is the new kid in the family, but it’s making quite a showing, largely because of the buzz<br />

surrounding Ruby on Rails (RoR), a very nice web application framework written in Ruby.<br />

Ruby shares many similarities with Python in general and on <strong>Leopard</strong>. Both are object oriented<br />

(in Ruby everything becomes an object), both are relatively easy to pick up, and both include an<br />

interactive interpreter for playing around with code (Ruby’s interactive interpreter is not built<br />

into the language in the same way that Python’s is; to get to the Ruby interactive interpreter, you

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

Saved successfully!

Ooh no, something went wrong!