What Python looks like

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iu2

    What Python looks like

    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

    #2
    Re: What Python looks like

    iu2 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?
    >
    (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
    Python looked like pseudo-code that people would write before actually coding.
    I've always thought that Python was "Pseudo-code that runs".

    -Larry

    Comment

    • Gary Herron

      #3
      Re: What Python looks like

      iu2 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?
      >
      (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

      Comment

      • Mensanator

        #4
        Re: What Python looks like

        On Aug 4, 2:06 pm, iu2 <isra...@elbit. co.ilwrote:
        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

        Comment

        • Ben Finney

          #5
          Re: What Python looks like

          iu2 <israelu@elbit. co.ilwrites:
          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

          Comment

          • Mel

            #6
            Re: What Python looks like

            Ben Finney wrote:
            iu2 <israelu@elbit. co.ilwrites:
            >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.

            Comment

            • Santiago Romero

              #7
              Re: What Python looks like

              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.

              Comment

              • Gabriel Genellina

                #8
                Re: What Python looks like

                En Mon, 04 Aug 2008 19:20:18 -0300, Ben Finney
                <bignose+hate s-spam@benfinney. id.auescribi� :
                iu2 <israelu@elbit. co.ilwrites:
                >
                >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

                Comment

                • brad

                  #9
                  Re: What Python looks like

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

                  Comment

                  • rynt

                    #10
                    Re: What Python looks like

                    On Aug 4, 12:06 pm, iu2 <isra...@elbit. co.ilwrote:
                    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

                    Comment

                    • Brett Ritter

                      #11
                      Re: What Python looks like

                      On Aug 4, 3:43 pm, Gary Herron <gher...@island training.comwro te:
                      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.

                      Comment

                      • Ben Finney

                        #12
                        Re: What Python looks like

                        brad <byte8bits@gmai l.comwrites:
                        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

                        Comment

                        • Paddy

                          #13
                          Re: What Python looks like

                          On Aug 4, 8:06 pm, iu2 <isra...@elbit. co.ilwrote:
                          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.

                          Comment

                          • William Pursell

                            #14
                            Re: What Python looks like

                            On 5 Aug, 16:08, Brett Ritter <swift...@swift one.orgwrote:
                            On Aug 4, 3:43 pm, Gary Herron <gher...@island training.comwro te:
                            >
                            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.

                            Comment

                            Working...