开发者

Which code is more readable? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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.开发者_如何学Go0).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).


Option #3

Entity* square = Entity::Builder()
                     .positionX(0.0)
                     .positionY(0.0)
                     .controller(ctrl)
                     .representation(rep)
                     .build();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜