风格问题...... [英] Style question...

查看:56
本文介绍了风格问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用通过结束缩进级别声明,我会惹恼那些必须阅读我的代码的人吗?例如:

$ x $ b for x in xrange(0,5):

if i:

print i

通过

打印i * -1

通过


我问两个原因... a)它有帮助emacs想出来了,b)我更多

用令牌来结束复合语句。

解决方案

Anthony Roberts写道:


如果我用传递结束缩进级别声明,我会惹恼那些必须阅读我的代码的人吗?例如:

我在xrange(0,5):
如果我:
打印我
通过
打印i * -1 传递

我问了两个原因... a)它帮助emacs搞清楚,并且b)我用一个令牌来更好地结束复合语句。



对不起,但是,我觉得很难看。如果你刚刚开始使用

Python,那么请暂时不用这种方法试一试

并看看你是否变得更舒服*没有*令牌

比你曾经使用过它。


-Peter


Anthony Roberts写道:

如果我用传递结束缩进级别声明,我会惹恼那些必须阅读我的代码的人吗?例如:

我在xrange(0,5):
如果我:
打印我
通过
打印i * -1 传递




* yuck * :(


(哎呀,对不起......)

>
布鲁诺


" Anthony Roberts"< an ***************** ********@nospam.com>在留言中写道

新闻:Uv ******************* @ news1.calgary .shaw.ca ..。

如果我用传递语句结束缩进级别,我会惹恼那些必须阅读我的代码的人吗?例如:
<我喜欢xrange(0,5):
如果我:
打印我
打印
打印i * -1
通过
<我问了两个原因... a)它帮助emacs弄明白,并且b)我用一个令牌来更好地结束复合语句。



嗨。我很早就尝试过这样的事情。 (我记得

感到沮丧,发现我不能只是别名end = pass,并使用''end''作为

块分隔符..嘿)。我实际上并不想使用''end''(我喜欢

重要的空白),我刚看到很多关于

的投诉帖子没有-block-delimiter",我想,我想知道你是否可以制作一个。那么,你可以(当然)
,但不是那样的。


无论如何。我认为对于必须拥有可见块

分隔符的人来说,建议的成语是#end< keyword>。如果你使用这个,我认为emacs可以计算出来的价格。 (我不知道,我不使用emacs,但我认为pymode可以处理

这个),如果你愿意,你也可以使用Tools / scripts / pindent.py。


"来自pindent.py"

#此文件包含一个类和一个主程序,执行三个

#相关(尽管是免费的)Python上的格式化操作

#programs。当被称为pindent -c时,它需要一个有效的Python

#程序作为输入,并输出一个增加了块关闭的版本

#comments。当被称为pindent -d时,它假设它的输入是一个带有块结束注释的

#Python程序,并输出一个无评论的
#版本。当被称为pindent -r时它假设它的输入是一个

#Python程序,带有块关闭注释但是有缩进

#搞砸了,并输出一个正确的缩进版本。


[snip]


#秘密功能:

# - 输入时,一个块也可以用结束关闭声明" -

#这是一个没有#符号的块结束评论。


嗯。看起来你也可以使用结束,或者也许结束。我不知道

< keyword>是否可选,从未使用过这个模块。

无论如何,如果你使用这种格式,那么,如果有人不喜欢看到所有

那么噪音阅读你的代码,他们可以用

" pindent -d"删除它。便利。并且,当你阅读其他人的代码时,你可以用pindent -c很好地混淆它/ b $ b。真是两全其美。


HTH

肖恩


If I end indentation levels with "pass" statements, will I piss off people
that have to read my code? eg:

for i in xrange(0,5):
if i:
print i
pass
print i * -1
pass

I ask for two reasons... a) it helps emacs figure it out, and b) I''m more
comfortable ending compound statements with a token.

解决方案

Anthony Roberts wrote:


If I end indentation levels with "pass" statements, will I piss off people
that have to read my code? eg:

for i in xrange(0,5):
if i:
print i
pass
print i * -1
pass

I ask for two reasons... a) it helps emacs figure it out, and b) I''m more
comfortable ending compound statements with a token.



Sorry, but yes, I find that ugly. If you''re just starting out with
Python, please just give it a shot without that approach for a while
and see whether you become much more comfortable *without* the token
than you ever were with it.

-Peter


Anthony Roberts wrote:

If I end indentation levels with "pass" statements, will I piss off people
that have to read my code? eg:

for i in xrange(0,5):
if i:
print i
pass
print i * -1
pass



*yuck* :(

(oops, sorry...)

Bruno


"Anthony Roberts" <an*************************@nospam.com> wrote in message
news:Uv*******************@news1.calgary.shaw.ca.. .

If I end indentation levels with "pass" statements, will I piss off people
that have to read my code? eg:

for i in xrange(0,5):
if i:
print i
pass
print i * -1
pass

I ask for two reasons... a) it helps emacs figure it out, and b) I''m more
comfortable ending compound statements with a token.


Hi. I tried to do something like that too, early on. (I recall being
frustrated to find I couldn''t just alias "end = pass", and use ''end'' as a
block delimiter... heh). I didn''t actually want to use ''end'' (I like
significant whitespace), I just saw a lot of posts with complaints about
"no-block-delimiter", and I thought, I wonder if you can make one. Well, you
can (of course), but not like that.

Anyway. I think the suggested idiom for people who must have a visible block
delimiter is "# end <keyword>". If you use this, I think emacs can "figure
it out" (I don''t know, I don''t use emacs, but I think pymode can handle
this), and you can also use Tools/scripts/pindent.py, if you like.

"from pindent.py"
# This file contains a class and a main program that perform three
# related (though complimentary) formatting operations on Python
# programs. When called as "pindent -c", it takes a valid Python
# program as input and outputs a version augmented with block-closing
# comments. When called as "pindent -d", it assumes its input is a
# Python program with block-closing comments and outputs a commentless
# version. When called as "pindent -r" it assumes its input is a
# Python program with block-closing comments but with its indentation
# messed up, and outputs a properly indented version.

[snip]

# Secret feature:
# - On input, a block may also be closed with an "end statement" --
# this is a block-closing comment without the ''#'' sign.

Hmm. Looks like you can also use "end", or perhaps ''end'' . I don''t know if
the <keyword> is optional or not, having never used this module.
Anyway, if you use this format, then, if someone doesn''t like seeing all
that noise when they read your code, they can strip it out with
"pindent -d". Handy. And, when you read other peoples code, you can clutter
it up nicely with "pindent -c". Best of both worlds, really.

HTH
Sean


这篇关于风格问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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