code blocks in Python

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

    #16
    Re: code blocks in Python


    "Hung Jung Lu" <hungjunglu@yah oo.com> wrote in message
    news:8ef9bea6.0 311241527.61a27 b6c@posting.goo gle.com...[color=blue]
    > Skip Montanaro <skip@pobox.com > wrote in message[/color]
    news:<mailman.1 035.1069703636. 702.python-list@python.org >...[color=blue][color=green]
    > >[/color]
    > I come back again to repeat it one more time: the compile() function
    > already exists and works in Python. Before you do your posting, please
    > think about the compile() function first. (Do I need to say it one
    > more time? I don't mind.)[/color]

    So what?

    Functionality is not added to Python simply because it looks like
    a logical extension of something else that already exists. First,
    you need to show a compelling use case.

    So far, I've seen one thing in your proposal: dynamic binding
    of free variables in a function, rather than static binding. All
    questions of syntax aside, please show me why this matters,
    bearing in mind that I've never programmed in a language
    that has this, and am not going to be convinced by references
    to such languages.

    While I'm not *the* person that has to be convinced (that's Guido),
    I'm probably representative. If you don't manage a compelling
    case for why dynamic binding is a useful option, then you're not going
    to get anywhere with this proposal.

    By the way - if I understand the guts of the proposal, the compile
    function has nothing to do with it, and wouldn't be used to implement
    it in any case.

    John Roth


    Comment

    • Greg Ewing (using news.cis.dfn.de)

      #17
      Re: code blocks in Python

      Hung Jung Lu wrote:[color=blue]
      > Is there something obvious that I am missing here? Why isn't codeblock
      > part of the language?[/color]

      When code blocks are discussed, it's usually in the context of
      user-defined control structures. For that, you need a way of
      writing code blocks in-line where they're needed. You also
      need a way of defining and using new control structures, and
      some way of passing parameters to the code block would be
      highly desirable. New syntax would be needed for all these.

      Just having code blocks on their own without any of those
      other things doesn't seem all that useful to me.

      --
      Greg Ewing, Computer Science Dept,
      University of Canterbury,
      Christchurch, New Zealand


      Comment

      • Skip Montanaro

        #18
        Re: code blocks in Python


        hjl> Skip: being you a Python old timer, I think you are just grumbling
        hjl> for no good reason. :)

        hjl> Before anything else, people are already jumping into
        hjl> implementation details, optimization, syntax, etc. I am barely
        hjl> starting to look at whether there have been previous existing
        hjl> efforts, and if so, why were they discarded, etc.

        I'm not asking about implementation details, optimization, syntax. All
        you've told me is "the compile() function already exists and works in
        Python". I understand that. I am completely missing the connection between
        "I would like to see code blocks added to Python" and "the compile()
        function already exists and works in Python". Just because you have one
        doesn't mean you need the other.

        Are you just looking for syntactic sugar for the compile() function? If so,
        I'm going to have to vote against it. I've been using Python for about 10
        years and can't ever remember using the builtin compile() function in my own
        code. In fact, for the first year or two I programmed in Python I wasn't
        even aware it existed and used to import the compile function from the old
        regex module as "from regex import compile".

        hjl> (d) Aha! So by analogy, there is no need for the compile() function
        hjl> in Python. I get it now!

        Fine with me. I've never used it. ;-)

        hjl> (e) Wait a second... searching through the Python newsgroup archive
        hjl> I find hundreds if not thousands of messages related to
        hjl> the usage of the compile() function. So the compile() function
        hjl> can't be useless. Either thousands of Python users are wrong,
        hjl> or I have not been careful in my thinking process.

        I think you're dreaming here.

        hjl> Bingo! Now you get it.

        I think you built your logic on a false premise: namely that lots of people
        use the compile() builtin. If you google for something like "Python
        compile", I'll wager almost every hit will be about:

        1. compiling Python itself,

        2. the Python byte code compiler (to which the compile() function is
        only a rarely used interface), or

        3. compiling regular expressions

        and most of the hits which are actually about the compile() builtin will be
        links to pages which document it.

        Skip


        Comment

        • Hung Jung Lu

          #19
          Re: code blocks in Python

          "John Roth" <newsgroups@jhr othjr.com> wrote in message news:<vs56mue8h mdob1@news.supe rnews.com>...[color=blue]
          > I'm probably representative. If you don't manage a compelling
          > case for why dynamic binding is a useful option, then you're not going
          > to get anywhere with this proposal.[/color]

          Wow, I did not even know there was a proposal. :)

          I thought the purpose of my message was to find out whether there have
          been previous attempts. I still have not gotten an answer, and I see
          already lots of fire. For no good reason.

          As I have said, I refuse to believe I am the first person to bring up
          this topic. Because it seems such a simple issue, such a simple
          feature. (Bear in mind that the compile() function exists since a long
          long time ago.) So, I am prepared to listen to experts comment on why
          everything is wrong and un-doable, and that the topic has been covered
          many times before and is dead since a long time ago. So that I can
          simply stop. Yet, I have heard none to the effect.

          ------------------

          Like someone said once about metaclasses: if you need to ask if you
          need to use metaclasses, the answer is "you don't". Same thing with
          metaprogramming . If you need to ask whether you need metaprogramming ,
          the answer is: "you don't". People that get into metaclasses and
          metaprogramming know what they want to do.

          If you have really read and digested my comment about thinking first
          on compile() function and post later, you wouldn't have posted your
          message.

          There are two issues here:

          (1) The usefulness of meta-programming.
          (2) Codeblock feature.

          You are asking the question about (1), not (2). My impression is that
          you have no experience using compile() function, nor general idea
          about metaprogramming . (Feel free to correct me.) But you decide to
          use it as an argument to attack (2) anyway, instead of (1). Your
          firepower is misplaced, and causes only colateral damages.

          Usefulness of meta-programming (in particular, linear
          meta-programming) is a completely different subject. If you don't like
          metaprogramming , you should have attacked Guido a long time ago, when
          the compile() function and code object appeared in Python. That's what
          I mean by you need to keep the compile() function in mind before you
          make senseless comments about dynamic binding and linking it to (2).

          You need to first make that distinction in mind. Your mistake and of
          the others comes from your unfamiliarity with the usage of code
          objects. Your questions are not regarding codeblock implementation.
          Your questions are about metaprogramming in general.

          Sure, I'm more than glad to discuss about linear metaprogramming ,
          despite of having discussed with tons of other Python regulars lots of
          times before. But before that, I'd like to make sure about my original
          point: has the idea of codeblock ever been discussed in Python? When
          and where and the URL links. I am still waiting.

          regards,

          Hung Jung

          Comment

          • John Roth

            #20
            Re: code blocks in Python

            news:8ef9bea6.0 311242041.92f10 8a@posting.goog le.com...[color=blue]
            > "John Roth" <newsgroups@jhr othjr.com> wrote in message[/color]
            news:<vs56mue8h mdob1@news.supe rnews.com>...[color=blue][color=green]
            > > I'm probably representative. If you don't manage a compelling
            > > case for why dynamic binding is a useful option, then you're not going
            > > to get anywhere with this proposal.[/color]
            >
            > Wow, I did not even know there was a proposal. :)
            >
            > I thought the purpose of my message was to find out whether there have
            > been previous attempts. I still have not gotten an answer, and I see
            > already lots of fire. For no good reason.
            >
            > As I have said, I refuse to believe I am the first person to bring up
            > this topic. Because it seems such a simple issue, such a simple
            > feature. (Bear in mind that the compile() function exists since a long
            > long time ago.) So, I am prepared to listen to experts comment on why
            > everything is wrong and un-doable, and that the topic has been covered
            > many times before and is dead since a long time ago. So that I can
            > simply stop. Yet, I have heard none to the effect.[/color]

            Try Google Groups.
            [color=blue]
            >
            > ------------------
            >
            > Like someone said once about metaclasses: if you need to ask if you
            > need to use metaclasses, the answer is "you don't". Same thing with
            > metaprogramming . If you need to ask whether you need metaprogramming ,
            > the answer is: "you don't". People that get into metaclasses and
            > metaprogramming know what they want to do.
            >
            > If you have really read and digested my comment about thinking first
            > on compile() function and post later, you wouldn't have posted your
            > message.[/color]

            Rudeness objection. You're mind reading. You have no
            idea what I'm thinking, or what my background is.
            [color=blue]
            >
            > There are two issues here:
            >
            > (1) The usefulness of meta-programming.
            > (2) Codeblock feature.
            >
            > You are asking the question about (1), not (2). My impression is that
            > you have no experience using compile() function, nor general idea
            > about metaprogramming . (Feel free to correct me.) But you decide to
            > use it as an argument to attack (2) anyway, instead of (1). Your
            > firepower is misplaced, and causes only colateral damages.[/color]

            Rudeness objection. What I know or don't know isn't of issue.
            Since you said you don't have a clear use case, my participation
            in this discussion is ended.

            John Roth


            Comment

            • Florian Reiser

              #21
              Re: code blocks in Python

              Hi folks,

              I have read your thread about code blocks.
              When reading it, a problem that I have came to my mind.
              I have a module ZReportLab. This module defines a class for Zope
              (http://www.zope.org) for using the reportlab library.
              The actual code I want the object to execute is stored in three string
              variables, compiled at change time with compile()
              and executed, when the object is called. So I can use a different content
              code for each object I have created in the object database
              of Zope.
              But no one programs without errors, so every time I've made an error, I get
              a traceback holding the information that there's an error,
              inside my code object.
              It would be nice if I could debug it with pdb. But at the moment I have to
              guess where the error is, or step towards it, through inserting
              a raise and trying if it runs to the position of the raise. This is really
              hard work.
              How can I compile my code object, so that I can debug it when I do the exec
              codeObject?

              Regards
              Florian Reiser

              "Hung Jung Lu" <hungjunglu@yah oo.com> schrieb im Newsbeitrag
              news:8ef9bea6.0 311221215.804bd b3@posting.goog le.com...[color=blue]
              > Hi,
              >
              > I know people have talked about it before, but I am still really
              > confused from reading the old messages.
              >
              > When I talk about code blocks, I am not talking about Lisp/Ruby/Perl,
              > so I am not making comparisons.
              >
              > If you have a file, in Python you could do:
              >
              > code = compile(code_st ring, 'FileName.py', 'exec')
              >
              > and obtain a code object, which later on you can execute. That's the
              > kind of code block I have in mind. That is, no parameters, no
              > specification of scopes, no nothing else. Just a plain block of code
              > lines compiled into a code object.
              >
              > It's not too much work to write a code string like:
              >
              > my_codeblock = '''
              > x = x + 1
              > y = y + 2
              > '''
              >
              > and then use compile() to turn it into a code object. But it seems to
              > me that Python could perfectly allow this syntax directly into the
              > language, something like:
              >
              > codeblock my_codeblock:
              > x = x + 1
              > y = y + 2
              >
              > so that users won't need to explicitly call the compile() function.
              > The advantage is that the codeblock is compiled at compile time, not
              > at run time, even if the codeblock is defined inside something else (a
              > class, a function, etc.)
              >
              > Is there something obvious that I am missing here? Why isn't codeblock
              > part of the language? It seems to be an important building element for
              > meta-programming. Not only that, it seems to be much more fundamental
              > than functions. So, why isn't it part of Python? Any intrinsic
              > difficulties?
              >
              > regards,
              >
              > Hung Jung[/color]


              Comment

              Working...