Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [OT] code is data

Reply
Thread Tools

[OT] code is data

 
 
Ravi Teja
Guest
Posts: n/a
 
      06-18-2006

Fredrik Lundh wrote:
> Ravi Teja wrote:
>
> > Web frameworks, which seem to be the rage now in Python community could
> > have benefited tremendously from Macro capabilities since they have a
> > lot of boiler plate.

>
> they do? methinks you haven't done much web programming lately...
>
> </F>


You blogged on Django. Let's use that. Don't you think model creation
in Django can be represented better, given that it is done often
enough?

Let's take an example from the official tutorial
from
http://www.djangoproject.com/documen...reating-models

class Poll(models.Model):
question = models.CharField(maxlength=200)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(maxlength=200)
votes = models.IntegerField()

I don't use Django and I made this up quickly, so please don't pick on
subtleties.

@Poll:
question: char length 200
pub_date('date published'): date

@Choice:
poll -> Poll
choice: char length 200
votes: int

The following is my rationale. Annoted variables, symbols and code
layout visually cue more efficiently to the object nature than do
explicit text definitions. Of course, this is only sensible when there
aren't too many of any of those. In that case, the cognitive cost of
notation outweighs the representational cost of text.

Representational minimalism is troublesome in general code (ala Perl),
but not so in a DSL where the context is constrained.

I would also like to symbolize field types since they occur so commonly
in a definition file and only a few of them are commonly used. I admit
though that I find the code below a bit visually jarring and I might
use something else. But it serves to illustrate the point. I chose the
respective symbols based on their colloquial use and association with
the field types.

@Poll:
$question: length 200
%pub_date('date published')

@Choice:
poll -> Poll
$choice: length 200
#votes

Since you are on thread and are a prominent and involved member of the
Python community, I would like it if you (or any such other) can
provide feedback on the rest of my previous post rather than be
dismissive by just a small portion of it. Perhaps, that will give me
some insight how these language design decisions are rationally made (I
am not strictly a programmer by profession, much less a language
designer).

 
Reply With Quote
 
 
 
 
Roberto Bonvallet
Guest
Posts: n/a
 
      06-18-2006
Ravi Teja <(E-Mail Removed)> said:
> I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would
> have done it myself for *my* code.


You can write your own preprocessor to handle things like that.
--
Roberto Bonvallet
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=
Guest
Posts: n/a
 
      06-18-2006
> > > community has no interest in it. When I absolutely need macros, I will
> > > go elsewhere.

> I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would
> have done it myself for *my* code.


I think this example more is a symptom of a childish need to get
things your way than of a deficiency in Python. BTW, range(5) = 0..4
in Ada and Ruby.

You said "when I absolutely need macros" but none of your examples
demonstrate any "absolute need." I can't see your point.

--
mvh Björn
 
Reply With Quote
 
bruno at modulix
Guest
Posts: n/a
 
      06-19-2006
Anton Vredegoor wrote:
> With the inclusion of ElementTree (an XML-parser) in Python25 and recent
> developments concerning JSON (a very Pythonesque but somewhat limited
> XML notation scheme, let's call it statically typed XML)


JSON stands for JavaScript Object Notation, and has *nothing* to do with
XML - except for the fact that it's more and more used instead of XML
for AJAX stuff.

> Python seems to
> have reached a stage where it now seems to be possible to completely
> swallow lesser languages code, modify it, and spit out new source code
> targeting the original language the code was written in, or even make a
> translation to other languages.


If you mean "parsing source in a given format and outputting another -
modified or not - representation, in the same or another format", Python
as always been able to do so.

> The idea is that we now have a fast parser (ElementTree) with a
> reasonable 'API' and a data type (XML or JSON) that can be used as an
> intermediate form to store parsing trees. Especially statically typed
> little languages seem to be very swallow-able. Maybe I will be able to
> reimplement GFABasic (my first love computer language, although not my
> first relationship) someday, just for fun.
>
> Then there are things like cTypes (calling functions from native DLL's)
> and PyPy (implementing Python in Python).
>
> All this taken together, to me it starts looking like we're now entering
> a territory that traditionally was exclusively in the Lisp domain.


Sorry, but I just don't get the point. Parsing, working with trees and
calling native code are in no way "exclusively in the Lisp domain".

> Yes, Python had eval and exec for a long time already, and metatypes and
> generators are having some strange unexplored possibilities too, but the
> day will come soon (and at last when PyPy is reaching execution speeds
> close to cPython) where Python will be able to swallow smaller
> languages, and finally it will be able to swallow its own tail, like
> Lisp but then more powerful


I'm afraid Python is still very far from Lisp - and will never get there
(FWIW, this seems not to be the goal anyway).

> (because of the widely used standard data
> types and the code exchange between languages that that makes possible).


I still don't get the point.

> Your thoughts please.
>
> Anton



--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
bruno at modulix
Guest
Posts: n/a
 
      06-19-2006
BJörn Lindqvist wrote:
>> Personally, I would like to see macros in Python (actually Logix
>> succeeding is good enough). But I am no language designer and the
>> community has no interest in it. When I absolutely need macros, I will
>> go elsewhere.

>
>
> One must wonder, when is that? When do you absolutely need macros?
>

One must wonder, when do you absolutely need HOFs, closures, OO,
functions, or even structured programming. All we 'absolutely' need is
tests and gotos... (and love, of course !-).

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
bruno at modulix
Guest
Posts: n/a
 
      06-19-2006
Ravi Teja wrote:
> BJörn Lindqvist wrote:
>
>>>Personally, I would like to see macros in Python (actually Logix
>>>succeeding is good enough). But I am no language designer and the
>>>community has no interest in it. When I absolutely need macros, I will
>>>go elsewhere.

>>
>>One must wonder, when is that? When do you absolutely need macros?

>
>
> Whenever there is significant boiler plate code that functions and
> classes cannot eliminate alone.
> Whenever there is a more elegant way to express your code.
>
> Python 2.5 introduced conditional expressions and with statement. With
> macros, one would not have to wait for the language team to implement
> them. More so for features which only a small part of the community has
> an interest in.
>
> I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would
> have done it myself for *my* code.


And that's the downside with macros - and with anything that's not
officially part of the language or it's standard lib : everybody
implements it it's own way, and you end up with dozens non-standard ways
of doing the same thing.

Not to say this is absolutely bad, but there's a balance to be found
here. One could do function decorators long before we had official
syntactic sugar for it, but it only started to be a common idiom with
the @decorator syntax. Python 2.5 introduces a 'partial' type, that is
quite easy to implement with 2.4 (and probably with older versions too),
but having it in the builtins or standard lib means it will become the
standard way to do it - no need to deal with half a dozen half-backed
implementations of it no more.


--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
bruno at modulix
Guest
Posts: n/a
 
      06-19-2006
Ravi Teja wrote:

(snip)
> Annoted variables, symbols and code
> layout visually cue more efficiently to the object nature than do
> explicit text definitions. Of course, this is only sensible when there
> aren't too many of any of those. In that case, the cognitive cost of
> notation outweighs the representational cost of text.
>
> Representational minimalism is troublesome in general code (ala Perl),
> but not so in a DSL where the context is constrained.


This still impose the need to learn a new language.

> I would also like to symbolize field types since they occur so commonly
> in a definition file and only a few of them are commonly used. I admit
> though that I find the code below a bit visually jarring and I might
> use something else. But it serves to illustrate the point. I chose the
> respective symbols based on their colloquial use and association with
> the field types.
>
> @Poll:
> $question: length 200
> %pub_date('date published')
>
> @Choice:
> poll -> Poll
> $choice: length 200
> #votes


<IMHO>Yuck</IMHO>.


--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
Anton Vredegoor
Guest
Posts: n/a
 
      06-19-2006
bruno at modulix wrote:

> I still don't get the point.


Well, I've got to be careful here, lest I'd be associated with the
terr.., eh, the childp..., eh the macro-enablers.

The idea is to have a way to transform a Python (.py) module into XML
and then do source code manipulations in XML-space using ElementTree.

But rest assured, there is no such module, nor will we ever need it for
anything.

Anton

"use cases are for the faint-hearted"
 
Reply With Quote
 
Michele Simionato
Guest
Posts: n/a
 
      06-19-2006
John Roth wrote:
> I saw the "make" statement as a breath of fresh air.
> Then it got shot down for what were, to me, totally
> trivial reasons.


Which reasons? I as I recall, Guido cut it out without giving any
reason.
Of course Guido has the right to do so, but it is not respectful of
all the work people like Steven Bethard and others did

Michele Simionato

 
Reply With Quote
 
bruno at modulix
Guest
Posts: n/a
 
      06-19-2006
Anton Vredegoor wrote:
> bruno at modulix wrote:
>
>> I still don't get the point.

>
>
> Well, I've got to be careful here, lest I'd be associated with the
> terr.., eh, the childp..., eh the macro-enablers.
>
> The idea is to have a way to transform a Python (.py) module into XML
> and then do source code manipulations in XML-space using ElementTree.


My my my... I'm not against the idea of dynamic source code
transformation, but for heaven's sake, *why* would one put XML in the
mix ???????


--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How add data to Entity Data Model via code? Bobby Edward ASP .Net 0 09-23-2008 03:18 PM
Data Recovery SOURCE CODE ( SOURCE CODES of Professional Data Recovery Software ) Author Tarun Tyagi C Programming 0 12-29-2004 05:10 PM
Data Recovery SOURCE CODE ( SOURCE CODES of Professional Data Recovery Software ) Author Tarun Tyagi Cisco 0 12-29-2004 05:03 PM
Passing data/code from code-behind to aspx aratienza ASP .Net Web Controls 1 12-10-2004 04:55 PM
Passing code/data from code-behind to ASPX page A. Atienza ASP .Net Datagrid Control 1 12-08-2004 06:29 PM



Advertisments