Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What Python looks like

1 view
Skip to first unread message

iu2

unread,
Aug 4, 2008, 3:06:58 PM8/4/08
to
Hi,

This is a little bit strange post, but I'm curious...

I learned Python from its tutorial step by step, and practicing
writing small scripts.
I haven't seen a Python program before knowing Python.

I'm curious, what did Python code look like to those of you who have
seen a bunch of Python code for the first time before knowing Python?

(I can tell, for example, that seeing perl for the first time looked
like C with many $$$, I could see "if" and "for" and "while" but they
were meaningless. Or Lisp for the first time looked like many words,
no operators, how could that make a program???)

Thanks

Larry Bates

unread,
Aug 4, 2008, 3:38:01 PM8/4/08
to

Python looked like pseudo-code that people would write before actually coding.
I've always thought that Python was "Pseudo-code that runs".

-Larry

Gary Herron

unread,
Aug 4, 2008, 3:43:34 PM8/4/08
to pytho...@python.org

My impression was (and still is):

A page of Python code looks *clean*, with not a lot of
punctuation/special symbols and (in particular) no useless lines
containing {/} or begin/end or do/done (or whatever).

Gary Herron


> Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Mensanator

unread,
Aug 4, 2008, 4:18:11 PM8/4/08
to
On Aug 4, 2:06 pm, iu2 <isra...@elbit.co.il> wrote:
> Hi,
>
> This is a little bit strange post, but I'm curious...
>
> I learned Python from its tutorial step by step, and practicing
> writing small scripts.
> I haven't seen a Python program before knowing Python.
>
> I'm curious, what did Python code look like to those of you who have
> seen a bunch of Python code for the first time before knowing Python?

To me, when I started transitioning from perl to Python, Python

Python from 2002
--------------------------------------------------------------
import sys
import string
# Python Collatz tester
j = string.atol(sys.argv[1])
i = 2**(6*j-1)-1
print i,"\n"
r1 = 0
r2 = 0
count = 0
while i>1:
z = divmod(i,2)
if z[1]==0:
i = z[0]
r1 = r1 + 1
if z[1]>0:
i = i*3 + 1
r2 = r2 + 1
print "[1]",r1
print "[2]",r2,"\n"
--------------------------------------------------------------

looked just like perl, but without the braces (which seemed a
lot more important than the $s).

Perl from 2002
--------------------------------------------------------------
use Math::BigInt ':constant';
$j = @ARGV[0];
$i = 2**(6*$j-1)-1;
print "$i\n";
$r1 = 0;
$r2 = 0;
while ($i>1) {
if ($i =~ /.*?[0,2,4,6,8]$/) {
$i = $i/2;
$r1++;
}
else {
$i = $i*3 + 1;
$r2++;
}
}
print "[1] ",$r1;
print " [2] ",$r2,"\n";
--------------------------------------------------------------


>
> (I can tell, for example, that seeing perl for the first time looked
> like C with many $$$,

I wouldn't say that, the $s are minor, big thing is the declarations
and pointers.

C from 2005 (not complete program)
--------------------------------------------------------------
long collatz (mpz_ptr r)
{
mpz_t result, twee, twoo, cee;
mpz_init (result);
mpz_init_set_ui (cee, 1);
mpz_init_set_ui (twee, 3);
mpz_init_set_ui (twoo, 2);
long rule1 = 0;
long rule2 = 0;
long f;
while (mpz_cmp (r, cee) > 0)
{
f = mpz_scan1 (r, 0);
if (f>0) /* even */
{
mpz_tdiv_q_2exp (result, r, f);
rule1 = rule1 + f;
}
else /* odd */
{
mpz_set (result, cee);
mpz_addmul (result, r, twee);
rule2++;
}
mpz_swap (r, result);
}
printf ("\nRule1: %8d Rule2: %8d\n\n", rule1, rule2);
return rule1 + rule2;
}
--------------------------------------------------------------


> I could see "if" and "for" and "while" but they
> were meaningless.

Maybe you looked at a crappy example.

> Or Lisp for the first time looked like many words,
> no operators,

Aren't some of the words operators? I never used used Lisp,
but I did dabble in Scheme and have no trouble identifying the
operators (although not the overall program).

Scheme from 2004
--------------------------------------------------------------
(define n 1)
(define collatz
(lambda (n)
(if (even? n)
(/ n 2)
(+ 1 (* n 3))
)))
(define sequence
(lambda (n)
(do ((count 0 (+ count 1)))
((= n 1) (display "stopping: ") (display count))
(set! n (collatz n)) (display n) (display " ")
)))
--------------------------------------------------------------

> how could that make a program???)

You have to think differently with functional languages.
The functional snobs say you'll never "get" it once your
mind has been poisoned by imperative languages.

>
> Thanks

Ben Finney

unread,
Aug 4, 2008, 6:20:18 PM8/4/08
to
iu2 <isr...@elbit.co.il> writes:

> I'm curious, what did Python code look like to those of you who have
> seen a bunch of Python code for the first time before knowing Python?

To me it looked like the pseudo-code used for describing algorithms,
allowing clear understanding and redesign of the algorithm before
adding all the cruft "necessary" to make a real program from it.

I was very impressed, therefore, that program code could be so clear
and readable, and yet require so little computer-friendly cruft.

> (I can tell, for example, that seeing perl for the first time looked
> like C with many $$$, I could see "if" and "for" and "while" but they
> were meaningless.

Being already familiar with Bourne-style shell programs, Perl just
looked to me like an even-more-baroque version of Bourne shell syntax.
Not surprising, since that was one of its main inspirations.

> Or Lisp for the first time looked like many words, no operators, how
> could that make a program???)

I had no referent with which to compare Lisp when I first saw it. I
did wonder "if the program is so nicely indented anyway, why are all
these parentheses necessary?" That was many years before I encountered
Python :-)

--
\ “I see little commercial potential for the Internet for at |
`\ least ten years.” —Bill Gates, 1994 |
_o__) |
Ben Finney

Mel

unread,
Aug 4, 2008, 7:39:40 PM8/4/08
to
Ben Finney wrote:

> iu2 <isr...@elbit.co.il> writes:
>> Or Lisp for the first time looked like many words, no operators, how
>> could that make a program???)
>
> I had no referent with which to compare Lisp when I first saw it. I
> did wonder "if the program is so nicely indented anyway, why are all
> these parentheses necessary?" That was many years before I encountered
> Python :-)

Coming from assembly language "no operators" was not something that
registered. A big limitation of assembly language is that the instruction
operands have to be identifiable at assembly time.. linkedit time at the
latest. Lisp has no such restriction. Hence all the parens.

Mel.

Santiago Romero

unread,
Aug 5, 2008, 3:35:09 AM8/5/08
to

> I'm curious, what did Python code look like to those of you who have
> seen a bunch of Python code for the first time before k

Clean and readable.

Gabriel Genellina

unread,
Aug 5, 2008, 5:40:51 AM8/5/08
to pytho...@python.org
En Mon, 04 Aug 2008 19:20:18 -0300, Ben Finney
<bignose+h...@benfinney.id.au> escribi�:

> iu2 <isr...@elbit.co.il> writes:
>
>> I'm curious, what did Python code look like to those of you who have
>> seen a bunch of Python code for the first time before knowing Python?
>
> To me it looked like the pseudo-code used for describing algorithms,
> allowing clear understanding and redesign of the algorithm before
> adding all the cruft "necessary" to make a real program from it.
>
> I was very impressed, therefore, that program code could be so clear
> and readable, and yet require so little computer-friendly cruft.

I got the same impression when I saw Python code for the first time.

--
Gabriel Genellina

brad

unread,
Aug 5, 2008, 9:08:29 AM8/5/08
to
Gary Herron wrote:

> My impression was (and still is):
>
> A page of Python code looks *clean*, with not a lot of
> punctuation/special symbols and (in particular) no useless lines
> containing {/} or begin/end or do/done (or whatever).

what about all those 'self' thingys? :)

rynt

unread,
Aug 5, 2008, 9:46:55 AM8/5/08
to

I stumbled across Python in 2000 when I ran accross GNUe. I decided
to look into Python at that time, and was impressed that the code was
readable, and, understandable - even before I looked at the language
and library refs. I had been working in a subset of Basic and Delphi
at the time. I really don't like Pascal or C/C++ with all of the
BEGIN/END and braces. I don't work in Python full time, but do use it
for scripting, and "hobby" programming. One heck of a cool language!

RCB

Tyler Breisacher

unread,
Aug 5, 2008, 10:50:23 AM8/5/08
to pytho...@python.org
To paraphrase this video (http://www.youtube.com/watch?v=zJOS0sV2a24)
(which is the Randall Munroe, author of the famous xkcd
(http://www.xkcd.com/), giving a talk at Google), "you just type the
pseudo-code and it runs! And as someone said, if Python is executable
pseudo-code, then Perl is executable line noise." That quote (and the
"import antigravity" comic) were my first exposure to Python and then
when I actually began to use it, I found it to be quite true.

Brett Ritter

unread,
Aug 5, 2008, 11:08:09 AM8/5/08
to
On Aug 4, 3:43 pm, Gary Herron <gher...@islandtraining.com> wrote:
> A page of Python code looks *clean*,  with not a lot of
> punctuation/special symbols and (in particular) no useless lines

I am actually going to buck the trend.

My first impression of Python was that it was visually hard to parse.

When seeing sample code from languages I don't know (.NET, Smalltalk,
etc) I can decipher the intent fairly easily (on simple code).
Python, on the other hand, used shorthand notation for everything.
Each word wasn't bad, but as a whole it tended to wash out informative
clues. The lack of "special symbols" likewise removed visual parsing
clues.

Put another way, imagine math went from:
2 + 2 = 4
to:
two plus two equals four
and then someone decided to abbreviate:
two pl two eq four

When I ran into list comprehensions (Aah! Now we have punctuation,
but it's not providing visual parsing clues, it's more like Lisp
parens!) or lambda definitions or "self" being added a lot, it grew
more dense.

This is NOT a rip on Python. Please put the flamethrowers away. I
appreciate that Python operates with a fairly dense use of information
and operations. (Believe me, having done enough Java, I can
appreciate not having excessive syntax). My point is that not
everyone new to Python is going to have a "clean and clear" first
impression, particularly based on their previous language experience.

Ben Finney

unread,
Aug 5, 2008, 9:32:01 PM8/5/08
to
brad <byte...@gmail.com> writes:

> Gary Herron wrote:
>
> > A page of Python code looks *clean*, with not a lot of
> > punctuation/special symbols and (in particular) no useless lines
> > containing {/} or begin/end or do/done (or whatever).
>
> what about all those 'self' thingys? :)

Nice, clear, explicit, readable. I loved explicit 'self' the first
time I saw it.

--
\ “I've always wanted to be somebody, but I see now that I should |
`\ have been more specific.” —Jane Wagner, via Lily Tomlin |
_o__) |
Ben Finney

Paddy

unread,
Aug 6, 2008, 1:27:44 AM8/6/08
to

Strange you should mention this. I am currently new to Rosetta Code
http://www.rosettacode.org/ where some pages I have been looking at
such as the page for Zig Zag, and a page I created called Spiral
have had very terse solutions, and long explanations in the talk
pages all written in the J language. I can read the lines between
the code samples enough to intrigue , (OK frustrate), me - but the
code is impenetrable.
I am not sure if J attracts good programmers or if learning J
forces you to think about solutions in different or useful ways.
I've learnt A LISP-like language, dabbled with forth & prolog &
constraints - maybe its time to learn J and find out if this
array programming malarky will bring new insight to my problem
solving - but it will never be readable :-)

- Paddy.

William Pursell

unread,
Aug 6, 2008, 1:34:59 AM8/6/08
to
On 5 Aug, 16:08, Brett Ritter <swift...@swiftone.org> wrote:
> On Aug 4, 3:43 pm, Gary Herron <gher...@islandtraining.com> wrote:
>
> > A page of Python code looks *clean*,  with not a lot of
> > punctuation/special symbols and (in particular) no useless lines

> My first impression of Python was that it was visually hard to parse.
<snip>>


> Put another way, imagine math went from:
> 2 + 2 = 4
> to:
> two plus two equals four
> and then someone decided to abbreviate:
> two pl two eq four

That looks more like tcl than python to me.

My first reaction to python was a strong dislike
of indentation as a block delimeter and
the convention of using '__*__' names. I got over
my issue with indentation fairly quickly, but still
don't care for the excessive underscores. However,
overall I thought it was extremely clean and
easy to write. By the time I saw Python, I had
already essentially given up on Perl, but it
only took 20 minutes going through the tutorial to
completely nail down the lid on the coffin of
my Perl self.

To summarize the first impression: clean, simple,
powerful, and a lot of potential.

0 new messages