What Python looks like

I

iu2

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
 
G

Gary Herron

iu2 said:
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???)

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
 
M

Mensanator

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.
 
M

Mel

Ben said:
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.
 
S

Santiago Romero

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.
 
G

Gabriel Genellina

En Mon, 04 Aug 2008 19:20:18 -0300, Ben Finney
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.
 
B

brad

Gary said:
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? :)
 
R

rynt

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

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
 
B

Brett Ritter

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.
 
P

Paddy

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top