<div dir="auto"><br><br><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I know what functional programming is. What I don't understand is what <br>
you mean when you say that the F.P. community "seems to be more <br>
interested in python". Surely they are more interested in functional <br>
languages than a multi-paradigm language like Python which does not <br>
privilege functional idioms over imperative idioms.<br><br></blockquote></div><div dir="auto"><br></div><div dir="auto">Just a personal feeling, it's not really thought out.</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> > try...except exceptions have been proposed before and rejected.<br>
> <br>
> I'm wondering why, that must have been the same reasons of not accepting<br>
> "with".<br>
<br>
Read the PEP. Or the (long!) discussions on Python-Ideas and Python-Dev.<br>
<br>
<a href="https://www.python.org/dev/peps/pep-0463/" rel="noreferrer noreferrer noreferrer" target="_blank">https://www.python.org/dev/peps/pep-0463/</a><br><br>
></blockquote></div><div dir="auto"><br></div><div dir="auto">I'm reading it. The prelude at the beginning then says there are no convincing use case if I get it right?</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Which is why I said it was not a good example. If you're going to <br>
propose syntax, you ought to give good examples, not bad examples.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">When showing toy examples I thought some people would think "indeed, that happens to me often".</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In any case, this is not a proposal for a "where" expression. You aren't <br>
going to convince people to add a "with" expression by showing them <br>
expression forms of "if", "for" or hypothetical "where". Each feature <br>
must justify itself, not sneak in behind another feature.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">Indeed, I'm talking about it because I think it all relates to "expressionalize simple statements", that's also why I speak about FP, because that's an "expression-first" paradigm.</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Or factor your code into named functions with isolated namespaces, so <br>
the f in one function doesn't clobber the f in another function. <br>
Structured programming won the debate against unstructured programming a <br>
long time ago.<br>
<br>
<a href="https://en.wikipedia.org/wiki/Structured_programming#History" rel="noreferrer noreferrer noreferrer" target="_blank">https://en.wikipedia.org/wiki/Structured_programming#History</a><br><br>
<br>
[...]</blockquote></div><div dir="auto"><br></div><div dir="auto">Of course I would do that, i completely agree that refactoring is useful, but as shown in the end of my post:</div><div dir="auto"><br></div><div dir="auto"><div dir="auto" style="">filename = compute_filename(...)</div><div dir="auto" style="">lines = compute_lines(...)</div><div dir="auto" style="">parsed_data = compute_parsed_data(...)</div><div dir="auto" style="font-family:sans-serif;font-size:12.8px"><br></div></div><div dir="auto">The functions body being a bit too small to be refactored and doesn't really have another meaning of "code to compute filename", I feel like the "filename =" already catches the idea, I feel like repeating myself (DRY).</div><div class="gmail_quote" dir="auto"></div><div dir="auto"><br></div><div dir="auto">And the function body in those cases is not very reusable so it doesn't make sense to give it a meaningful name.</div><div dir="auto"><br></div><div dir="auto">I would do a named function otherwise indeed.</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> One difficultly of finding use cases, it that it's about changing the<br>
> paradigm, probably all cases have a really readable implementation in<br>
> current python / imperative style. But when I see:<br>
> <br>
> try:<br>
> a_variable = int(input("..."))<br>
> except ValueError:<br>
> try:<br>
> a_variable = fetch_db()<br>
> except DbError:<br>
> a_variable = default<br>
> <br>
> I really think "why can't I put it one one line like I do with if".<br>
> <br>
> a_variable = (int(input("...")) except ValueError:<br>
> fetch_db() except DbError:<br>
> default)<br>
<br>
Whereas when I see somebody using a double if...else expression in a <br>
single line, I wish they would spread it out over multiple lines so it <br>
is readable and understandable, instead of trying to squeeze the maximum <br>
amount of code per line they can.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">Multiline is clearly better yes. When I say 'one line' I'm just saying "using the expression-statement but probably gonna span it on multiple lines because the Expressions are not short.</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> For "with", I'm just wondering "why do I have to indent, it will lose the<br>
> focus of the reader on the result itself".<br>
<br>
If this is a problem, then you can easily focus the reader on the <br>
result by factoring the code into a named function.<br>
<br>
text = read('filename')<br>
<br>
requires no indentation, no complicated new syntax, and it is easily <br>
extensible to more complex examples:<br>
<br>
text = (prefix + (read('filename') or 'default') + moretext).upper()<br>
<br>
This argument isn't about whether it might occasionally be useful to use <br>
a with expression, but whether it is useful *enough* to justify adding <br>
new syntax to the language.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">For 'with', as you all say, it really boils down to finding use cases other than "file manipulation". It's true I can't think of any (expect the fact it does create a function that may not have a meaningful name).</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
-- <br>
Steve<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" rel="noreferrer noreferrer" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div></div>