Hi there,
this is rather a philosophical question, but I assume I miss something.
I don't remember I ever used else clause for years I was with python and
my expectation was it executed only if the the main body was never run. Ha-ha! I was caught by this mental trap.
So, seriously, why they needed else if the following pieces produce same result? Does anyone know or remember their motivation?
Just curious.
Axy.
print('--- with else')
for i in [1,2,3]:The else is always coming with the break, not the for. There are [for ...], [for...break...], and[for...break...else], but the [for...else] is insane.
print(i)
else:
print(4)
for i in []:
print(i)
else:
print(5)
print('--- without else')
for i in [1,2,3]:
print(i)
print(4)
for i in []:
print(i)
print(5)
On 10/7/22 21:32, Axy wrote:
So, seriously, why they needed else if the following pieces produce
same result? Does anyone know or remember their motivation?
In real scenarios there would be more logic in the for block that
would meet a condition and break out of the loop. If the condition is
never met, the else block runs. To steal from w3schools:
fruits = ["apple", "peach", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
else:
print("Yes we got no bananas")
Got it, thanks!
Actually the reason I never used "else" was the violation of the rule of beauty "shortest block first". With if--else you can easily follow this
rule by inverting "if" expression, but with for--else you can't. The
loop body of the simplest example is already three lines, in real life
things are much worse.
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list <python-list@python.org> wrote:
Got it, thanks!That's not a rule I've ever been taught; how important is it?
Actually the reason I never used "else" was the violation of the rule of
beauty "shortest block first". With if--else you can easily follow this
rule by inverting "if" expression, but with for--else you can't. The
loop body of the simplest example is already three lines, in real life
things are much worse.
ChrisA
On 09/10/2022 05:47, Chris Angelico wrote:
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list <python-list@python.org> wrote:
Got it, thanks!That's not a rule I've ever been taught; how important is it?
Actually the reason I never used "else" was the violation of the rule of >> beauty "shortest block first". With if--else you can easily follow this
rule by inverting "if" expression, but with for--else you can't. The
loop body of the simplest example is already three lines, in real life
things are much worse.
ChrisA
It gets important if the lifetime of your project is more than three
months and is extremely important if more than 10 years. But, it depends.
I also might be wrong in terminology, anyway, there are many rules that
make programmer's life easier, described in the literature from the old
good "How to write unmaintainable code" to "The Art of Readable Code".
And I hope there are a lot of recent books on this subject I did not
track and read yet.
Python is awesome because it's semantic is clear for the majority, but
there are places that look odd. In case of "for", "else" looks logically
tied with "for" clause, but actually it is not. It's tied with "break" statement and I overlooked that even after re-reading the language
reference. If "else" was named like "never_broken_loop" or "nobreak",
the semantic would be perfectly clear. But, what's done is done.
Yes, I'm aware that code readability becomes irrelevant for
short-duration projects. Beside the point. I'm wondering how important
it really is to have the shortest block first.
I also might be wrong in terminology, anyway, there are many rules thatAlso not really a justification for "shortest block first". Wanting
make programmer's life easier, described in the literature from the old
good "How to write unmaintainable code" to "The Art of Readable Code".
And I hope there are a lot of recent books on this subject I did not
track and read yet.
some elaboration on that. What's the value in it?
Actually the reason I never used "else" was the violation of the rule
of beauty "shortest block first".
Also not really a justification for "shortest block first".Well, the value is productivity. No need to save puzzles "what this
hanging else belongs to?" regardless of semantic, which ideally should
not be a puzzle as well.
Well, the value is productivity. No need to save puzzles "what this
hanging else belongs to?"
Yes, I'm aware that code readability becomes irrelevant for
short-duration projects. Beside the point. I'm wondering how important
it really is to have the shortest block first.
I also might be wrong in terminology, anyway, there are many rules thatAlso not really a justification for "shortest block first". Wanting
make programmer's life easier, described in the literature from the old
good "How to write unmaintainable code" to "The Art of Readable Code".
And I hope there are a lot of recent books on this subject I did not
track and read yet.
some elaboration on that. What's the value in it?
Well, the value is productivity. No need to save puzzles "what this
hanging else belongs to?" regardless of semantic, which ideally should
not be a puzzle as well. Code small things first and return early, same
as taking a test: do easy and quick things first and boring and
difficult ones later.
Axy.
--
https://mail.python.org/mailman/listinfo/python-list
On Sun, 9 Oct 2022 at 16:05, Axy via Python-list <python-list@python.org> wrote:
On 09/10/2022 05:47, Chris Angelico wrote:python-list@python.org> wrote:
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list <
ofGot it, thanks!
Actually the reason I never used "else" was the violation of the rule
thisbeauty "shortest block first". With if--else you can easily follow
rule by inverting "if" expression, but with for--else you can't. TheThat's not a rule I've ever been taught; how important is it?
loop body of the simplest example is already three lines, in real life >> things are much worse.
ChrisA
It gets important if the lifetime of your project is more than three
months and is extremely important if more than 10 years. But, it depends.
Yes, I'm aware that code readability becomes irrelevant for
short-duration projects. Beside the point. I'm wondering how important
it really is to have the shortest block first.
I also might be wrong in terminology, anyway, there are many rules that make programmer's life easier, described in the literature from the old good "How to write unmaintainable code" to "The Art of Readable Code".
And I hope there are a lot of recent books on this subject I did not
track and read yet.
Also not really a justification for "shortest block first". Wanting
some elaboration on that. What's the value in it?
Given that for-else is an excellent, if rarely-used, construct, I
would say that, *at least*, it is worth setting aside this rule for
that particular situation. It is also generally worth using fewer
commas than I just did. Take my advice with a grain of salt.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Python is awesome because it's semantic is clear for the majority, but there are places
that look odd. In case of "for", "else" looks logically tied with "for" clause, but
actually it is not. It's tied with "break" statement and I overlooked that even after
re-reading the language reference. If "else" was named like "never_broken_loop" or
"nobreak", the semantic would be perfectly clear. But, what's done is done.
Smallest code blocks first may be a more modern invention.
Some would argue for a rule related to efficiency of execution. When you
have multiple blocks as in an if-else or case statement with multiple choices, that you order the most common cases first. Those shorten
execution more often than the rarer cases especially the ones that should never happen.
On 2022-10-09 05:37:59 +0100, Axy via Python-list wrote:
Actually the reason I never used "else" was the violation of the rule
of beauty "shortest block first".
That's a weird rule.
I can see justifications for "most common case first" and "most special
case first", but ordering the cases in an if/elif/else statement by
length seems like ordering books by color: It may be pretty, but it
doesn't make them easy to find.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
--
https://mail.python.org/mailman/listinfo/python-list
On Mon, 10 Oct 2022 at 03:22, Avi Gross <avi.e.gross@gmail.com> wrote:
Smallest code blocks first may be a more modern invention.
Some would argue for a rule related to efficiency of execution. When you have multiple blocks as in an if-else or case statement with multiple choices, that you order the most common cases first. Those shorten execution more often than the rarer cases especially the ones that should never happen.
Seems fairly dubious and full of special-cases. If you want to follow
that rule, it should be easy enough to still permit for-else clauses.
It's an extremely weak argument against for-else.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Chris, I was not arguing that at all.
Since many languages allow placing multiple statements on one line or spreading one over many lines, it seems that the number of lines in code
can be adjusted.
If I have a line like:
Alpha, beta, gamma, delta = 1, 2, 3, 4
Could that be rewritten as 4 or more lines?
Smallest code blocks first may be a more modern invention.
Some would argue for a rule related to efficiency of execution. When you
have multiple blocks as in an if-else or case statement with multiple choices, that you order the most common cases first. Those shorten
execution more often than the rarer cases especially the ones that should never happen.
So not a rule but realistically not always a bad idea to write code in a
way that draws the attention of readers along the main path of execution
and perhaps not showing all the checking for odd cases first.
I have seen programmers who have taken an elegant pipeline I have built
apart and made it into many lines of code reassignment the value of each
step to the same or different variables and other ways of lengthening or obscuring my intent.
So although size may matter, so can sighs.
On Mon, 10 Oct 2022 at 03:46, Avi Gross <avi.e.gross@gmail.com> wrote:
Chris, I was not arguing that at all.
Maybe not intentionally, but you did lend a lot of weight to that argument
:)
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
On 2022-10-09 12:34:22 -0400, Avi Gross wrote:
I have seen programmers who have taken an elegant pipeline I have built apart and made it into many lines of code reassignment the value of each step to the same or different variables and other ways of lengthening or obscuring my intent.
I have certainly done that (not with your code, AFAIK). The problem with those beautiful one-liners is that they are really hard to debug. So if
I can't convince myself that they are correct just by reading them I
have to split them over multiple lines so I can add breakpoints or log messages. Of course I could put it together again afterwards, but I
would argue that if I didn't understand it the first time it's probably better to leave it in its more verbose and debuggable state.
Of course I have also done the opposite: Taken some messy and
complicated code and simplified it into a simple generator expression.
In fact I would say that I code tends to be shorter after I fixed a bug
than before.
So although size may matter, so can sighs.
:-)
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
--
https://mail.python.org/mailman/listinfo/python-list
and of course no pipelines.
"shortest block first"
On 2022-10-09 12:18:09 -0400, Avi Gross wrote:
Smallest code blocks first may be a more modern invention.
Some would argue for a rule related to efficiency of execution. When you
have multiple blocks as in an if-else or case statement with multiple
choices, that you order the most common cases first. Those shorten
execution more often than the rarer cases especially the ones that should
never happen.
Those of us who started programming on 8 bit homecomputers of course
have efficiency always at the back of their heads, but I find this
So not a rule but realistically not always a bad idea to write code in a
way that draws the attention of readers along the main path of execution
and perhaps not showing all the checking for odd cases first.
much more important. Putting the main path first makes it easier to understand what the code is supposed to do normally. All those pesky exceptions are in the "small print" below.
There is of course the opposite view that you should just get all of the confounding factors out of the way first, so that the default is also
the common case. I also do that sometimes, but then I don't hide this in
in an else: clause but do something like this:
for item in whatever:
if not_this_one(item):
continue
if neither_this_one(item):
continue
if cant_continue(item):
break
if oopsie():
raise SomeError()
do_something_with(item)
and_some_more(item)
we_are_done(item)
which shows visually what the main purpose of the loop (or function or
other block) is.
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list
<python-list@python.org> wrote:
"shortest block first"
Have never heard this advice before. Kind-of rankled with me, as it did
for others.
Enquiring minds want to know... Played Duck, duck, go on this: zero hits amongst a pile of similar phrases - turns-out there's an algorithm with
a similar name, but not related, and an electronics approach (way too
'low' a level for translation to us though).
Tried prefixing with "program" but no such advice to programmers or program[me] designers.
Tried prefixing with "python", but equal lack of joy.
Would OP please quote source?
On 2022-10-10 00:40, dn wrote:
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list
<python-list@python.org> wrote:
"shortest block first"
Have never heard this advice before. Kind-of rankled with me, as it did
for others.
Enquiring minds want to know... Played Duck, duck, go on this: zero hits amongst a pile of similar phrases - turns-out there's an algorithm with
a similar name, but not related, and an electronics approach (way too
'low' a level for translation to us though).
Tried prefixing with "program" but no such advice to programmers or program[me] designers.
Tried prefixing with "python", but equal lack of joy.
Would OP please quote source?
[snip]
After a few minutes searching I found this:
https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/CodingGuidelines/CglPhp/PhpFileFormatting/PhpSyntaxFormatting.html
"""It is recommended to create conditions so that the shortest block of
code goes first."""
On 2022-10-10 00:40, dn wrote:
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list[snip]
<python-list@python.org> wrote:
"shortest block first"
Have never heard this advice before. Kind-of rankled with me, as it did
for others.
Enquiring minds want to know... Played Duck, duck, go on this: zero hits
amongst a pile of similar phrases - turns-out there's an algorithm with
a similar name, but not related, and an electronics approach (way too
'low' a level for translation to us though).
Tried prefixing with "program" but no such advice to programmers or
program[me] designers.
Tried prefixing with "python", but equal lack of joy.
Would OP please quote source?
After a few minutes searching I found this:
https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/CodingGuidelines/CglPhp/PhpFileFormatting/PhpSyntaxFormatting.html
"""It is recommended to create conditions so that the shortest block of
code goes first."""
and of course no pipelines.
"The only place I could find it was a PHP style guide"?Which is more disparaging: "I couldn't find anyone suggesting this" or
ChrisA
"shortest block first"
On 2022-10-09 12:18:09 -0400, Avi Gross wrote:
Smallest code blocks first may be a more modern invention.
Some would argue for a rule related to efficiency of execution. When you
have multiple blocks as in an if-else or case statement with multiple
choices, that you order the most common cases first. Those shorten
execution more often than the rarer cases especially the ones that should
never happen.
Those of us who started programming on 8 bit homecomputers of course
have efficiency always at the back of their heads, but I find this
So not a rule but realistically not always a bad idea to write code in a
way that draws the attention of readers along the main path of execution
and perhaps not showing all the checking for odd cases first.
much more important. Putting the main path first makes it easier to understand what the code is supposed to do normally. All those pesky exceptions are in the "small print" below.
There is of course the opposite view that you should just get all of the confounding factors out of the way first, so that the default is also
the common case. I also do that sometimes, but then I don't hide this in
in an else: clause but do something like this:
for item in whatever:
if not_this_one(item):
continue
if neither_this_one(item):
continue
if cant_continue(item):
break
if oopsie():
raise SomeError()
do_something_with(item)
and_some_more(item)
we_are_done(item)
which shows visually what the main purpose of the loop (or function or
other block) is.
Which is more disparaging: "I couldn't find anyone suggesting this" or "The only place I could find it was a PHP style guide"?
ChrisA
Chris,
If someone says they heard something from their own personal guru, people often do not feel threatened or argue. I often am told nutrition or medical or other advice that I simply ignore especially if it is about exotic herbs to use or weird ideas like homeopathy or that I should use language X
because it is the only way to a haven or heaven or whatever.
What we had here was someone suggesting their advice was WELL-KNOWN followed by lots of people sputtering about not having heard of it. I actually think the advice would be reasonable in many circumstances as long as it did not conflict with dozens of goals I find more compelling but which vary on a
case by case basis such as whether I am prototyping something I will use once, ...
I have studied PHP but have never felt a need to use it and arguably the roles it has played are often done commonly by other programs or methods.
So in my view, the objection is not about PHP but about uniqueness. If the author of one Python textbook and no others, suggest that your code should declare all imports in alphabetical order then declare all functions in alphabetical order, they can not only safely be ignored, but perhaps not taken seriously as imports sometimes need to be done carefully if something needs something else and if a language needs functions to be defined before another function body calls them, ...
But some people seem to miss a point we have discussed. The odd clauses like ELSE after a loop (and quite a few variants in similar and different cases) often provide guarantees such as making sure a file opened is closed.
Are these things out of the way? Yes, but so what? I see things as a whole not as just a single screen shot. If a loop has several optional clauses lie we are discussing and you know they are normally near the end, then look for them where they are.
I know some languages, JavaScript being an example, may have things you
might consider odd such as promoting some things like function definitions found further in your code to near the top so you can use a function that is not defined till later even without something like a forward declaration
used in other languages.
I am now going to stop replying on this topic as I have said way too much
and am not in particular disagreement if we are discussing preferences and ideas. I see TOOLS here, not religion. Use what works or that has to be used for a task but don't take any one thing too seriously.
heaven or whatever."The only place I could find it was a PHP style guide"?Which is more disparaging: "I couldn't find anyone suggesting this"
or
ChrisA
Chris,
If someone says they heard something from their own personal guru,
people often do not feel threatened or argue. I often am told
nutrition or medical or other advice that I simply ignore especially
if it is about exotic herbs to use or weird ideas like homeopathy or
that I should use language X because it is the only way to a haven or
What we had here was someone suggesting their advice was WELL-KNOWN
followed by lots of people sputtering about not having heard of it. I actually think the advice would be reasonable in many circumstances as
long as it did not conflict with dozens of goals I find more
compelling but which vary on a case by case basis such as whether I am prototyping something I will use once, ...
I have studied PHP but have never felt a need to use it and arguablymethods.
the roles it has played are often done commonly by other programs or
So in my view, the objection is not about PHP but about uniqueness. If
the author of one Python textbook and no others, suggest that your
code should declare all imports in alphabetical order then declare all functions in alphabetical order, they can not only safely be ignored,
but perhaps not taken seriously as imports sometimes need to be done carefully if something needs something else and if a language needs
functions to be defined before another function body calls them, ...
But some people seem to miss a point we have discussed. The oddopened is closed.
clauses like ELSE after a loop (and quite a few variants in similar
and different cases) often provide guarantees such as making sure a file
Are these things out of the way? Yes, but so what? I see things as a
whole not as just a single screen shot. If a loop has several optional clauses lie we are discussing and you know they are normally near the
end, then look for them where they are.
I know some languages, JavaScript being an example, may have things
you might consider odd such as promoting some things like function definitions found further in your code to near the top so you can use
a function that is not defined till later even without something like
a forward declaration used in other languages.
I am now going to stop replying on this topic as I have said way tooseriously.
much and am not in particular disagreement if we are discussing
preferences and ideas. I see TOOLS here, not religion. Use what works
or that has to be used for a task but don't take any one thing too
Am Sun, Oct 09, 2022 at 09:58:14AM +0000 schrieb Stefan Ram:
I often follow this rule. For me, it's about readability. Compare:... ad infinitum ....
if not open( disk ):
error( "Can't open disk" )
else:
printf( "now imagine there's some larger block here" )
Should this not be
if not open( disk ):
error( "Can't open disk" )
else:
do_lots_of_things_with(disk)
as for readability ?
Should this not be
if not open( disk ):
error( "Can't open disk" )
else:
do_lots_of_things_with(disk)
as for readability ?
I often follow this rule. For me, it's about readability. Compare:... ad infinitum ....
if not open( disk ):
error( "Can't open disk" )
else:
printf( "now imagine there's some larger block here" )
Axy 在 2022年10月8日 星期上11:39:44 [UTC+8] 的信中寫道:
However, the compiler does not complain.Hi there,The else is always coming with the break, not the for.
this is rather a philosophical question, but I assume I miss something.
I don't remember I ever used else clause for years I was with python and
my expectation was it executed only if the the main body was never run.
Ha-ha! I was caught by this mental trap.
So, seriously, why they needed else if the following pieces produce same
result? Does anyone know or remember their motivation?
Just curious.
Axy.
print('--- with else')
for i in [1,2,3]:
print(i)
else:
print(4)
for i in []:
print(i)
else:
print(5)
print('--- without else')
for i in [1,2,3]:
print(i)
print(4)
for i in []:
print(i)
print(5)
There are [for ...], [for...break...], and[for...break...else],
but the [for...else] is insane.Not in Python.
Not sure what you mean, but a for-else without a break is quite
useless. What exactly ARE you arguing here?
The else is associated with the break to the exact extent that one is essential to the other's value.
On 09/10/2022 03:33, Jach Feng wrote:Sure, the compiler will not complain even in a IOCCC contest:-)
The else is always coming with the break, not the for.However, the compiler does not complain.
The confusion is always in human mind.but the [for...else] is insane.Not in Python.
The else is always coming with the break, not the for.However, the compiler does not complain.
There are [for ...], [for...break...], and[for...break...else],
That's implied and contradicts Zen of Python, I think. If "else" came
with "break" there had to be a strong indication of that, namely
indentation, as it takes place for all other statements with their
clauses. However, there's no such an explicit connection between "break"
and "else". That's the point.
Well, sorry for this addition to the discussion which went weird way. I should had to be cautious mentioning particular coding style, that's a totally different subject, actually. Let's close it at last.
but the [for...else] is insane.Not in Python.
Am Sun, Oct 09, 2022 at 09:58:14AM +0000 schrieb Stefan Ram:
I often follow this rule. For me, it's about readability. Compare:
if not open( disk ):... ad infinitum ....
error( "Can't open disk" )
else:
printf( "now imagine there's some larger block here" )
Should this not be
if not open( disk ):
error( "Can't open disk" )
else:
do_lots_of_things_with(disk)
as for readability ?
Or even
if not open( disk ):
error( "Can't open disk" )
return what_needs_to_be_returned
do_lots_of_things_with(disk)
The latter version may need some code reorganization, though.
On Mon, 10 Oct 2022 at 21:57, Axy via Python-listOh, I'm really sorry. My apologies.
<python-list@python.org> wrote:
Here's where the "rest of this thread" started:
Not sure what you mean, but a for-else without a break is quiteI'm not arguing. That was just for the record, how things are done in
useless. What exactly ARE you arguing here?
The else is associated with the break to the exact extent that one is
essential to the other's value.
Python. Basically, I simply asked a question and got a definite answer
and clear understanding shortly, in a few replies. All the rest of this
thread looks irrelevant to me, it's about coding style and probably
should be continued under a different title, but I'm not interested to
participate in it.
Actually the reason I never used "else" was the violation of the rule ofYou disparaged a feature on the basis of a style rule that few of us
beauty "shortest block first".
had heard of or agree with.
We all agree that coding style is
important; none of us would see block length as a reason to avoid
using an else clause on a for loop.
Not sure what you mean, but a for-else without a break is quite
useless. What exactly ARE you arguing here?
The else is associated with the break to the exact extent that one is essential to the other's value.
I'm not arguing. That was just for the record, how things are done in
Python. Basically, I simply asked a question and got a definite answer
and clear understanding shortly, in a few replies. All the rest of this thread looks irrelevant to me, it's about coding style and probably
should be continued under a different title, but I'm not interested to participate in it.
Actually the reason I never used "else" was the violation of the rule of beauty "shortest block first".
On 10/10/2022 12:24, Chris Angelico wrote:
On Mon, 10 Oct 2022 at 21:57, Axy via Python-list
<python-list@python.org> wrote:
Here's where the "rest of this thread" started:
Not sure what you mean, but a for-else without a break is quiteI'm not arguing. That was just for the record, how things are done in
useless. What exactly ARE you arguing here?
The else is associated with the break to the exact extent that one is
essential to the other's value.
Python. Basically, I simply asked a question and got a definite answer
and clear understanding shortly, in a few replies. All the rest of this
thread looks irrelevant to me, it's about coding style and probably
should be continued under a different title, but I'm not interested to
participate in it.
Oh, I'm really sorry. My apologies.Actually the reason I never used "else" was the violation of the rule of >> beauty "shortest block first".You disparaged a feature on the basis of a style rule that few of us
had heard of or agree with.
We all agree that coding style is
important; none of us would see block length as a reason to avoid
using an else clause on a for loop.
As I understand from the above there must be a committee that delegates
a speaker? Where to read rules? How to participate? There's something
beyond this list I'm not aware of yet?
On Mon, 10 Oct 2022 at 11:52, MRAB <python@mrabarnett.plus.com> wrote:
On 2022-10-10 00:40, dn wrote:
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list
<python-list@python.org> wrote:
"shortest block first"
Have never heard this advice before. Kind-of rankled with me, as it did
for others.
On 10/7/22 21:32, Axy wrote:
So, seriously, why they needed else if the following pieces produce same result? Does anyone know or remember their motivation?
In real scenarios there would be more logic in the for block that would
meet a condition and break out of the loop. If the condition is never
met, the else block runs. To steal from w3schools:
fruits = ["apple", "peach", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
else:
print("Yes we got no bananas")
try:
open(disk)
except:
error(“Can’t open disk”)
lots of things
I often follow this rule. For me, it's about readability. Compare:... ad infinitum ....
if not open( disk ):
error( "Can't open disk" )
else:
printf( "now imagine there's some larger block here" )
On 10/7/22 21:32, Axy wrote:
So, seriously, why they needed else if the following pieces produce same result? Does anyone know or remember their motivation?
In real scenarios there would be more logic in the for block that would
meet a condition and break out of the loop. If the condition is never
met, the else block runs. To steal from w3schools:
fruits = ["apple", "peach", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
else:
print("Yes we got no bananas")
On Sat, Oct 8, 2022 at 5:35 PM rbowman <bowman@montana.com> wrote:
On 10/7/22 21:32, Axy wrote:
So, seriously, why they needed else if the following pieces produce same >> > result? Does anyone know or remember their motivation?
In real scenarios there would be more logic in the for block that would
meet a condition and break out of the loop. If the condition is never
met, the else block runs. To steal from w3schools:
fruits = ["apple", "peach", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
else:
print("Yes we got no bananas")
I wonder if for/else could have been less confusing if it was referred to
as for-break-else and if the else clause was only valid syntax if the for loop actually contained a break statement in the first place.
Core developer Raymond Hettinger explains the history starting at 15:40 https://www.youtube.com/watch?v=OSGv2VnC0go
(which I found on stackoverflow https://stackoverflow.com/questions/9979970/why-does-python-use-else-after-for-and-while-loops )
TL:DR
The “else” is a historical artificial from the way developers thought during the transition from unstructured (i.e. “GOTO”) programming to structured programming. Since we all do structured now, it seems odd.
From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Calvin Spealman <cspealma@redhat.com>
Date: Monday, October 10, 2022 at 10:38 AM
To: python-list@python.org <python-list@python.org>
Subject: Re: for -- else: what was the motivation?
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***
On Sat, Oct 8, 2022 at 5:35 PM rbowman <bowman@montana.com> wrote:
On 10/7/22 21:32, Axy wrote:I wonder if for/else could have been less confusing if it was referred to
So, seriously, why they needed else if the following pieces produce same >>> result? Does anyone know or remember their motivation?In real scenarios there would be more logic in the for block that would
meet a condition and break out of the loop. If the condition is never
met, the else block runs. To steal from w3schools:
fruits = ["apple", "peach", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
else:
print("Yes we got no bananas")
as for-break-else and if the else clause was only valid syntax if the for loop actually contained a break statement in the first place.
Yes, I'm aware that code readability becomes irrelevant for
short-duration projects. Beside the point. I'm wondering how important
it really is to have the shortest block first.
Given that for-else is an excellent, if rarely-used, construct
I've followed that advice for several decades. I find it much easier
to read code that's organized that way -- particularly when the
difference in block sizes is large (e.g. the first block is one line,
and the second is a a hundred).
Also not really a justification for "shortest block first". Wanting
some elaboration on that. What's the value in it?
Well, the value is productivity. No need to save puzzles "what this
hanging else belongs to?"
Code small things first and return early, same
as taking a test: do easy and quick things first and boring and
difficult ones later.
On 10/10/2022 15:52, Weatherby,Gerard wrote:
I wonder if for/else could have been less confusing if it was
referred to
as for-break-else and if the else clause was only valid syntax if the
for
loop actually contained a break statement in the first place.
Sounds reasonable. It would be something alike UnboundLocalError when
a local variable referenced before assignment. If they won't remove
"else" completely in far future, that checking really worths
implementing now.
On 10/10/2022 05.56, Peter J. Holzer wrote:
On 2022-10-09 12:18:09 -0400, Avi Gross wrote:
Some would argue for a rule related to efficiency of execution. When you have multiple blocks as in an if-else or case statement with multiple choices, that you order the most common cases first. Those shorten execution more often than the rarer cases especially the ones that should never happen.
Those of us who started programming on 8 bit homecomputers of course
have efficiency always at the back of their heads, but I find this
... for mainframes just as much as micro-computers!
Regarding execution-efficiencies, I'm sure @Avi knows better than I: It
seems likely that Python, as an interpreted language, will create 'blocks'
of its virtual-machine code in the same order as they appear in the Python-source. However, aren't there optimising compilers which do something intelligent with the equivalent clauses/suites in other languages?
Regardless, is a Jump-instruction which transfers else-control to a block five machine-instructions 'down', any less efficient than a jump which spans 50-instructions?
There is of course the opposite view that you should just get all of the confounding factors out of the way first, so that the default is also
the common case. I also do that sometimes, but then I don't hide this in
in an else: clause but do something like this:
for item in whatever:
if not_this_one(item):
continue
if neither_this_one(item):
continue
if cant_continue(item):
break
if oopsie():
raise SomeError()
do_something_with(item)
and_some_more(item)
we_are_done(item)
which shows visually what the main purpose of the loop (or function or other block) is.
Nicely stated!
NB I've seen sufficient of @Peter's posts to know that this was never (even implied to be) intended as a snippet for all occasions!
It also illustrates why such is less readable: because we have to scan four if-statements before we can 'see' the purpose of the loop. My 'itch' would
be to extract this code 'out' to a function - that way the name will convey the somewhat-obscured purpose of the loop.
Alternately, reduce the 'distractions':-
try:
for item in whatever:
inspect_the_data( item )
do_something_with(item)
and_some_more(item)
we_are_done(item)
except SomeError:
...
except CustomBreakException:
... ?pass? # same effect as break
by 'hiding' in:
def inspect_the_data( item ):
if not_this_one(item):
continue
In some ways, (IMHO) there are reasons to feel disquiet over this style of coding. Learning "Modular Programming", and slightly-later "Structured Programming", when they were still new (?fresh, ?exciting), we were inculcated with the 'one way in, one way out' philosophy-of-correctness.
This applied to "blocks" of code (per "module"), as well as formal units, eg functions.
On 2022-10-09 15:32:13 -0400, Avi Gross wrote:
and of course no pipelines.
Since you've now used that term repeatedly: What is a pipeline in
Python?
pylint, at least, provides a warning:
fe.py:4:0: W0120: Else clause on loop without a break statement (useless-else-on-loop)
On 10/10/2022 15:52, Weatherby,Gerard wrote:
I wonder if for/else could have been less confusing if it was
referred to
as for-break-else and if the else clause was only valid syntax if the
for
loop actually contained a break statement in the first place.
Sounds reasonable. It would be something alike UnboundLocalError when
a local variable referenced before assignment. If they won't remove
"else" completely in far future, that checking really worths
implementing now.
[This is an answer for Peter and can easily be skipped by those who know or have no wish to.]
Strictly speaking Peter, the word "pipe" may not mean quite something in Python but other concepts like chaining may be better.
The original use of the word I am used to was at the UNIX shell level where an in-core data structure called a pipe was used
If you have an object with some method you can call on it (or in some cases
a normal function call) that returns another (or the same) object, then you can write code like:
This.that.other
On 10/10/2022 15:52, Weatherby,Gerard wrote:
I wonder if for/else could have been less confusing if it was
referred to as for-break-else and if the else clause was only valid
syntax if the for loop actually contained a break statement in the
first place.
Sounds reasonable. It would be something alike UnboundLocalError when
a local variable referenced before assignment. If they won't remove
"else" completely in far future, that checking really worths
implementing now.
Chris Angelico wrote:
Yes, I'm aware that code readability becomes irrelevant for
short-duration projects. Beside the point. I'm wondering how important
it really is to have the shortest block first.
I usually put the most expected / frequent / not negated block first if the whole if/else statement is not "too long". Sometimes whatever you want to do becomes pointless if a certain conditions is not met, in which case I do an early break or return and have no else block at all.
Given that for-else is an excellent, if rarely-used, construct
I knew it existed but coming from C I never thought to exploit it. I know I wrote loops like this:
found = None
while not found:
found = search(something)
if found:
break
if not found:
complain()
Need to look into using "else" in these cases.
[This is an answer for Peter and can easily be skipped by those who know or have no wish to.]
Strictly speaking Peter, the word "pipe" may not mean quite something in Python but other concepts like chaining may be better.
The original use of the word I am used to was at the UNIX shell level where an in-core data structure called a pipe was used to connect the output of
one process to the inputr of another, sometimes in long chains like:
cat file1 file2 file3 | grep pattern | ... | lp
[This is an answer for Peter and can easily be skipped by those wholike:
know or have no wish to.]
Strictly speaking Peter, the word "pipe" may not mean quite something
in Python but other concepts like chaining may be better.
The original use of the word I am used to was at the UNIX shell level
where an in-core data structure called a pipe was used to connect the
output of one process to the inputr of another, sometimes in long chains
cat file1 file2 file3 | grep pattern | ... | lp
I won't reply to everything Dave says and especially not the parts I fully agree with.languages with all kinds of ways of doing things and then zoom in on how to do it in the current language be it Python or R or JavaScript and so on. Yes, I am in some sense focused but also open, just as in Human languages I may mostly be thinking in
I think in many situations in life there is no ONE way to do things so most advice is heuristic at best and many exceptions may exist depending on your chosen approach. As such, I do not really think in PYTHON when writing code but an amalgam of many
But is that native python or some extension where "|" has been modified to mean something other than a form of OR in some places?
What module do you need to load to make that happen?
Chris, a short(er) answer to your addition below.
I did not at first share your perception but maybe do now. If the argument was that ELSE and other constructs like FINALLY or CATCH are horrible
because they follow other code and important things should be first, that is a silly argument.
So, seriously, why they needed else if the following pieces produce same >result? Does anyone know or remember their motivation?
So, seriously, why they needed else if the following pieces produce same >result? Does anyone know or remember their motivation?
I would not use tabs in source code as they are not
displayed in the same way everywhere.
Functions also come at a cost. From the Web:^^^^^^^^^^^^
Axy wrote:
Also not really a justification for "shortest block first". Wanting
some elaboration on that. What's the value in it?
Well, the value is productivity. No need to save puzzles "what this hanging else belongs to?"
If you find yourself asking that question, the if-block is probably too long to
begin with.
^^^^^^^^^^^^Code small things first and return early, same
as taking a test: do easy and quick things first and boring and
difficult ones later.
Yes, but in that case you have a very long indented "else" block,
On 2022-10-10, Chris Angelico <rosuav@gmail.com> wrote:
On Mon, 10 Oct 2022 at 11:52, MRAB <python@mrabarnett.plus.com> wrote:
On 2022-10-10 00:40, dn wrote:
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list
<python-list@python.org> wrote:
"shortest block first"
Have never heard this advice before. Kind-of rankled with me, as it did >>>> for others.
I've followed that advice for several decades. I find it much easier
to read code that's organized that way -- particularly when the
difference in block sizes is large (e.g. the first block is one line,
and the second is a a hundred).
As did I.
tree = ET.parse(lfile)
for child in tree.getroot():
if child.tag == 'server':
break
else:
raise ValueError(f"server tag not found in {lfile}")
I think there are other places I could be using it, but honestly I tend to forget it’s available.
From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Stefan Ram <ram@zedat.fu-berlin.de>
Date: Wednesday, October 12, 2022 at 2:22 PM
To: python-list@python.org <python-list@python.org>
Subject: Re: for -- else: what was the motivation?
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***
Axy <axy@declassed.art> writes:
So, seriously, why they needed else if the following pieces produce sameJust wrote code wherein I used "else"! This:
result? Does anyone know or remember their motivation?
import locale
for name in( 'de', 'de_DE', 'deu_deu', 'deu', 'German', 'Deutsch' ):
try: locale.setlocale( locale.LC_ALL, name ); break
except locale.Error: pass
else: print( "Programm kann deutsche Schreibweise nicht einrichten." )
.
-- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iyDac-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEdR04mSQ5Ln0OA1ETUNloyH24iY9meNHVdixLgWRYL8$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iyDac-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEdR04mSQ5Ln0OA1ETUNloyH24iY9meNHVdixLgWRYL8$>
I too have occasionally used for ... else. It does have its uses. But
oh, how I wish it had been called something else more meaningful,
whether 'nobreak' or whatever.
I too have occasionally used for ... else. It does have its uses. But
oh, how I wish it had been called something else more meaningful,
whether 'nobreak' or whatever. It used to really confuse me. Now I've
As did I.
tree = ET.parse(lfile)
for child in tree.getroot():
if child.tag == 'server':
break
else:
raise ValueError(f"server tag not found in {lfile}")
I think there are other places I could be using it, but honestly I tend to forget it’s available.
From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org>
on behalf of Stefan Ram <ram@zedat.fu-berlin.de>
Date: Wednesday, October 12, 2022 at 2:22 PM
To: python-list@python.org <python-list@python.org>
Subject: Re: for -- else: what was the motivation?
*** Attention: This is an external email. Use caution responding,
opening attachments or clicking on links. ***
Axy <axy@declassed.art> writes:
So, seriously, why they needed else if the following pieces produceJust wrote code wherein I used "else"! This:
same result? Does anyone know or remember their motivation?
import locale
for name in( 'de', 'de_DE', 'deu_deu', 'deu', 'German', 'Deutsch' ):
try: locale.setlocale( locale.LC_ALL, name ); break
except locale.Error: pass
else: print( "Programm kann deutsche Schreibweise nicht einrichten." )
.
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/p ython-list__;!!Cn_UX_p3!iyDac-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEd R04mSQ5Ln0OA1ETUNloyH24iY9meNHVdixLgWRYL8$<https://urldefense.com/v3/_ _https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iyDa c-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEdR04mSQ5Ln0OA1ETUNloyH24iY9me NHVdixLgWRYL8$>
Op 16/10/2022 om 00:50 schreef avi.e.gross@gmail.com:existing programs or break older compilers/interpreters.
This has been discussed so often precisely because I swear NO CHOICE of keyword would satisfy everybody! Most languages start with designated keywords and some reserve a few for later use. But then things can get frozen in place to avoid breaking
language in a fairly harmless way as no older program would likely have used features that did not exist.Some languages use techniques to extend themselves more harmlessly such as creating a singleton object that has content that can be regular data as in math.pi, or functions/methods or new ides like "Symbols" that allow all kinds of extensions to the
That might not easily solve this problem. But I wonder if reserving some kind of prefix might help, so anything like extension.0nNoBreak could be added to a loop as a final clause and be treated as a non-key keyword of sorts.
My idea would be to reserve different unicode blocks for the keywords
and the identifiers. e.g. We could reserve the mathematical alphanumeric block for keywords and all other letters and numbers for identifiers.
Doing so would allow extenting the keywords without breaking programs
that already use that combination as an identifier.
Python could slowly transition in this direction by first allowing the current keywords to be in this block. Every new keyword would only be in
that unicode block. If would then be possible to write python code with
this convention but it wouldn't be obligatory. After some time the
python developers could decide to make it obligatory.
I doubt this will idea will get from the ground, but I think it would
allow for a smoother transition into new concepts, as it is no longer a strugle searching for a keyword that will break as little programs as possible.
This has been discussed so often precisely because I swear NO CHOICE of keyword would satisfy everybody! Most languages start with designated keywords and some reserve a few for later use. But then things can get frozen in place to avoid breakingexisting programs or break older compilers/interpreters.
Some languages use techniques to extend themselves more harmlessly such as creating a singleton object that has content that can be regular data as in math.pi, or functions/methods or new ides like "Symbols" that allow all kinds of extensions to thelanguage in a fairly harmless way as no older program would likely have used features that did not exist.
That might not easily solve this problem. But I wonder if reserving some kind of prefix might help, so anything like extension.0nNoBreak could be added to a loop as a final clause and be treated as a non-key keyword of sorts.
On Sun, 16 Oct 2022 at 21:19, Antoon Pardon<antoon.pardon@vub.be> wrote:
My idea would be to reserve different unicode blocks for the keywordsPython currently defines identifiers as follows: https://docs.python.org/3/reference/lexical_analysis.html#identifiers
and the identifiers. e.g. We could reserve the mathematical alphanumeric
block for keywords and all other letters and numbers for identifiers.
Doing so would allow extenting the keywords without breaking programs
that already use that combination as an identifier.
Briefly, what it means is that (aside from some backward compatibility special cases) an identifier contains letters, numbers, and connector punctuation, and must not start with a number. It's not by blocks,
it's by types.
It's way WAY too late to change what's allowed for identifiers, as you
will potentially be breaking programs that use the current rules.
Python could slowly transition in this direction by first allowing theObligatory??? Please explain how you intend to convince the entire
current keywords to be in this block. Every new keyword would only be in
that unicode block. If would then be possible to write python code with
this convention but it wouldn't be obligatory. After some time the
python developers could decide to make it obligatory.
world that non-ASCII code is an acceptable requirement. Explain to me
how you're going to go to every text editor and ensure that it
supports easy entry of Python keywords that aren't ASCII. And please
explain how this is even better.
I doubt this will idea will get from the ground, but I think it wouldYeah it won't. Good luck though.
allow for a smoother transition into new concepts, as it is no longer a
strugle searching for a keyword that will break as little programs as
possible.
Op 16/10/2022 om 13:03 schreef Chris Angelico:
On Sun, 16 Oct 2022 at 21:19, Antoon Pardon<antoon.pardon@vub.be> wrote:
My idea would be to reserve different unicode blocks for the keywordsPython currently defines identifiers as follows: https://docs.python.org/3/reference/lexical_analysis.html#identifiers
and the identifiers. e.g. We could reserve the mathematical alphanumeric >> block for keywords and all other letters and numbers for identifiers.
Doing so would allow extenting the keywords without breaking programs
that already use that combination as an identifier.
Briefly, what it means is that (aside from some backward compatibility special cases) an identifier contains letters, numbers, and connector punctuation, and must not start with a number. It's not by blocks,
it's by types.
It's way WAY too late to change what's allowed for identifiers, as you
will potentially be breaking programs that use the current rules.
So? Python has broken backward compatibility before. The cost could
be acceptable. How many programs do you estimated use the mathematical alphanumeric block for an identifier at this moment?
Why would I need good luck? I expressed an idea and you didn't like it.
That won't affect my life in a meaningful way.
Op 16/10/2022 om 00:50 schreef avi.e.gross@gmail.com:
This has been discussed so often precisely because I swear NO CHOICE ofkeyword would satisfy everybody! Most languages start with designated keywords and some reserve a few for later use. But then things can get
frozen in place to avoid breaking existing programs or break older compilers/interpreters.
Some languages use techniques to extend themselves more harmlessly suchas creating a singleton object that has content that can be regular data as in math.pi, or functions/methods or new ides like "Symbols" that allow all kinds of extensions to the language in a fairly harmless way as no older program would likely have used features that did not exist.
That might not easily solve this problem. But I wonder if reserving somekind of prefix might help, so anything like extension.0nNoBreak could be added to a loop as a final clause and be treated as a non-key keyword of sorts.
My idea would be to reserve different unicode blocks for the keywords
and the identifiers. e.g. We could reserve the mathematical alphanumeric block for keywords and all other letters and numbers for identifiers.
Doing so would allow extenting the keywords without breaking programs
that already use that combination as an identifier.
Python could slowly transition in this direction by first allowing the current keywords to be in this block. Every new keyword would only be in
that unicode block. If would then be possible to write python code with
this convention but it wouldn't be obligatory. After some time the
python developers could decide to make it obligatory.
I doubt this will idea will get from the ground, but I think it would
allow for a smoother transition into new concepts, as it is no longer a strugle searching for a keyword that will break as little programs as possible.
--
Antoon Pardon.
--
https://mail.python.org/mailman/listinfo/python-list
On Sun, 16 Oct 2022 at 22:47, Antoon Pardon<antoon.pardon@vub.be> wrote:
Why would I need good luck? I expressed an idea and you didn't like it.Well, with that attitude, it's not going to affect anyone else's life
That won't affect my life in a meaningful way.
either, so go ahead, carry on.
Op 16/10/2022 om 00:50 schreef avi.e.gross@gmail.com:
That might not easily solve this problem. But I wonder if reserving
some kind of prefix might help, so anything like extension.0nNoBreak
could be added to a loop as a final clause and be treated as a
non-key keyword of sorts.
My idea would be to reserve different unicode blocks for the keywords and
the identifiers. e.g. We could reserve the mathematical alphanumeric block for keywords and all other letters and numbers for identifiers. Doing so would allow extenting the keywords without breaking programs that already
use that combination as an identifier.
Op 16/10/2022 om 17:05 schreef Chris Angelico:
On Sun, 16 Oct 2022 at 22:47, Antoon Pardon<antoon.pardon@vub.be> wrote:
Why would I need good luck? I expressed an idea and you didn't like it.Well, with that attitude, it's not going to affect anyone else's life either, so go ahead, carry on.
That won't affect my life in a meaningful way.
What attitude? I just floated a little idea. It was not meant/expected to affect anyone else's life. So why do you react as if it was?
This has been discussed so often precisely because I swear NO CHOICE of keyword would satisfy everybody! Most languages start with designated keywords and some reserve a few for later use. But then things can get frozen in place to avoid breakingexisting programs or break older compilers/interpreters.
Some languages use techniques to extend themselves more harmlessly such as creating a singleton object that has content that can be regular data as in math.pi, or functions/methods or new ides like "Symbols" that allow all kinds of extensions to thelanguage in a fairly harmless way as no older program would likely have used features that did not exist.
That might not easily solve this problem. But I wonder if reserving some kind of prefix might help, so anything like extension.0nNoBreak could be added to a loop as a final clause and be treated as a non-key keyword of sorts.
-----Original Message-----nobreak", it confuses me a bit less.
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Rob Cliffe via Python-list
Sent: Wednesday, October 12, 2022 6:20 PM
To: python-list@python.org
Subject: Re: for -- else: what was the motivation?
I too have occasionally used for ... else. It does have its uses. But oh, how I wish it had been called something else more meaningful, whether 'nobreak' or whatever. It used to really confuse me. Now I've learned to mentally replace "else" by "if
Rob Cliffe
On 12/10/2022 22:11, Weatherby,Gerard wrote:
As did I.
tree = ET.parse(lfile)
for child in tree.getroot():
if child.tag == 'server':
break
else:
raise ValueError(f"server tag not found in {lfile}")
I think there are other places I could be using it, but honestly I tend to forget it’s available.
From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org>
on behalf of Stefan Ram <ram@zedat.fu-berlin.de>
Date: Wednesday, October 12, 2022 at 2:22 PM
To: python-list@python.org <python-list@python.org>
Subject: Re: for -- else: what was the motivation?
*** Attention: This is an external email. Use caution responding,
opening attachments or clicking on links. ***
Axy <axy@declassed.art> writes:
So, seriously, why they needed else if the following pieces produceJust wrote code wherein I used "else"! This:
same result? Does anyone know or remember their motivation?
import locale
for name in( 'de', 'de_DE', 'deu_deu', 'deu', 'German', 'Deutsch' ):
try: locale.setlocale( locale.LC_ALL, name ); break
except locale.Error: pass
else: print( "Programm kann deutsche Schreibweise nicht einrichten." )
.
On Mon, 17 Oct 2022 at 03:57, Antoon Pardon<antoon.pardon@vub.be> wrote:
You expressed an idea that you would like to see implemented in
Op 16/10/2022 om 17:05 schreef Chris Angelico:
On Sun, 16 Oct 2022 at 22:47, Antoon Pardon<antoon.pardon@vub.be> wrote: >>>> Why would I need good luck? I expressed an idea and you didn't like it. >>>> That won't affect my life in a meaningful way.What attitude? I just floated a little idea. It was not meant/expected to
Well, with that attitude, it's not going to affect anyone else's life
either, so go ahead, carry on.
affect anyone else's life. So why do you react as if it was?
Python, and part of that idea was that people would be *obliged* to
write their code using non-ASCII keywords. If that were to be
implemented, it absolutely WOULD affect many people's lives.
So if
you're saying that your idea was not meant to affect anyone else's
life, you are saying that you floated the idea fully intending for it
to be ignored, which makes me wonder why you posted it in the first
place.
Interesting idea, Anton.
I would be interested in hearing more detail on how it would work.
Although much of programming has been centered on the Latin alphabet
and especially English, that may change. I can imagine a customized
compiler or interpreter that uses key words in the local language
instead of for or while or if or else or even import.
If a region of UNICODE was set aside, would it have to be as a sort of additional ALT or shift key for anything, or just English characters
or would it be for abstract symbols that would be mapped to and from a
long list of reserved key words that may vary by locale?
On 2022-10-16 12:17:39 +0200, Antoon Pardon wrote:
Op 16/10/2022 om 00:50 schreefavi.e.gross@gmail.com:Or you could go back to the old Algol idea of underlining keywords.
That might not easily solve this problem. But I wonder if reservingMy idea would be to reserve different unicode blocks for the keywords and
some kind of prefix might help, so anything like extension.0nNoBreak
could be added to a loop as a final clause and be treated as a
non-key keyword of sorts.
the identifiers. e.g. We could reserve the mathematical alphanumeric block >> for keywords and all other letters and numbers for identifiers. Doing so
would allow extenting the keywords without breaking programs that already
use that combination as an identifier.
Both have the same problem, though: They make editing with an ordinary
text editor pretty much impossible. You need a language-aware IDE which
makes entering these characters or markups simple.
Op 16/10/2022 om 17:03 schreef Avi Gross:
Interesting idea, Anton.
I would be interested in hearing more detail on how it would work.
Although much of programming has been centered on the Latin alphabet
and especially English, that may change. I can imagine a customized
compiler or interpreter that uses key words in the local language
instead of for or while or if or else or even import.
Op 16/10/2022 om 19:01 schreef Peter J. Holzer:
On 2022-10-16 12:17:39 +0200, Antoon Pardon wrote:
Op 16/10/2022 om 00:50 schreefavi.e.gross@gmail.com:Or you could go back to the old Algol idea of underlining keywords.
That might not easily solve this problem. But I wonder if reserving some kind of prefix might help, so anything like extension.0nNoBreak could be added to a loop as a final clause and be treated as aMy idea would be to reserve different unicode blocks for the keywords and the identifiers. e.g. We could reserve the mathematical alphanumeric block
non-key keyword of sorts.
for keywords and all other letters and numbers for identifiers. Doing so would allow extenting the keywords without breaking programs that already use that combination as an identifier.
Both have the same problem, though: They make editing with an ordinary
text editor pretty much impossible. You need a language-aware IDE which makes entering these characters or markups simple.
That is not true with my idea. The editor would just need to be able
to work with unicode characters. Vim can work with 𝐝𝐞𝐟 just as it can
with def.
In vim I can also define abbreviations so that whenever I type ^Bd vim
wil insert 𝐝𝐞𝐟 for me.
On Mon, 17 Oct 2022 at 03:57, Antoon Pardon<antoon.pardon@vub.be> wrote:wrote:
Op 16/10/2022 om 17:05 schreef Chris Angelico:
On Sun, 16 Oct 2022 at 22:47, Antoon Pardon<antoon.pardon@vub.be>
You expressed an idea that you would like to see implemented inWhat attitude? I just floated a little idea. It was notWhy would I need good luck? I expressed an idea and you didn't like it. >>>> That won't affect my life in a meaningful way.Well, with that attitude, it's not going to affect anyone else's
life either, so go ahead, carry on.
meant/expected to affect anyone else's life. So why do you react as if it was?
Python, and part of that idea was that people would be *obliged* to
write their code using non-ASCII keywords. If that were to be
implemented, it absolutely WOULD affect many people's lives.
So if
you're saying that your idea was not meant to affect anyone else's
life, you are saying that you floated the idea fully intending for it
to be ignored, which makes me wonder why you posted it in the first
place.
I had another crazy thought that I AM NOT ASKING anyone to do. OK?
I had another crazy thought that I AM NOT ASKING anyone to do. OK?
My point Chris was that you can have a conversation where you are exploring and not proposing. Brainstorming, perhaps.
So my POINT (and I repeat NOT a suggestion) is that I can IMAGINE ways to
add a feature to a loop, such as an extra optional argument that is called
if the loop exits from the bottom. The code you now put in the ELSE clause might have to be in the lambda or whatever. That may not be a good fit for Python.
What may aggravate you is that lots of people keep telling you that the ELSE on a loop feature is not intuitive to many, sometimes even after it is explained.
My suggestion is you should deal with that and not take it out on others. Live and let live.
This forum may be about Python but not exclusively. I personally often enjoy hearing how some other system does something similar, such as discussions on how and whether Python should allow an underscore in static numbers given other languages do so, not always identically. We can learn from such comparisons, for good and also for bad.
But if it makes you happy, take me off this list! I have so many things I need to do and free up time for.
On Mon, 17 Oct 2022 at 10:46,<avi.e.gross@gmail.com> wrote:
My point Chris was that you can have a conversation where you are exploring >> and not proposing. Brainstorming, perhaps.And my point is that either a proposal is a serious one that can
expect serious discussion, or it isn't. Yes, I'm aware that it wasn't
you who backpedalled as soon as any criticism was posted, but your
caveat comes to the same thing - if you're trying to avoid serious
criticism, you have to not post an idea.
Op 17/10/2022 om 04:01 schreef Chris Angelico:
On Mon, 17 Oct 2022 at 10:46,<avi.e.gross@gmail.com> wrote:
My point Chris was that you can have a conversation where you are exploringAnd my point is that either a proposal is a serious one that can
and not proposing. Brainstorming, perhaps.
expect serious discussion, or it isn't. Yes, I'm aware that it wasn't
you who backpedalled as soon as any criticism was posted, but your
caveat comes to the same thing - if you're trying to avoid serious criticism, you have to not post an idea.
Your reaction was not serious criticisme but a belligerent reaction.
You made it clear you wanted a fight. I choose not to enter that
fight.
I had another crazy thought that I AM NOT ASKING anyone to do. OK?
I was wondering about a sort of catch method you could use that generates a pseudo-signal only when the enclosed preceding loop exits normally as a
sort of way to handle the ELSE need without the use of a keyword known by
the language. All you would need is an object of the right kind that is thrown and optionally caught.
Of course, even if I fleshed this out and even if anyone thought it made sense, there is no such need now as Python has made a choice that meets the need even if few may dare use it or even know about it! LOL!
which had special combinations for all the BASIC keywords). And if you
go this way, why not go a step further and dissociate the program from
its linear text representation? Add footnotes, different views,
hyperlinks, format mathematical expressions like formulas, etc.
http://literateprogramming.com/
On 2022-10-17 09:25:00 +0200, Karsten Hilbert wrote:
which had special combinations for all the BASIC keywords). And if you
go this way, why not go a step further and dissociate the program from its linear text representation? Add footnotes, different views, hyperlinks, format mathematical expressions like formulas, etc.
http://literateprogramming.com/
Right. That's one of the inspirations for my comment.
But literate programming is of course still very much rooted in the
"linear text representation" paradigm. You have one definite source
which is a linear text.
In a world of IDEs, databases and hypertext that's probably not the best
we can do. As Raymond Hettinger would say, "there must be a better way".
It would be very different from mainstream programming languages,
however. And ideally you would want it to integrate with a lot of other infrastructure. So that alone might make it a non-starter, even if it
was really good (which realistically early iterations wouldn't be).
On Wed, 19 Oct 2022 at 12:01, Peter J. Holzer <hjp-python@hjp.at> wrote:
On 2022-10-17 09:25:00 +0200, Karsten Hilbert wrote:
http://literateprogramming.com/
Right. That's one of the inspirations for my comment.
But literate programming is of course still very much rooted in the
"linear text representation" paradigm. You have one definite source
which is a linear text.
In a world of IDEs, databases and hypertext that's probably not the best
we can do. As Raymond Hettinger would say, "there must be a better way".
It would be very different from mainstream programming languages,
however. And ideally you would want it to integrate with a lot of other infrastructure. So that alone might make it a non-starter, even if it
was really good (which realistically early iterations wouldn't be).
There are special-purpose languages like Scratch which are not simple
text in that form.
My Twitch channel bot has a command executor whose language, if you
call it that, is basically JSON - and the way to edit those commands
is very Scratch-inspired.
On 2022-10-19 12:10:52 +1100, Chris Angelico wrote:[...]
On Wed, 19 Oct 2022 at 12:01, Peter J. Holzer <hjp-python@hjp.at> wrote:
On 2022-10-17 09:25:00 +0200, Karsten Hilbert wrote:
http://literateprogramming.com/
Right. That's one of the inspirations for my comment.
But literate programming is of course still very much rooted in the "linear text representation" paradigm. You have one definite source
which is a linear text.
In a world of IDEs, databases and hypertext that's probably not the best we can do. As Raymond Hettinger would say, "there must be a better way".
It would be very different from mainstream programming languages, however. And ideally you would want it to integrate with a lot of other infrastructure. So that alone might make it a non-starter, even if it
was really good (which realistically early iterations wouldn't be).
There are special-purpose languages like Scratch which are not simple
text in that form.
Yes, I know.
It has a different goal though: Scratch tries to establish a friendly learning environment. Get rid of typing and syntax errors that beginners
find so frustrating.
What I'm interested in is an enviroment for developing medium-sized real applications. Somewhere in the several person-months to several
person-years of effort, hundreds of user-stories, maybe thousands of bug-reports and change-requests over its life-time.
And of course there have been lots of CASE tools over the years.
On 2022-10-19 12:10:52 +1100, Chris Angelico wrote:
On Wed, 19 Oct 2022 at 12:01, Peter J. Holzer <hjp-python@hjp.at> wrote:
On 2022-10-17 09:25:00 +0200, Karsten Hilbert wrote:
http://literateprogramming.com/
Right. That's one of the inspirations for my comment.
But literate programming is of course still very much rooted in the "linear text representation" paradigm. You have one definite source
which is a linear text.
bestIn a world of IDEs, databases and hypertext that's probably not the
way".we can do. As Raymond Hettinger would say, "there must be a better
It would be very different from mainstream programming languages, however. And ideally you would want it to integrate with a lot of other infrastructure. So that alone might make it a non-starter, even if it
was really good (which realistically early iterations wouldn't be).
There are special-purpose languages like Scratch which are not simple
text in that form.
Yes, I know.
It has a different goal though: Scratch tries to establish a friendly learning environment. Get rid of typing and syntax errors that beginners
find so frustrating.
What I'm interested in is an enviroment for developing medium-sized real applications. Somewhere in the several person-months to several
person-years of effort, hundreds of user-stories, maybe thousands of bug-reports and change-requests over its life-time.
The people using such a system/language would be professional
programmers. They probably don't need much help to get the syntax of a
for loop right. What they do need, though:
* Cross-reference between requirements and code. (Yes, you can write
comments, yes, you will hopefully have meaningful commit messages.
Still, I see a lot of room for improvements there)
* Cross-references between related parts of the code. (Yes, many IDEs
can jump to the definition of an instance or list all instances of a
definiton, But sometimes the relationship isn't that mechanic. And
yes, you can use comments fpr that, too)
* Views which highlight some parts of the code and omit others. (Folding
editors do that in a very limited fashion)
* For example, I might want to see only the code proper when I'm
focusing on an algorithm or I might want to see lots of context
(type definitions, requirements, test results, ...)
* Classes often have quite a lot of methods with no natural order.
Being able to view only a subset of them in some custom order may
help.
* Going back to the core idea of literate programming: Especially
views which show some requirement(s) together with the code that
implements them plus some explanation why that implementation was
chosen.
Presented like this, it's clear that the "language" (i.e. the file
format) is probably the smallest part of the problem. How the user can
view the program, how they can edit it, and how to keep the whole thing manageable is a much bigger question. And it would probably be a good
idea to start at the system level and not at the language level.
My Twitch channel bot has a command executor whose language, if you
call it that, is basically JSON - and the way to edit those commands
is very Scratch-inspired.
I designed a graphical filter language for database queries once. The idea was that you could combine various operations (selects, projections, grouping, transformations, ...) into pipelines via a web interface. We
did implement it (sadly it wasn't me who did it), and it turned out to
be a lot harder than I thought to make that actually usable.
And of course there have been lots of CASE tools over the years. That
seems to have been mostly a fad of 90s. Still, there were some good
ideas there (although not alway implemented well), and something bubbles
back up every now and then.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
--
https://mail.python.org/mailman/listinfo/python-list
On 2022-10-19 12:10:52 +1100, Chris Angelico wrote:
On Wed, 19 Oct 2022 at 12:01, Peter J. Holzer <hjp-python@hjp.at> wrote:
On 2022-10-17 09:25:00 +0200, Karsten Hilbert wrote:
http://literateprogramming.com/
Right. That's one of the inspirations for my comment.
But literate programming is of course still very much rooted in the "linear text representation" paradigm. You have one definite source
which is a linear text.
In a world of IDEs, databases and hypertext that's probably not the best we can do. As Raymond Hettinger would say, "there must be a better way".
It would be very different from mainstream programming languages, however. And ideally you would want it to integrate with a lot of other infrastructure. So that alone might make it a non-starter, even if it
was really good (which realistically early iterations wouldn't be).
There are special-purpose languages like Scratch which are not simple
text in that form.
Yes, I know.
It has a different goal though: Scratch tries to establish a friendly learning environment. Get rid of typing and syntax errors that beginners
find so frustrating.
What I'm interested in is an enviroment for developing medium-sized real applications.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 32:27:47 |
Calls: | 10,391 |
Calls today: | 2 |
Files: | 14,064 |
Messages: | 6,417,118 |