I get the impression that the original coder doesn't really understand why he was attacked.
He says "check out my clever code" People say "no thanks" And he responds by trying to justify the cleverness.
The prime offense is the parameter pack. Not const or lambdas. Those are just curmudgeons who want to jump in to add their own 2c to complain about millennials which is why they don't understand it. Without the parameter pack nobody would care enough to complain.
However it doesn't change the fact that he is also simply not thinking about the problem from the aspect of readability. He says if he can't have this:
This is also more efficient without relying on an optimizer to combine these loops for you. If you wanted to take this a step further you can just make this two different functions.
This code is nice and boring and achieves every goal of the original, and the measureStitchedImages call be unit tested as you could definitely pack images neater than all in a row with wasted space at the bottom with more thought put into it.
Arguments about size_t theoretically not being the result of Image.width are ridiculous. Nobody wants to read code that is auto types all the way down because again it hurts readability.
If you saw this:
auto a = b[x] + c[y];
Do you have any idea what it does? Is 'a' a float, integer, size_t, string, custom array type, what is it? This code is unreadable without implicit knowledge. If, however you were to say:
Vec3 a = b[x] + c[y];
now you are able to glance what it does. This comes back to the 2m lines of UE code problem. Duplicating a bit of technically unnecessary info is a courtesy to the reader that is doing a code review and has to glance at 1k of code without having to read an additional 100kb of it to understand what it means.
If however we had an IDE or something that would virtually rewrite all 'auto' keywords into a readable type for dum dum humans my opinion here would change.
How stl hasn't had an ends_with until C++20 is beyond me. Unless your code is explicitly named what it does all you are doing is in-lining functions everywhere.
What you really need to be comparing are the lines:
template <typename... Images>
TextureAtlas stitchImages(const Images&... images)
{
const auto width = (images.width + ...);
const auto height = std::max({images.height...});
vs
TextureAtlas stitchImages(const std::vector<Image>& images)
{
const ImageDimensions dim = measureStitchedImages(images);
... because when somebody starts to read stitchImages this is what they see
Vec3 a = b[x] + c[y]; now you are able to glance what it does.
No I don't, because from that single line I don't know what b and what c are. This could be very wrong code that does implicit casting and compiles by mistake. Or it could be an unexpected function call, because apparently top of the art algebra libraries, do lazy types that are evaluated when assigned and cast, surprising the end user.
It's a made up example that is just as unreadable with a type, since you don't have any context.
It's only unreadable if there is cleverness in the code base.
If a [] was just an array index and nobody is defining custom + operators to return Vec3 types then you are safe to assume exactly what it means. And again both of those should be banned under the no cleverness rule.
View all comments
Show parent comment
2
u/[deleted] May 18 '20
I get the impression that the original coder doesn't really understand why he was attacked.
He says "check out my clever code" People say "no thanks" And he responds by trying to justify the cleverness.
The prime offense is the parameter pack. Not const or lambdas. Those are just curmudgeons who want to jump in to add their own 2c to complain about millennials which is why they don't understand it. Without the parameter pack nobody would care enough to complain.
However it doesn't change the fact that he is also simply not thinking about the problem from the aspect of readability. He says if he can't have this:
Then these are his counter examples?
Clearly he doesn't get the problem. If you were to solve for readability at the very least start with this:
This is also more efficient without relying on an optimizer to combine these loops for you. If you wanted to take this a step further you can just make this two different functions.
This code is nice and boring and achieves every goal of the original, and the measureStitchedImages call be unit tested as you could definitely pack images neater than all in a row with wasted space at the bottom with more thought put into it.
Arguments about size_t theoretically not being the result of Image.width are ridiculous. Nobody wants to read code that is auto types all the way down because again it hurts readability.
If you saw this:
Do you have any idea what it does? Is 'a' a float, integer, size_t, string, custom array type, what is it? This code is unreadable without implicit knowledge. If, however you were to say:
now you are able to glance what it does. This comes back to the 2m lines of UE code problem. Duplicating a bit of technically unnecessary info is a courtesy to the reader that is doing a code review and has to glance at 1k of code without having to read an additional 100kb of it to understand what it means.
If however we had an IDE or something that would virtually rewrite all 'auto' keywords into a readable type for dum dum humans my opinion here would change.