- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 answer 中(由 S.Lott) 回答关于 Python 的 try...else
语句的问题:
Actually, even on an if-statement, the else: can be abused in truly terrible ways creating bugs that are very hard to find. [...]
Think twice about else:. It is generally a problem. Avoid it except in an if-statement and even then consider documenting the else- condition to make it explicit.
这是一个广泛持有的观点吗?是 else
considered harmful ?
当然,您可以用它编写令人困惑的代码,但任何其他语言结构都是如此。即使是 Python 的 for...else
在我看来也是一件非常方便的事情(try...else
就不太方便了)。
最佳答案
S.Lott 显然看到了一些糟糕的代码。我们不是吗?我不认为 else 有害,尽管我已经看到它用来编写错误的代码。在那些情况下,所有周围的代码也很糟糕,那么为什么要责怪其他人呢?
关于python - "else"在 Python 中被认为是有害的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/865741/
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我在摆弄 LinqToSQL 和 LINQPad,我注意到 SingleOrDefault() 没有对生成的 SQL 进行任何过滤或限制(我几乎期望与 Take(1) 等效)。 因此,假设您想保护自己
我是一名优秀的程序员,十分优秀!