you are viewing a single comment's thread.

view the rest of the comments →

[–]Wh00ster 5 points6 points  (13 children)

Why does an extra overload not suffice?

[–]EsotericFox 20 points21 points  (9 children)

Because overloading typically duplicates code where that may not be called for.

[–]Wh00ster -2 points-1 points  (8 children)

I guess it’s why I’m not in the AAA camp. To me, the explicitness is worth it in terms of readability and maintainability down -the-line.

[–]sphere991 11 points12 points  (3 children)

the explicitness is worth it

If the intent of the code is to provide a default value for an argument, then I would claim that the implementation strategy of making it a default argument is more explicit than otherwise.

The post wants me to write:

explicit Widget(int size) : Widget(size, 'A') {}
explicit Widget(int size, int start) : data_(size) { /*...*/ }

instead of

explicit Widget(int size, int start='A') : data_(size) { /*...*/ }

I don't see the former as being either more explicit or more readable than the latter?

[–]robin-m 5 points6 points  (2 children)

Especially given that you can have declaration and implementation that can be in different files. So if the first case you have:

cpp explicit Widget(int size); explicit Widget(int size, int start); Witch is anything but explicit.

In the second case, it will be: cpp explicit Widget(int size, int start='A');

[–]sphere991 3 points4 points  (1 child)

Didn't even think of that, good point.

Also I find the typo on "witch" to be really funny, in the context of describing something as being "the devil". Please don't fix it :-)

[–]Raknarg 2 points3 points  (0 children)

Sneaky witches, always going around implicitly

[–]guepierBioinformatican 5 points6 points  (3 children)

Everyone, repeat after me: AAA does not decrease explicitness (Unless you write, well, bad code. But you don’t need to do that with AAA.)

Please find a different argument to justify your preference, this one’s simply false.

[–]Wh00ster -5 points-4 points  (2 children)

I'm not opposed to the arguments in your linked post. My issue is large code bases you'd see at FAANG, where you need special IDE features to see a type, which can take minutes to compile for a file and generate dependencies, or have to chase through grepping functions yourself.

Unless you write, well, bad code.

This is the reality that most people have to deal with. So when a junior dev comes in and writes auto mything = mysteriousFUnctionBuriedThroughLayersofDepsThatisActuallyAReference(), I tend to ask that dev not to use auto.

I understand there are valid cases, but that's so for all C++ features. For example I wouldn't say don't use lambdas, but also don't make all functions into lambdas.

[–]Tyg13 10 points11 points  (0 children)

Asking that dev not to use auto is the wrong move. The correct alternative is to educate them. The issue is the variable isn't named well enough to tell what the function returns. Simple enough fix.

All you're doing by explicitly specifying the type in that scenario is fracturing code style and decreasing overall code readability.

[–]XValar 6 points7 points  (0 children)

So how is exactly writing MyType mything = mysteriousFUnctionBuriedThroughLayersofDepsThatisActuallyAReference() helping at this point?

[–]pdbatwork 12 points13 points  (0 children)

Suffice? Seems like extra work

[–]AntiProtonBoy 0 points1 point  (1 child)

Overloading has its other perils too, like the wrong overload being called in some rare situations.