
On Tue, 18 Jul 2023 at 08:34, Dom Grigonis <dom.grigonis@gmail.com> wrote:
I still feel that compared to list comprehension and other functional and elegant python constructs, python's if-else expression is lacking. I often choose to go multi-line much more verbose code as opposed to more brief constructs just because it becomes unreadable - a more elegant and logically convenient expression would change the decision ratio significantly, at least for me.
You choose to go multi-line because the one-liner becomes less readable? Then that's a win for the current system. This is NOT a problem to be solved. Everything is working correctly. You have chosen the readable option over the compact one!
# Code becomes easily read when there is a nice alignment in horizontal space. e.g.:
variable = None length_1 = None somethin = None
variable = length_1 = somethin = None
# I often take this into account on variable name selection. Now:
Poor choice IMO. You could have had more consistent variable names by taking advantage of chained assignment.
foo = var1 if a == 0 else default bar = variable2 if a == 0 else default2
# As opposed to
foo = a == 0 ? var1 : default bar = a == 0 ? variable2 : default2
As opposed to if a == 0: foo, bar = var1, variable2 else: foo, bar = default, default2
From what I have gathered, these: https://peps.python.org/pep-0505/ https://peps.python.org/pep-0463/ , and certain number of proposals in this group at their root are pointing approximately to the same direction. I.e. some things are too verbose (and too many lines of code) given the simplicity of what is needed to be done.
Both of those are about *expressiveness*. This is not the same thing as compactness. The two do sometimes align but the purpose is different.
https://peps.python.org/pep-0308/#detailed-results-of-voting It seems that C’s expression was ranked 2nd most favourable… The decision was 3rd. This kinda suggests that I am not as delusional as I initially thought I might appear to be with this...
Like I said, people who are *already familiar with* C's syntax find it more comfortable than those who are not. But also - this ship has sailed. There's not a lot of point discussing this. If Python had decided against having any conditional expression, then maybe you could reopen the discussion (and I'll be honest, it would have been reopened already by now); but we have a perfectly good conditional expression, so the chances of getting a duplicate syntax added are slim to Buckley's. Adding another way of writing the same thing doesn't materially improve expressiveness. ChrisA