Python syntax wart

  • Thread starter Lawrence D'Oliveiro
  • Start date
M

Marc 'BlackJack' Rintsch

Good, you're improving.
Thanks.


Who said anything about a table?

Me. If that statement is 2D I expected to see a table structure. And I
don't mean that the source code itself is arranged in lines and columns
but that the so called *2D statement* can be seen as table.
Which is precisely the point.

Then is the lack of curly braces also a syntax wart. Maybe you should
switch to a different language or write a preprocessor.

Ciao,
Marc 'BlackJack' Rintsch
 
S

Stefan Behnel

Lawrence said:
Which is precisely the point.

This actually sounds somewhat pointless to me. If complex things don't fit
into one line, a good way to deal with it is not to insist on making them a
single statement.

Stefan
 
G

Gabriel Genellina

How can a statement be two-dimensional? Like a two-dimensionalTuringMachine?

Do you know the Befunge language? Program flow is not lineal but along
a 2D grid. There are variants over toroids and more bizarre surfaces,
even using 3D.

"Befunge is believed to be the first two-dimensional, ASCII-based,
general-purpose programming language."
<http://www.esolangs.org/wiki/Befunge>
 
D

Duncan Booth

Stefan Behnel said:
This actually sounds somewhat pointless to me. If complex things don't
fit into one line, a good way to deal with it is not to insist on
making them a single statement.

Or make them into a single method/function call. I would post some pseudo-
code replacing the TheProduct conditions with a single call to a
meaningfully named method except I haven't got the faintest idea what it is
trying to achieve.
 
B

Bjoern Schliessmann

TheFlyingDutchman said:
It may be that a language that doesn't have a statement terminator
(which can be end-of-line) needs a statement continuation symbol.

Which language could that be? I can hardly imagine making a complex
program out of one statement.

Regards,


Björn
 
B

Bjoern Schliessmann

Lawrence said:
In message <[email protected]>, Bjoern

Then you're no longer showing the syntax structure in two
dimensions.

Why should I want to? :)

BTW, this is the first time I read about "two dimensional syntax".
What's the benefit?

Regards,


Björn
 
B

Bjoern Schliessmann

Gabriel said:
Do you know the Befunge language? Program flow is not lineal but
along a 2D grid. There are variants over toroids and more bizarre
surfaces, even using 3D.

Ah, I remember. Once read about it. Really cool idea :)

Regards,


Björn
 
B

Bjoern Schliessmann

Lawrence said:
In message <[email protected]>, Marc 'BlackJack'

Good, you're improving.

Tree structures can't, IMHO, be called two-dimensional. Although,
you can represent them with a two-dimensional graph. If the tree
gets more complex this can become very messy.
Which is precisely the point.

You're the first person I see using a complete line just for an "if"
or "for". Is this for tuning the code line count?

Regards,


Björn
 
T

TheFlyingDutchman

It may be that a language that doesn't have a statement terminator
(which can be end-of-line) needs a statement continuation symbol.
(Excluding languages like Lisp that have parentheses everywhere).

Actually I guess Python does have a statement terminator - end-of-
line.
If you use end-of-line as your statement terminator it is difficult
and maybe impossible
to avoid a line-continuation character in those situations where you
don't want
an end-of-line to terminate your statement.
 
T

TheFlyingDutchman

Which language could that be? I can hardly imagine making a complex
program out of one statement.

Regards,

Björn

Funny how I mentioned end-of-line but didn't include Python as one
those languages that used it.
I should have said "It may be that a language that doesn't have a
statement terminator
symbol, but instead uses end-of-line, can't avoid a statement
continuation symbol.
 
J

Jason

The one thing I don't like about Python syntax is using backslashes to
continue lines. Yes, you can avoid them if you can include parentheses
somehow, but this isn't always possible.

Possible:

if (
quitting
and
len(client["to_write"]) == 0
and
len(client["read"]) + client["to_read"] == 0
) :
close_client(client, "shutting down")
#end if

Not possible:

for \
Link \
in \
GetEachRecord \
(
"links",
("from_episode",),
"to_episode = %s",
[EpisodeID],
"order by when_created"
) \
:
out.write \
(
"<P><A HREF=\"%s\">Back to episode %d</A>\n"
%
(
LinkToMe({"ep" : Link["from_episode"]}),
Link["from_episode"]
)
)
#end for

Python doesn't prevent you from writing ugly code, using poor variable
names, or doing other silly things. The rules on indention require
that you are at least consistent on a given line. That said, the
backslash simply continues the line, and I don't see why your (ugly,
IMO) code is impossible. Here's some similarly schizophrenically
formatted code that I just tried:
.... l\
.... in \
.... (\
.... 1,
.... 2,
.... 3
.... )\
.... :
.... print\
.... "This is "\
.... "poorly "\
.... "formatted!",\
.... l
....
This is poorly formatted! 1
This is poorly formatted! 2
This is poorly formatted! 3
Looks like it runs to me. In general, I'd recommend that you avoid
such nonsense spacing and alignment, and use wrappers, generators, and
other Python constructs to help write more sensible code.

--Jason
 
S

Steven W. Orr

On Monday, Sep 10th 2007 at 08:34 -0000, quoth Marc 'BlackJack' Rintsch:

=>On Mon, 10 Sep 2007 20:19:08 +1200, Lawrence D'Oliveiro wrote:
=>
=>> In message <[email protected]>, Marc 'BlackJack' Rintsch
=>> wrote:
=>>
=>>> I see a tree structure here ...
=>>
=>> Good, you're improving.
=>
=>Thanks.
=>
=>>> ... but still no table.
=>>
=>> Who said anything about a table?
=>
=>Me. If that statement is 2D I expected to see a table structure. And I
=>don't mean that the source code itself is arranged in lines and columns
=>but that the so called *2D statement* can be seen as table.
=>
=>>> And this is also easily written that way in Python if you don't insist on
=>>> the line break after the ``if`` or can live with backslashes.
=>>
=>> Which is precisely the point.
=>
=>Then is the lack of curly braces also a syntax wart. Maybe you should
=>switch to a different language or write a preprocessor.

C'mon give the
poor guy
a break.

What did
I just
say ?

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 
C

Carl Banks

Actually I guess Python does have a statement terminator - end-of-
line.
If you use end-of-line as your statement terminator it is difficult
and maybe impossible
to avoid a line-continuation character in those situations where you
don't want
an end-of-line to terminate your statement.

Well, a good chunk of line continuations can be done implicitly with
parentheses (one of the few places where implicit is better than
explicit).

Problem is, there are a few places where you might to break line that
parentheses aren't legal. Back in the day, import statements were
like this, but the designers of Python artifically added the ability
to use parentheses there. Nowadays, they're rarely needed. One of
their main remaining uses is in opening multiline strings, like so:

mls = """\
This is line 1.
This is line 2.
I like all my lines lined up.
"""

The OP seems to be complaining that you can't arbitrarily break lines
in the middle of a statement, so that he can write ridiculously
formatted code. It's not impossible to do what he asks; for example,
the following hypothetical code is not ambiguous.

for
x
in
range(10)
:
print x

It isn't legal to end the statement anywhere before the colon, so it
would be possible to add a rule to Python's parser that says, "there
shall be implicit line continuations everywhere between the opening
keyword and the colon".

To be honest, I've always thought this would be a nice feature to
have, but now that I've seen what kind of abominations are possible
with it, I'm not so sure.

Carl Banks



P.S. The "two dimensional structure" can currently be done like this,
not that I believe such a travesty should ever be used in real code.

for(
x
)in(
range(10)
):
print x
 

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,773
Messages
2,569,594
Members
45,122
Latest member
VinayKumarNevatia_
Top