Why did Quora choose Python for its development?

John Bokma john at castleamber.com
Tue May 24 21:48:30 EDT 2011


Chris Angelico <rosuav at gmail.com> writes:

> On Wed, May 25, 2011 at 9:16 AM, John Bokma <john at castleamber.com> wrote:
>> Chris Angelico <rosuav at gmail.com> writes:
>>
>>> Yes, I believe that was Perl. And an amusing quote. But most of the
>>> point of it comes from the fact that Perl uses punctuation for most of
>>> its keywords,
>>
>> For example?
>>
>>> whereas (say) Python uses English words; it's a lot more
>>> fun to crunch something down when you can use $|
>>
>> That's not a keyword but a special (global) variable. On top of that,
>> you don't have to use it [1] and most people most likely encounter this in
>> (badly) written CGI scripts originating in the last century.
>
> Okay, poor example. But there's a lot of Perl that uses concise
> notation for things that in Python are keyworded; for instance,
> regular expressions.

Perl does have indeed operators for matching and substitution. It's:

( my $foo = $bar ) =~ s/ ... / ... /;

versus

foo = re.sub(r" ... ", " ... ", bar )

and:

my $foo = qr/

...

/xi;

versus:

foo = re.compile(r"""

...

""", re.IGNORECASE|re.VERBOSE)

It's just a matter of taste IMO. The regular expression noise stays the
same ;-).

>>> and friends than when you have to put "x and y", complete with spaces,
>>> for a simple boolean.
>>
>> Perl has also the and logical operator. This is legal Perl:
>>
>> if ( $x and $y ) {
>>  print "yes\n";
>> }
>
> That's at a completely different precedence level, isn't it? 

Yes, /but/ in this case it doesn't matter. Of course there are cases
that it /does/ matter:

> For instance:
>
> $a = $b && $c ? $e : $f;
> # versus
> $a = $b and $c ? $e : $f;
>
> The first one is an assignment to $a, conditional on two variables.
> The second is an unconditional assignment to $a, and then based on
> that, evaluates either $e or $f and does nothing with it.
>
> Python:
> a = e if b and c else f

Yes, "recently" added to the language, before that you had to and or
your way out of it (or use lambdas).

> It's pretty similar, actually (although, coming from a C background, I
> do prefer to have the condition first); but I could crunch the first
> one down a lot, while the last one is almost as tight as it can be.
>
> $a=$b&&$c?$e:$f;
> a=e if b and c else f
>
> It's that crunched appearance that makes Perl look like line noise,

So you just agree with what I earlier wrote: one /can/ write harder to
read in Perl, like you can jump off a cliff. And I have seen a lot of
extremely badly written Perl code, but never seen a disaster like the
one above ;-).

> and the open keyworded appearance that makes Python look like
> pseudocode. But that's not necessarily a good thing; a courteous
> programmer can space out Perl to keep it readable, and he then has the
> option of crunching pieces that are 'logically one' and spacing out
> the parts that aren't:
>
> $a= $b&&$c ? $e : $f;
>
> Silly, contrived example, but in production code I've often had
> situations where it makes sense to space out one part of an expression
> and crunch another. And when everything's an English word, that's not
> an available option.

I would write it like

$a = ( $b and $c ) ? $e : $f;

> That said, though, I do find Python a lot easier for reading other
> people's code in. A LOT easier.

Like I wrote earlier: I find Perl easier to read. And honestly, I don't
know why. Partially it might have a lot to do with having been exposed
to it much more. But many years back, when I could pick between several
languages, Perl was the one that stuck with me. And that was before
everybody and his mom was hacking CGI scripts in Perl (badly).

And while I do want to switch to Python (or use it more often), for one
reason or another it's hard. Maybe it's for similar reasons that one
loves Spanish but hates German as a second language (or vice versa)?

Both Perl and Python are evolving. Perl has a lot of bagage from the
beginning, and more so since a lot got slapped on later on. Things are
changing, but you just can't make major changes since people, like me I
guess, are used to how things are right now.

I now and then have peeks at Perl 6 and each time my first reaction is:
this is Perl only in name; it's very, very different. On the other hand
it still shares what I consider warts with Perl 5.

-- 
John Bokma                                                               j3b

Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html



More information about the Python-list mailing list