On 7/18/23 12:03 AM, Dom Grigonis wrote:
Ok, thanks. I think what I am aiming at is that there is a pool of
suggestions and PEPs that are pointing towards very similar direction
and I find myself often wandering in the same space, just trying to
figure out what it exactly is.
It sometimes feels more verbose than it could be for what it is in the
context of how simple python is to use in general.
I am fully well aware that current if-else expression is not going
anywhere. Chances that another expression is introduced, which does
exactly the same thing are close to none.
So I am just gauging if it is a matter of conciseness of existing
expressions or absence of something that could be there. Conditional
if-else is just a place where I got to naturally.
Got some useful references to PEPs, python history and opinions. Maybe
it will become more clear in the future or maybe something new is
already being worked that is going to fill the gap which I am not
aware of.
I haven’t even started any proposal myself, I was just following
e-mail requests and rejected PEPs that were mentioned here. Combined
it with my own experience and this is where I got to.
Currently seems like it’s a dead end. Decision’s have been made,
opinions taken into account, but I still have to write either:
a) awkward 1-liner
self.value= valueif valueis not None else DefaultClass()
b) 3 nicely readable lines with 1 unnecessary assignment.
self.value= value
if valueis None:
self.value= DefaultClass()
or, changing around:
if value is None:
value = DefaultClass()
self.value = value
since the assignment is fundamental to the operation of the function,
that is adding 2 lines to implement an optional default, which isn't
that much to implement the feature.
it could be simplified to one line as
if value is None: value = DefaultClass()
(I think this is legal but against PEP8)
c) 4 lines, no unnecessary assignments with excellent readability.
if valueis None:
self.value= DefaultClass()
else:
self.value= value
The issue with b) and c) is that if I use those ones, my constructors
become unbearably long and finally lead to the point where development
becomes awkward. I would think that for what it does, it shouldn’t be
more than 1 line. Max - 2. But a) is somewhat awkward. All (well not
all, just several things) taken into account I ended up at
inconvenience of `ifelse` expression, which would make a) my natural
choice in this case. I am not even suggesting to introduce analogous
`ifelse` with different syntax, just trying to get some ideas,
references, opinions or alternatives that I don’t know about.
-
Richard Damon
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/TLOWSO7GPUPU4XW2GP6OOW3IN2NFVWCA/
Code of Conduct: http://python.org/psf/codeofconduct/