Reputation
1,045
Top tag
Next privilege 2,000 Rep.
Edit questions and answers
Badges
1 8 17
Newest
 Cleanup
Impact
~28k people reached

  • 0 posts edited
  • 0 helpful flags
  • 179 votes cast
Jan
13
comment Anonymous namespaces make code untestable
@DocBrown, yes, I understand what you're saying. If I'd use a subset of C++ which would forbid me calling private functions outside of the class, then I'd have same problem as with anon. namespaces. However there is a clear answer to the "private functions problem" - C++ has the friend keyword for it, don't use such stupid subset of C++, it's not C# or Java!
Jan
13
comment Anonymous namespaces make code untestable
@DocBrown look, there is a big difference between "practically impossible" and "bad idea". There is the Chromium codebase. It uses friend class FooTest; in almost every class. No matter what experts say - it's a norm there, and the coding style guide agrees with that. So while it's important to listen to experts, one should stay pragmatic and think of more options than only "recommended by some theoreticians on the internet".
Jan
13
comment Anonymous namespaces make code untestable
@DocBrown private functions are perfectly testable, C++ has the friend keyword for it. Functions in anonymous namespace are not visible to tests at all (except for the trick with #include "foo.cpp" in foo_test.cpp, which is usually impossible because of the ODR)
Jan
13
comment Anonymous namespaces make code untestable
@DocBrown I'm not asking how to test functions in anon. namespaces. I'm asking "why put code into anon. namespaces?" (see the text at the end of the question). Blame Ixrec for changing the title to something different.
Dec
26
comment Doesn't “always initialize variables” lead to important bugs being hidden?
Yeah, the example is no good. I'd remove it but that'd mess up the history.
Dec
26
comment Doesn't “always initialize variables” lead to important bugs being hidden?
@Mat that buffer[bytes_read] = 0 was just an example of a read operation. It could be anything, it doesn't really matter if there is a terminating 0 or not.
Dec
26
comment Doesn't “always initialize variables” lead to important bugs being hidden?
1) it's all about probabilities, like 1% vs 99%. 2 and 3) VC++ generates such initialization code, for local variables as well. 3) static (global) variables are always initialized with 0.
Dec
26
comment Doesn't “always initialize variables” lead to important bugs being hidden?
@Mat the design is bad, but it's not relevant here. That use thing could be a third party function (e.g. system).
Dec
26
comment Doesn't “always initialize variables” lead to important bugs being hidden?
@DocBrown I slightly changed the code. Usually functions are supposed to fill their out-parameters even in case of an error, so let's assume that it's a bug. Also let's assume that use() expects data which were successfully read, not an empty buffer after a read error.
Jul
30
comment Is it bad practice to use constant variables with global scope in C++?
Currently the latest working draft is N4527.
Jun
28
comment Named output parameters vs return values
@Telastyn, well, at call site you don't see parameter names either.
Jun
28
comment Named output parameters vs return values
in handle_message(out bool wasHandled), false value of wasHandled doesn't mean "failure" or "success". It means that there is no need to pass message to next handler. Something like "stop event propagation" if we'd use term "event" instead of "message". As for Windows window messages, DOM events, etc. And yeah, wasHandled has nothing to do with message result and actual message processing. Handler can process message, but return wasHandled == false if it wants to pass the message to a next handler.
Jun
28
comment Named output parameters vs return values
oh, WinForms events. Did you notice that all of them have void return type? Why do you ignore all the events which have output values? E.g. FormClosing, Drag&Drop events, etc?
Jun
28
comment Named output parameters vs return values
In my IDE, you can see comments at declaration, if you move mouse cursor over function identifier at call site.
Jun
27
comment Named output parameters vs return values
@JustinC, side-effect free? Do you mean the process_message and set_value functions? Well yeah, I'd even say it's impossible to make them side-effect free.
Jun
27
comment Named output parameters vs return values
@Bobson, will you make that reply an answer, including different cases of message and event processing, e.g. void processEvent(SomeEvent event, ref string eventResult, ref string otherEventResult, out bool stopEventPropagation) ? Maybe with examples from existing libraries and frameworks.
Jun
27
comment Named output parameters vs return values
@Ingo with tuple<string, string> you have no idea what output values are, or what is their order in tuple.
Jun
27
comment Named output parameters vs return values
When I see bool DoStuff(...) I have no idea what that bool means. Is it "that stuff was good, let's do it again" or "we did enough of that stuff, let's stop" or something else - I don't know. Or maybe it has nothing to do with doing stuff? But with void DoStuff(..., out bool success) or void DoStuff(..., out bool dontDoItAgain) I know what that output value means.
Jun
27
comment Named output parameters vs return values
of course, if function clearly states what it returns, there is no need in named output parameter. E.g. sumOfArray obviously returns a sum. But I'm asking about functions which aren't named after their output values.
Jun
27
comment Named output parameters vs return values
@Bobson please suggest another name.