2,077 reputation
1114
bio website
location Houston, TX
age 32
visits member for 4 years, 4 months
seen Mar 18 at 18:51

Mar
16
comment What is the reason of using an interface versus a generically constrained type
@NtscCobalt: It's more useful when you combine both parametric and interface generic programming. E.g. what LINQ does all the time (accepts an IEnumerable<T>, returns another IEnumerable<T> which is e.g. actually an OrderedEnumerable<T>)
Mar
16
awarded  Citizen Patrol
Mar
13
comment how to nicely use constant std::string in c++
Most certainly, but you'll need a definition somewhere, or suffer linker errors. Using a singleton would also avoid copying many strings many times.
Mar
13
comment how to nicely use constant std::string in c++
const is fine. The problem with the code in this answer is that the strings are non-static data members, so new copies are made for each class instance. There's no reason to have multiple copies of the same hardcoded string.
Mar
13
comment how to nicely use constant std::string in c++
The original question showed an approach that provides string objects, with a lot less copying.
Mar
12
comment how to nicely use constant std::string in c++
Are you aiming for maximum inefficiency? This makes a copy of nearly every string in the entire program each time one of them gets used!
Mar
12
comment how to nicely use constant std::string in c++
I have to disagree with nearly all of @CrazyEddie's comment. std::string does add overhead, namely dynamic allocation, and string copy, and a field for storing the size at runtime. The size of a std::string is calculated at runtime, the number of elements in a const char[] is a compile-time constant. The only advantage of std::string is the interface. Someone should provide a library of string manipulation functions that take character arrays as input and return RAII object (std::string or similar) of the needed size as output, thus both efficient and immune to buffer overflow.
Mar
10
comment Teaching a course on intro to programming, in C++: Do I teach C-style casts?
@ChristopherCreutzig: std::string is required to use a contiguous representation and follow it with a 0-character (NUL), but that is not a terminator; the end is controlled by a stored length. So it isn't really a C-style string inside, only at the API boundary where C-style strings are received. Anyway, I agree that not very much "under the hood" should be covered in an introductory course, but justify that on its own merits, not by incorrectly categorizing the topic as "of historical interest only".
Mar
10
comment Teaching a course on intro to programming, in C++: Do I teach C-style casts?
@ChristopherCreutzig: Manual memory management absolutely is occurring inside library implementations. And std::string certainly contains a lot of low-level string manipulation logic, including quite a number of functions that deal in C-style (terminated, not counted) strings, since the std::string public API accepts these. Furthermore, you won't be using any OS APIs whatsoever without having to work with C-style strings. So yes, these are quite current, as library implementation details. And they dictate how the abstractions work, too.
Mar
10
comment what should be logger's position in the parameter list
Of course this has the drawback that the logger is unavailable to the constructor.
Mar
9
comment Teaching a course on intro to programming, in C++: Do I teach C-style casts?
@ChristopherCreutzig: Except that "historical baggage" is very inaccurate. I'd opt for "Under the hood" or "What happens inside". Virtually all of the behavior of the abstraction is obvious if you understand the implementation.
Feb
12
answered Is throwing an exception an anti-pattern here?
Feb
1
revised Would redrawing controls in c# give more performance?
added 159 characters in body
Feb
1
answered Would redrawing controls in c# give more performance?
Nov
16
awarded  Yearling
Sep
22
comment Undefined behavior, in principle
@jxh: Fault-tolerant systems are indeed quite interesting. But they aren't undefined-behavior tolerant. Copies running in lockstep which encounter undefined behavior may all make the wrong choice, and voting won't help then.
Sep
15
comment Undefined behavior, in principle
C and C++ use two different terms: undefined behavior and unspecified behavior. There's also indeterminately sequenced. And the distinction is important. It is possible, albeit difficult, to write a correct program in the presence of unspecified behavior. But no amount of careful coding can ensure correctness in the presence of undefined behavior. Undefined behavior removes the semantic meaning of your entire program. On the other hand, behavior left undefined by the language may be defined by the platform.
Sep
11
answered Workflow for obfuscated PHP code with PHP protect
Sep
11
comment Workflow for obfuscated PHP code with PHP protect
@RobertHarvey: But with a deobfuscated stack trace, even without values of variables and parameters, you have a fighting chance at finding the bug.
Sep
11
comment Workflow for obfuscated PHP code with PHP protect
This approach may not be possible for errors that are data-dependent, and either (1) privacy concerns forbid having a copy of the entire user database in the test environment or (2) privacy concerns prevent logs from identifying what data was being processed, to the degree necessary to select the same data in the test environment.