烦人,冗长的自我 [英] the annoying, verbose self

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

问题描述

有没有任何诀窍可以摆脱不必输入烦人的,b / b
字符吃自我。在课堂上到处都是前缀?有时候我会花费大量资金来避免OO处理它的冗长。事实上,我尝试使用

Ruby在任何地方速度并不重要,特别是对于@前缀更好 -

看起来比自己。


但是事情在增长 - 是否有任何元编程技巧或者我们什么?b $ b可以投入自我?


干杯,

Alexy

Is there any trick to get rid of having to type the annoying,
character-eating "self." prefix everywhere in a class? Sometimes I
avoid OO just not to deal with its verbosity. In fact, I try to use
Ruby anywhere speed is not crucial especially for @ prefix is better-
looking than self.

But things grow -- is there any metaprogramming tricks or whatnot we
can throw on the self?

Cheers,
Alexy

推荐答案

braver写道:
braver wrote:

是否有任何伎俩摆脱不得不输入烦人的,b $ b字符吃自我。在课堂上到处都是前缀?有时候我会花费大量资金来避免OO处理它的冗长。事实上,我尝试使用

Ruby在任何地方速度并不重要,特别是对于@前缀更好 -

看起来比自己。


但事情在增长 - 是否有任何元编程技巧或者我们不知道什么?b $ b可以投入自我?
Is there any trick to get rid of having to type the annoying,
character-eating "self." prefix everywhere in a class? Sometimes I
avoid OO just not to deal with its verbosity. In fact, I try to use
Ruby anywhere speed is not crucial especially for @ prefix is better-
looking than self.

But things grow -- is there any metaprogramming tricks or whatnot we
can throw on the self?



你将得到的最常见的答案是明确的比隐式的更好

,我倾向于同意。有些人用''s'代替

''self''。这缩短了你必须键入的字符数,并且
只比Ruby'''''前缀多一个字符。


这是一个删除自我的元编程技术,但我不会推荐这些东西,特别是如果其他人打算在将来查看你的代码。所以使用它需要您自担风险!

http://aspn.activestate.com/ASPN/Coo.../Recipe/362305

-Farshid

The most common answer you are going to get is that explicit is better
than implicit, which I tend to agree with. Some people use ''s'' instead
of ''self''. This shortens the number of characters you have to type, and
is only one character more than the Ruby ''@'' prefix.

Here is a metaprogramming technique that removes self, but I don''t
recommend these sorts of things, especially if other people are going to
be looking at your code in the future. So use it at your own risk!

http://aspn.activestate.com/ASPN/Coo.../Recipe/362305

-Farshid


总有一些技巧。如果5个字符真的太难打字,

大约2个字符s。。虽然我建议不要使用

,因为它违反了标准的Python惯例。


def foo(self):


变成


def foo:


否则,如果你碰巧使用自己。很多东西,只是

将它分配给一个变量,并使用它。但要小心,因为

可能会变得更难以阅读/维护,而不仅仅是开始时让自己离开。


ss = self.something

ss.foo()

对我来说,在Python中使用''self'与使用其他一些没有什么不同

变量指向静态C ++类函数中的类实例。


-James
There are always tricks. If 5 characters is really too much to type,
how about 2 characters "s.". Though I would recommend against that
since
it violates standard Python convention.

def foo( self ):

becomes

def foo( s ):

Otherwise, if you happen to be using self.something a lot, just
assign it to a variable, and use that. But be careful as that
can become a lot more difficult to read/maintain than simply
leaving self along to begin with.

ss = self.something
ss.foo()

To me, using ''self'' in Python is no different than using some other
variable pointing to a class instance in a static C++ class function.

-James

-----原始信息-----

来自:py ************************** *************** @ python .org

[mailto:py ******************* ********************** @ python.org

]代表勇敢

发送:星期三,2007年11月21日下午4:52

要: py ******* **@python.org

主题:烦人,冗长的自我


有没有任何技巧可以摆脱烦恼,

字符吃自我。在课堂上到处都是前缀?有时候我会花费大量资金来避免OO处理它的冗长。事实上,我尝试使用

Ruby在任何地方速度并不重要,特别是对于@前缀更好 -

看起来比自己。


但是事情在增长 - 是否有任何元编程技巧或者我们什么?b $ b可以投入自我?


干杯,

Alexy

-
http://mail.python.org/mailman/listinfo/python-list


2007年11月21日星期三15:51: 56 -0800,braver写道:
On Wed, 21 Nov 2007 15:51:56 -0800, braver wrote:

是否有任何技巧可以摆脱不必输入烦人的,

字符吃 。自"在课堂上到处都是前缀?
Is there any trick to get rid of having to type the annoying,
character-eating "self." prefix everywhere in a class?



哦,我知道!这真是一种痛苦。 Sinc写了一个拥抱cla lat wk,我有一个

trribl hortag o lowrca S E L和F charactr。它写得非常讨厌。


Oh I know! It'' uch a pain. Sinc writing a hug cla lat wk, I''v had a
trribl hortag o lowrca S E L and F charactr. It mak writing vry annoying.


有时我会避免OO只是为了不处理它的冗长。
Sometimes I avoid OO just not to deal with its verbosity.



还有其他值,而不是简洁。事实上,简洁是重要的价值之一。

There are other values than brevity. In fact, brevity is one of the less
important values.


实际上,我尝试使用

Ruby在任何地方的速度并不重要,特别是对于@前缀更好 -

看起来比自己。
In fact, I try to use
Ruby anywhere speed is not crucial especially for @ prefix is better-
looking than self.



嗯,我认为它需要各种各样的。如果每个人都喜欢同样的东西,那些有品味的人会嘲笑



Well, it takes all sorts I suppose. Who would those with good taste mock
if everybody liked the same things?


但事情在增长 - 有没有元编程技巧或者我们还能做什么?b $ b抛出自我?
But things grow -- is there any metaprogramming tricks or whatnot we can
throw on the self?



哦,是的,这就是我喜欢看到的!复杂,脆弱,难以调试,难以理解元编程技巧优先于简单易读的命名约定。

-

史蒂文。

Oh yeah, that''s just what I like to see! Complicated, brittle, hard to
debug, difficult to understand metaprogramming tricks in preference to a
simple, easy-to-read naming convention.

--
Steven.


这篇关于烦人,冗长的自我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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