条件的python语法是不幸的 [英] python syntax for conditional is unfortunate

查看:57
本文介绍了条件的python语法是不幸的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事后看来,我对条件语法的选择感到失望。我知道改变已经太晚了。问题是


y = some something or other if if else something_else


扫描时我的眼睛往往会看到第一个短语而且只是稍后注意它是以x为条件的(或者根本不是通知!)。特别是如果某些事情或其他事情很长或很复杂。

In hindsight, I am disappointed with the choice of conditional syntax. I know it''s too late to change. The problem is

y = some thing or other if x else something_else

When scanning this my eye tends to see the first phrase and only later notice that it''s conditioned on x (or maybe not notice at all!). Particularly if ''some thing or other'' is long or complicated.

推荐答案

9月23日,6:52 * pm,Neal Becker< ndbeck ... @ gmail.comwrote:
On Sep 23, 6:52*pm, Neal Becker <ndbeck...@gmail.comwrote:

事后来看,我对条件语法的选择感到失望。 *我知道改变已经太晚了。 *问题是


y =某些东西或其他如果x else something_else


扫描时我的眼睛往往会看到第一个短语而且只有后来注意到它以x为条件(或者根本没有通知!)。 *特别是如果某些事情或其他事情很长或很复杂。
In hindsight, I am disappointed with the choice of conditional syntax. *I know it''s too late to change. *The problem is

y = some thing or other if x else something_else

When scanning this my eye tends to see the first phrase and only later notice that it''s conditioned on x (or maybe not notice at all!). *Particularly if ''some thing or other'' is long or complicated.



你正在严格谈论可读性,当然,除了其他东西之外,还是在beholder眼中是
。一些代码可以清除临时变量,即使选择名称也很麻烦,而且需要跟踪的事情要多得多。长线和额外变量形成交易 -

off。你正在写一个带有条件表达式的行,其值为

取决于某些东西。它依赖于什么,如果它是真的那么它的价值是多少?如果它是假的,它是什么? ''...如果......其他......''

只需要6个字符...也许你想要更多!


如果你'正在寻找一个严格的句法结构,你可以随时

火空白或追踪者,如果这个比喻更准确。


z =有条件地(x)如果b其他y


这可以作为一个温和的提醒,即使''有条件地''

返回其论点,即身份功能。你也可以随时用额外的参数滚动你自己的三元组:


z =条件(b,x,y)


不要把它与threading混淆。条件。


否则,你会被旧的语法标记所困,除非你

想要:


z =如果b然后x其他y


你没有选择。你必须以某种方式表达它。你想要首先获得

的条件吗?有没有另类的建议你

首选? IINM如果我没弄错的话,


z = b和x或y


的工作原理相同,只要x的计算结果为True即可,因为它将是b $ b测试的。


随意从头开始编写你自己的,我们会看到有多接近

Python可以变得类似它。


我想你可以把它与那些在

字''if''之前停止听的人比较,并且完全误解了你的陈述。 如果他站在食物盘附近,就喂他/她的b $ b狗。 !=喂狗,这可能是b
当然导致遗漏和佣金的错误(做得太多了b / b $或者太多)。没有办法以保证

的方式解决这个问题,除非说听完整个声明。


严格讽刺地说你在阅读

计划时想做些什么?你为什么读它? < snicker,ducks>

You''re talking strictly about readability, which among other things is
in the eye of the beholder, of course. Temporary variables can clean
up some code, even if choosing names can be a hassle and it''s more
things to keep track of. Long lines and extra variables form a trade-
off. You are writing a line with a conditional expression the value
of which depends on something. What does it depend on, what is its
value if that''s true, and what is it if it''s false? ''...if...else...''
only takes 6 characters... maybe you want more!

If you''re looking for a strictly syntactic construct, you can always
"fire blanks", or tracers, if the analogy''s more accurate.

z= conditionally( x ) if b else y

This could serve as a gentle reminder, even where ''conditionally''
returns its argument, i.e. is the identity function. You can always
roll your own ternary with extra parameters too:

z= condition( b, x, y )

Just don''t confuse it with threading.Condition.

Otherwise, you''re stuck with old syntax markers, and unless you
wanted:

z= if b then x else y

You''re out of options. You have to express it somehow. Did you want
the condition first? Was there an alternative proposal you
preferred? IINM if I''m not mistaken,

z= b and x or y

works just the same so long as x evaluates to True, as it will be
tested.

Feel free to write your own from scratch, and we''ll see how close
Python can come to resembling it.

I suppose you can compare it to someone who stops listening before the
word ''if'', and completely misunderstands your statement. "Feed the
dog if he''s standing near the food dish" != "Feed the dog", which can
of course lead to errors of both omission and commission (doing too
little -or- too much). There''s no way to fix that in a guaranteed
way, except to say, "listen to the whole statement".

And strictly sarcastically, what did you want to do with reading the
program? Why were you reading it? <snicker, ducks>


23集,20:52,Neal Becker< ndbeck ... @ gmail.comwrote:
On 23 set, 20:52, Neal Becker <ndbeck...@gmail.comwrote:

事后看来,我对条件语法的选择感到失望。 *我知道改变已经太晚了。 *问题是


y =某些东西或其他如果x else something_else


扫描时我的眼睛往往会看到第一个短语而且只有后来注意到它以x为条件(或者根本没有通知!)。 *特别是如果某些事情或其他事情很长或很复杂。
In hindsight, I am disappointed with the choice of conditional syntax. *I know it''s too late to change. *The problem is

y = some thing or other if x else something_else

When scanning this my eye tends to see the first phrase and only later notice that it''s conditioned on x (or maybe not notice at all!). *Particularly if ''some thing or other'' is long or complicated.



是的,中缀语法很糟糕。在前缀Lisp中没有歧义:(如果x(或

其他东西)something_else)


无论如何,看到Guido向Larry点头......非常有趣

Yes, infix syntax sucks. No ambiguities in prefixed Lisp: (if x (or
something other) something_else)

Anyway, pretty amusing seeing Guido nodding to Larry... ;)


AaronCastironpi Brady写道:
Aaron "Castironpi" Brady wrote:

9月23日下午6:52,Neal Becker< ndbeck ... @ gmail.comwrote:
On Sep 23, 6:52 pm, Neal Becker <ndbeck...@gmail.comwrote:

>事后看来,我对条件语法的选择感到失望。我知道改变已经太晚了。问题是

y =某些东西或其他如果x else something_else

扫描时我的眼睛往往会看到第一个短语而后来才注意到它这是以x为条件的(或者根本不是通知!)。
特别是如果某些事情或其他事情很长或很复杂。
>In hindsight, I am disappointed with the choice of conditional syntax. I
know it''s too late to change. The problem is

y = some thing or other if x else something_else

When scanning this my eye tends to see the first phrase and only later
notice that it''s conditioned on x (or maybe not notice at all!).
Particularly if ''some thing or other'' is long or complicated.



你正在严格谈论可读性,当然,除了其他方面,还是在旁观者眼中是
。一些代码可以清除临时变量,即使选择名称也很麻烦,而且需要跟踪的事情要多得多。长线和额外变量形成交易 -

off。你正在写一个带有条件表达式的行,其值为

取决于某些东西。它依赖于什么,如果它是真的那么它的价值是多少?如果它是假的,它是什么? ''...如果......其他......''

只需要6个字符...也许你想要更多!


如果你'正在寻找一个严格的句法结构,你可以随时

火空白或追踪者,如果这个比喻更准确。


z =有条件地(x)如果b其他y


这可以作为一个温和的提醒,即使''有条件地''

返回其论点,即身份功能。你也可以随时用额外的参数滚动你自己的三元组:


z =条件(b,x,y)


不要把它与threading混淆。条件。


否则,你会被旧的语法标记所困,除非你

想要:


z =如果b然后x其他y


你没有选择。你必须以某种方式表达它。你想要首先获得

的条件吗?有没有另类的建议你

首选? IINM如果我没弄错的话,


z = b和x或y


的工作原理相同,只要x的计算结果为True即可,因为它将是b $ b测试的。


随意从头开始编写你自己的,我们会看到有多接近

Python可以变得类似它。


我想你可以把它与那些在

字''if''之前停止听的人比较,并且完全误解了你的陈述。 如果他站在食物盘附近,就喂他/她的b $ b狗。 !=喂狗,这可能是b
当然导致遗漏和佣金的错误(做得太多了b / b $或者太多)。没有办法以保证

的方式解决这个问题,除非说听完整个声明。


严格讽刺地说你在阅读

计划时想做些什么?你为什么读它? < snicker,ducks>


You''re talking strictly about readability, which among other things is
in the eye of the beholder, of course. Temporary variables can clean
up some code, even if choosing names can be a hassle and it''s more
things to keep track of. Long lines and extra variables form a trade-
off. You are writing a line with a conditional expression the value
of which depends on something. What does it depend on, what is its
value if that''s true, and what is it if it''s false? ''...if...else...''
only takes 6 characters... maybe you want more!

If you''re looking for a strictly syntactic construct, you can always
"fire blanks", or tracers, if the analogy''s more accurate.

z= conditionally( x ) if b else y

This could serve as a gentle reminder, even where ''conditionally''
returns its argument, i.e. is the identity function. You can always
roll your own ternary with extra parameters too:

z= condition( b, x, y )

Just don''t confuse it with threading.Condition.

Otherwise, you''re stuck with old syntax markers, and unless you
wanted:

z= if b then x else y

You''re out of options. You have to express it somehow. Did you want
the condition first? Was there an alternative proposal you
preferred? IINM if I''m not mistaken,

z= b and x or y

works just the same so long as x evaluates to True, as it will be
tested.

Feel free to write your own from scratch, and we''ll see how close
Python can come to resembling it.

I suppose you can compare it to someone who stops listening before the
word ''if'', and completely misunderstands your statement. "Feed the
dog if he''s standing near the food dish" != "Feed the dog", which can
of course lead to errors of both omission and commission (doing too
little -or- too much). There''s no way to fix that in a guaranteed
way, except to say, "listen to the whole statement".

And strictly sarcastically, what did you want to do with reading the
program? Why were you reading it? <snicker, ducks>



我发现我经常被绊倒:


x = Y(很多构造函数参数.... )如果有什么......乍一看
,我没注意到if。


我为什么读这个?嗯,因为我写了它。

I find I''m often tripped up by:

x = Y (lots of constructor arguments....) if something ...

on first glance, I don''t notice the if.

Why am I reading this? Umm, because I wrote it.


这篇关于条件的python语法是不幸的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆