266 reputation
25
bio website
location Prague, Czech Republic
age 39
visits member for 2 years, 1 month
seen Jun 12 at 20:43

Enthusiastic developer at NCR, spending most of his time around machine-to-machine interfaces. Published an arcane book in computational complexity.


Aug
10
comment Why is the use of abstractions (such as LINQ) so taboo?
@MatthewPatrickCashatt - Performance drop is simply a kind of an abstraction leak. It's an extra prolific case because standards generally leave detailed performance levels undefined and it is not always clear what is the "correct" way of coding or compiling a construct performance wise. Example? Compare a performance of a prepend-loop and append-loop with a StringBuilder in .NET 2. No difference. Compare the same code in .NET 4.0. Drammatic difference that you could not reasonably have expected as it is an implementation detail of the abstraction.
Aug
2
comment Return magic value, throw exception or return false on failure?
@Virtlink - As per my answer. If the method body is just a few cycles, I'd probably choose TryXxx if I could not return a null or a natural magic value. If it's heavy-weight, I am using exceptions all the time, and I LOVE the unhandled stacktraces that I occasionally see in defect reports compared to corrupt heap or swallowed negative numbers in some other code. Mind you, this is just one team's preference. Find yours.
Aug
2
comment Return magic value, throw exception or return false on failure?
@Virtlink - Agreed on thread safety in general, but given that you referred to .NET 4 in particular, use ConcurrentDictionary for multi-threaded access and Dictionary for single threaded access for optimal performance. That is, not using ``Contains` does NOT make the code thread safe with this particular Dictionary class.
Aug
2
comment Return magic value, throw exception or return false on failure?
@gbjbaanb - Experimented finished. I was lazy and used mono on Linux. Exceptions gave me ~563000 throws in 3 seconds. Returns gave me ~10900000 returns in 3 seconds. That's 1:20, not even 1:200. I still recommend thinking 1:100+ for any more realistic code. (out param variant, as I had predicted, had negligible costs - I actually suspect that the jitter probably had optimized the call away completely in my minimalistic example if there was no exception thrown, regardless of the signature.)
Aug
2
comment Return magic value, throw exception or return false on failure?
@gbjbaanb - Well, maybe. That article uses a 1% failure rate to discuss the topic which isn't an entirely different ballpark. My own thoughts and vaguely remembered measurements would be from the context of table-implemented C++ (see Section 5.4.1.2 of this report, where one problem is that the first exception of its kind is likely to start with a page fault (drastic and variable but amortized one time overhead). But I'll do and post an experiment with .NET 4 and possibly tweak this ballpark value. I already stress the variance.