Which code is more readable? [closed]
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();
精彩评论