Reputation
2,099
Top tag
Next privilege 2,500 Rep.
Create tag synonyms
Badges
11 15
Impact
~59k people reached

  • 0 posts edited
  • 0 helpful flags
  • 174 votes cast
Jul
22
comment How do I handle setters on immutable fields?
setXYZ are horrible names for factory methods, consider withXYZ or the like.
Jun
27
awarded  Autobiographer
Jun
10
comment What is the “type” of data that pointers hold in the C language?
Again, existence of a big enough type is irrelevant, all that matters is whether the particular type which is named in the cast is big enough
Jun
10
comment What is the “type” of data that pointers hold in the C language?
@supercat: the requirements for casting to a integer type of insufficient size do not change depending on whether an integer type of sufficient size exists. You get unspecified results from the conversion but not undefined behavior (the conversion is guaranteed to produce some value of the result type)
Jun
9
comment What is the “type” of data that pointers hold in the C language?
This answer has the generally right idea, but fails on the specific claims. Coercing a pointer to integral type is not undefined behavior, and Windows HANDLE data types are not pointer values (they are not pointers hidden in integral data types, they are integers hidden in pointer types, to prevent arithmetic).
Apr
21
comment Big O Question about an algorithm with (n^2 + n) / 2 growth rate
"O(n!) is the same as O(1) for sufficiently low values of n" is just wrong. There has to be a better way to explain that "when n is kept sufficiently low, Big-O doesn't matter".
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 what should be logger's position in the parameter list
Of course this has the drawback that the logger is unavailable to the constructor.
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.