哪个代码更具可读性?
这不是一个困难的问题。我只是想知道您认为这两个 C++ 代码片段中哪一个更好(可读性 vs. 长度 vs. boiler-platery):
Option #1
Entity* square = Entity::Builder().positionX(0.0).positionY(0.0).
controller(ctrl).representation(rep).build();
Option # 2
Entity::Builder bld;
bld.positionX(0.0).positionY(0.0).controller(ctrl).representation(rep);
Entity* square = bld.build();
我个人更喜欢第一个选项,但这可能是因为我是代码的作者并且已经知道代码的作用(对于不了解代码的人来说可能会感到困惑)。我更喜欢它,因为它显示了对 Entity
对象的关注,而不是对 Entity::Builder
对象的关注(而且因为它更短)。
This isn't a difficult question. I simply want to know which of these two C++ code snippets you think is better (readability vs. length vs. boiler-platery):
Option #1
Entity* square = Entity::Builder().positionX(0.0).positionY(0.0).
controller(ctrl).representation(rep).build();
Option #2
Entity::Builder bld;
bld.positionX(0.0).positionY(0.0).controller(ctrl).representation(rep);
Entity* square = bld.build();
I personally prefer the first option, but that may be because I am the author of the code and already know what the code does (it may be confusing for someone who doesn't know the code). I like it better because it shows the focus on the Entity
object rather than on the Entity::Builder
object (and because it's shorter).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
选项#3
Option #3