Reputation
2,922
Top tag
Next privilege 3,000 Rep.
Cast close & reopen votes
Badges
10 23
Impact
~109k people reached

Jul
13
comment Rust-style error handling in C++
Well, this is more a review of the c++ implementation but thanks anyway. I'm not sure I completely understand point 1. Do you mean using something like std::unique_ptr< E >?
Jul
13
asked Rust-style error handling in C++
Jul
4
comment How to implement a NavigationManager class without using singleton pattern
Not using a singleton but instead passing an instance, possibly using an interface instead of a concrete implementation is (afaik) the way to not having to deal with singletons, yes. Whether or not using a framework to help with that is also the way I dare not say. Definitely not always.
Jul
4
answered How to implement a NavigationManager class without using singleton pattern
May
11
comment When and why should a destructor be declared as virtual?
Already 3 upvotes for an answer that imo doesn't quite cut it? Suggested reading (as linked by Snowman already) for a less vague description: stackoverflow.com/questions/461203/…
Apr
28
awarded  Popular Question
Jan
15
comment Is there a pattern for a more “natural” way of adding items to collections?
item.AddTo(items) suppose you have a language without extension methods: natural or not, to support addTo every type would need this method and provide it for every type of collection supporting appending. That is like the best example of introducing dependencies between everything I've ever heard :P - I think the false premise here is trying to model some programming abstraction to 'real' life. That often goes wrong.
Dec
31
comment Do ALL your variables need to be declared private?
@supercat good point. Haven't looked at this question for a while, but now I just realize that what you describe, and what the class in my answer does, i.e. just provide some kind of group of public data fields, is basically already builtin in lots of languages: tuple (or even the specialized case for 2 values, pair), or in case of Python even namedtuple. Especially the latter is semantically and functionally pretty much exactly the same as the class in the answer. This just again shows there's definitely a need for such types.
Dec
24
comment Safety-critical software and optimising compilers
Regarding third point: in the last couple of years alone I already filed a couple of optimization bugs to compiler vendors, and that's just me. Searching for 'gcc optimization bug' etc also reveals the problem is most definitely real.
Dec
23
comment Non-Object Oriented Programming in Object Oriented Language
Just a note, when you're leaning towards a bunch of if/else or switch statements, it's always an option to consider some sort of lookupt table. So another way to rewrite that goes along the lines of var dict = new Dictionary<string,Action<UserInfo>{ { "email", callEmailFunction }, { "sms", callSmsFunction } }; dict[ action ]( userInfo ); (dict can be static, error handling omitted)
Dec
21
comment readability vs shorter code in returning from function
@user949300 I know what you mean, but that is maybe not the best way to put it. Counterexample: if this gets called 10 million times in a loop but I'm only going to look at the output after a year, for some reason, it's still plenty fast and I shouldn't waste time on any worries.. Usually the principle is: don't do anything if there's no performance problem which manifests. If there is, measure. Then decide what needs fixing.
Dec
21
comment readability vs shorter code in returning from function
@Jules gooed point. Especially because I consider the second much, much clearer :] If the first would have been formatted in multiple lines it would be more readable though.
Dec
17
comment Are all magic numbers created the same?
At this point (24, 1024 etc) it sort of becomes a matter of preference I guess.. I'd still prefer a constant (not a #define btw) like numberOfHoursPerDay instead of just 24.
Dec
12
answered VCS - Better way to change location than pushing to branch?
Dec
10
comment Is there ever a reason to use an array when lists are available?
+1, often I have some operation for a couple of objects of the same type which are not in a collection. It's easy, short and clear to write foreach( var x in new []{ a, b, c ) ) DoStuff( x ) or new []{ a, b, c ).Select( ... ) etc
Dec
9
awarded  Enlightened
Dec
9
comment Allow iteration of an internal vector without leaking the implementation
+1, this is a pretty nice and safe implementation
Dec
9
comment Allow iteration of an internal vector without leaking the implementation
@BЈовић by not exposing the complete vector - hiding does not necessarily mean the implementation has to be literally hidden from a header and put in the source file: if it's private client cannot access it anyway
Dec
9
awarded  Nice Answer
Dec
8
comment Class design - should methods call other methods?
It's not really 'abstracting' the DB, that's one step further, I rather meant things even as simple as using a string constant instead of blatantly copy/pasting the complete query string so that when you have to change the string you have to do it in one place only (though in this case I'd just make a single function which executes the query and allows iteration over all resulting elements or so) - for the exeption handling: I don't really have sources for that, I also don't know php at all :]