Allman 风格的匿名类
关于如何使用匿名类同时与 Allman 缩进样式保持一致,有什么建议吗?我真的不喜欢我想出的任何东西,例如
// Pass as parameter.
foo(new Clazz( )
{
// Do stuff.
});
// Assign to variable.
Clazz bar = new Clazz( )
{
// Do stuff.
};
Any recommendations on how to use anonymous classes while staying consistent with Allman indent style? I don't really like anything I've come up with, e.g.
// Pass as parameter.
foo(new Clazz( )
{
// Do stuff.
});
// Assign to variable.
Clazz bar = new Clazz( )
{
// Do stuff.
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
奥尔曼风格实际上是对齐{大括号},而不是所有(括号)。我想如果你愿意的话,你可以自由地做这两件事,但在我看来,这似乎是问题的根源(就像这个),在可读性方面没有明显的回报。换句话说,这是一种合乎逻辑的迷恋:-)
您可以按照 http://mbreen.com/javastyle.html 上的指南进行操作:
“包含带有代码块的声明的语句首先作为语句缩进。”我认为这会将你的例子改为
Allman style is really about aligning the {braces}, not all the (brackets). I suppose you are free to do both if you want, but it looks like a source of problems (like this one) to me, without a clear payback in readability. In other words, a logical fetish :-)
You could follow the guide at http://mbreen.com/javastyle.html:
"A statement containing a declaration with a code block is indented first as a statement." I think that would change your examples to
这就是我已经决定的。
我只是不再在方法调用中定义匿名类。
This is what I've settled on.
And I just don't define anonymous classes inside method calls anymore.
我为自己的代码提出的最佳折衷方案是将匿名类缩进一个制表符级别,并将右括号放在新行上。
The best compromise I came up with for my own code, is indenting the anonymous class a single tabbing level, and putting the closing parentheses on a new line.