I always put empty blocks on a single line – i.e. { } (notice the space!).
Furthermore, I usually put the colon and commas in front of the initialization list members instead of after – this makes adding members later on easier.
As far as I'm concerned, do it your way: As long as you are self-consistent and consistent with the project you're working on, it doesn't matter what your indentation style is.
I'd recommend putting a comment into the empty constructor body, just so anyone reading the code knows that you intended it to be empty. That way they can be certain that it's not a case of you having forgotten to insert code there.
发布评论
评论(5)
我总是将空块放在一行上 - 即
{ }
(注意空格!)。此外,我通常将冒号和逗号放在初始化列表成员的前面,而不是后面 - 这使得以后添加成员变得更容易。
(编辑:我自己不再遵循这种风格:现在我省略了大括号之间的空格。)
I always put empty blocks on a single line – i.e.
{ }
(notice the space!).Furthermore, I usually put the colon and commas in front of the initialization list members instead of after – this makes adding members later on easier.
(Edit: I no longer follow this style myself: I omit the space between braces nowadays.)
我就是这样做的:
但是你的方式对我来说并不奇怪。
This is how I do it:
But your way does not look strange to me.
以下是我如何按照
Google 风格(至少是 protobuf)进行操作:
Here's how I do it
Google style (atleast protobuf), would be:
以下是我的做法,以及为什么我没有发现你的示例有任何问题:
就我而言,按照你的方式去做:只要你是自洽的并且与你正在从事的项目保持一致,您的缩进样式是什么并不重要。
Here's how I do it, and why I don't see anything wrong with your sample:
As far as I'm concerned, do it your way: As long as you are self-consistent and consistent with the project you're working on, it doesn't matter what your indentation style is.
我建议在空的构造函数主体中添加注释,这样任何阅读代码的人都知道您希望它为空。这样他们就可以确定这不是您忘记在那里插入代码的情况。
I'd recommend putting a comment into the empty constructor body, just so anyone reading the code knows that you intended it to be empty. That way they can be certain that it's not a case of you having forgotten to insert code there.