DAL new syntax RFC

162 views
Skip to first unread message

Massimo Di Pierro

unread,
Mar 4, 2011, 10:55:57 AM3/4/11
to web2py-users
There are some new features in trunk:

1)

I got tired of writing default='value',readable=False,writable=False
etc.

So:

Field(':name') is the same as
Field('name',readable=False,writable=False)
Field('.name') is the same as
Field('name',readable=True,writable=False)
Field('name=value') is the same as Field('name',default='value')

and combinations:

Field(':name=value') is the same as
Field('name',default='value',readable=True,writable=False)

notice

Field('name=') is the same as Field('name',default='')

2)

db(db.table).select((db.table.field.length()+5).sum())

note operators length(), +5, sum() can be combined in more ways than
before.







pbreit

unread,
Mar 4, 2011, 5:43:39 PM3/4/11
to web...@googlegroups.com
I like the "default" functionality since it's still really easy to understand. I'm not sold on the : and . shortcuts.

Massimo Di Pierro

unread,
Mar 4, 2011, 6:50:49 PM3/4/11
to web2py-users
think of a dot a False. Two does r and w are false, one dot and only w
is false.

Luther Goh Lu Feng

unread,
Mar 4, 2011, 11:34:38 PM3/4/11
to web2py-users
I too like the 'default' syntax much better than the new one. It feels
more readable.

If the following is feasible, will it be a better solution?

Field('name', r=F,w=F)

Field('name', d='value')


On Mar 5, 7:50 am, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Phyo Arkar

unread,
Mar 5, 2011, 8:47:37 AM3/5/11
to web...@googlegroups.com
Field(':name') and Field('.name') Is very hard to read.

Especially : Field('.name') . When writing large applications with
many lines of codes , "." is very very hard to read.

pbreit

unread,
Mar 5, 2011, 2:05:13 PM3/5/11
to web...@googlegroups.com
Obviously those of us who don't like it don't have to use it but I fear it going into documentation and leading to confusion.

This is where I like one of the zens:

"There should be one-- and preferably only one --obvious way to do it."

Stefaan Himpe

unread,
Mar 5, 2011, 2:29:59 PM3/5/11
to web...@googlegroups.com
> think of a dot a False. Two does r and w are false, one dot and only w
> is false.

IMHO: It's very short to write, but nearly impossible to guess its
meaning. Wouldn't Field('readonly:name') and Field('invisible:name') be
more readable ?

Vidul Petrov

unread,
Mar 5, 2011, 3:52:57 PM3/5/11
to web2py-users
I agree with Stefaan.

However the ':' before a variable name notation looks like the Ruby
symbols whose only purpose was improved performance (lightweight
strings) but lead inevitably to confusion (IMHO).


On Mar 4, 5:55 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Thadeus Burgess

unread,
Mar 5, 2011, 7:36:14 PM3/5/11
to web...@googlegroups.com
Explicit is better than implicit. Typing is cheap. Design is the hardest part of development.

--
Thadeus

Michele Comitini

unread,
Mar 5, 2011, 7:49:47 PM3/5/11
to web...@googlegroups.com
+1

2011/3/6 Thadeus Burgess <thad...@thadeusb.com>:

Massimo Di Pierro

unread,
Mar 6, 2011, 2:42:15 AM3/6/11
to web2py-users
OK, I will probably take it off... do not count on this feature being
backward compatible, yes I need to sleep on it some more.

On Mar 5, 6:49 pm, Michele Comitini <michele.comit...@gmail.com>
wrote:
> +1
>
> 2011/3/6 Thadeus Burgess <thade...@thadeusb.com>:
>
>
>
>
>
>
>
> > Explicit is better than implicit. Typing is cheap. Design is the hardest
> > part of development.
>
> > --
> > Thadeus
>

villas

unread,
Mar 6, 2011, 2:01:29 PM3/6/11
to web2py-users
>> Typing is cheap.

Not so cheap in a RAD framework.
However, agreed that we don't want anything that looks like 'magic' :)
-David

Jonathan Lundell

unread,
Mar 6, 2011, 2:06:12 PM3/6/11
to web...@googlegroups.com
On Mar 6, 2011, at 11:01 AM, villas wrote:
>
> However, agreed that we don't want anything that looks like 'magic' :)

Too late now...

villas

unread,
Mar 6, 2011, 4:51:25 PM3/6/11
to web2py-users
> Too late now...

Well... you're right - we do have quite a bit of magic already :-)

But extra punctuation marks don't make the code very readable.
More meaningful abbreviations would prompt people to look them up if
they don't know them.

For example, if an abbreviation was: Field('vf:name') - short for
"visible false",
I could make a search in the book for 'vf:' and I would discover the
meaning immediately.

Now try a similar search in the book for '.'

-D

Massimo Di Pierro

unread,
Mar 6, 2011, 5:15:40 PM3/6/11
to web2py-users
You could try for '. and ': in a model and I am pretty sure there is
no ambiguity. Moreover if the Field(s) are indented the . and : are
easy to spot. That was the rationale.

Massimo

villas

unread,
Mar 6, 2011, 5:40:26 PM3/6/11
to web2py-users
To me, to use a period '.' is inherently very ambiguous.
But mine is just one point of view and of course I do see the benefit
of typing less.
Thanks, D


On Mar 6, 10:15 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Luis Díaz

unread,
Mar 6, 2011, 11:30:33 PM3/6/11
to web...@googlegroups.com
Explicit is better than implicit. 
+1

kenji4569

unread,
Mar 7, 2011, 8:36:26 AM3/7/11
to web2py-users
Other alternatives might be:

Field('name', **Field.readonly)?
Field('name').readonly()?

though I appreciate explicit is better than implicit.

On 3月6日, 午前9:49, Michele Comitini <michele.comit...@gmail.com> wrote:
> +1
>
> 2011/3/6 Thadeus Burgess <thade...@thadeusb.com>:
>
>
>
>
>
>
>
> > Explicit is better than implicit. Typing is cheap. Design is the hardest
> > part of development.
>
> > --
> > Thadeus
>

Massimo Di Pierro

unread,
Mar 7, 2011, 6:10:42 PM3/7/11
to web2py-users
I am leaning towards

r=False,w=False,d='default' as alises for readable, writable and
default.

ron_m

unread,
Mar 7, 2011, 6:13:44 PM3/7/11
to web...@googlegroups.com
+1

Luis Díaz

unread,
Mar 7, 2011, 6:30:38 PM3/7/11
to web...@googlegroups.com
in my humble opinion
I think abbreviations are unnecessary.
this is ruby on rails

remember everyone:
the code is read more times than is written.

Díaz Luis
TSU Analisis de Sistemas
Universidad de Carabobo





2011/3/7 ron_m <ron.m...@gmail.com>
+1

Michael Barrow

unread,
Mar 7, 2011, 9:57:28 PM3/7/11
to web...@googlegroups.com
Yeah -- I agree with that! Macros in your editor keep you from typing as much. This is akin to technical folks incessant desire to create new acronyms. Ugh!
--
Michael Barrow
michael at barrow dot me
+1 (408) 782-4249

pbreit

unread,
Mar 7, 2011, 10:20:10 PM3/7/11
to web...@googlegroups.com
If we are evaluating enhancements that save a few keystrokes AND increase clarity, I'd consider this. :-)

     URL('default/home') for URL(c='default', f='home') or URL('default', 'home')

Thadeus Burgess

unread,
Mar 7, 2011, 10:26:05 PM3/7/11
to web...@googlegroups.com
You can already do


URL('default', 'home')

It has been in web2py for some months now.

--
Thadeus

Luis Díaz

unread,
Mar 8, 2011, 12:24:45 AM3/8/11
to web...@googlegroups.com
"premature optimization is the root of all evil"

otherwise I still use:
URL (f = 'default ', c = 'home')

these characters f =, c =
I may write more readable code

pbreit

unread,
Mar 8, 2011, 1:06:44 AM3/8/11
to web...@googlegroups.com
Yeah, I did also note URL('default', 'home')

Sure it's only 3 or 4 chars but I also like the readability of 'default/index' when working on web projects.

This is not a big deal, of course.

villas

unread,
Mar 8, 2011, 6:51:13 AM3/8/11
to web2py-users
Ideally there should just be one clear and convenient way of doing
something, otherwise we can confused.

Everytime we introduce a synonym we raise numerous questions on the
list and add a paragraph to the book. Ascribing a special meaning to
a period is totally against the clarity of the code. I believe we
should avoid synonyms and short-cuts wherever possible.

IMO if there is a clearer and more convenient way of doing something,
we should clearly deprecate the old way and introduce and promote the
new syntax. Maybe this will make us think carefully about introducing
changes.

-D

contatog...@gmail.com

unread,
Mar 8, 2011, 10:01:26 AM3/8/11
to web...@googlegroups.com
URL (f = 'default ', c = 'home')

This is desnecessary. I'm not used. Buy like this:

URL('default','home')

This is clean.
_____________________________________________
Gilson Filho


2011/3/8 villas <vill...@gmail.com>

Luis Díaz

unread,
Mar 8, 2011, 12:22:55 PM3/8/11
to web...@googlegroups.com
add shortcuts and much more magic.
distance of the system of philosophy python

Python is clean, easy to read.
You can love the language and can devote
time reading, that is understandable, allowing you to learn more easily

web2py is easy, because it's python, not have to learn new and complicated abbreviations.
Unlike other frameworks you have to learn a large list of commands and how to do things.

my language is Spanish.
my English is technical.
I do not want to be learning new things as shortcuts that only apply in the context ...


Díaz Luis
TSU Analisis de Sistemas
Universidad de Carabobo





Reply all
Reply to author
Forward
0 new messages