jaredpar's WebLog

Code, rants and ramblings of a programmer.

Browse by Tags

Tagged Content List
  • Blog Post: Don’t mix await and compound assignment

    The 5.0 release of C# introduced the await keyword which makes it extremely easy to use Task<T> in a non-blocking fashion.  This allows developers to replace either blocking calls to Task.Wait() or complicated combinations of ContinueWith and callbacks with a nice simple, straight forward...
  • Blog Post: Not all “true” are created equal

      During a review of some low level bit manipulation logic a developer raised a question about the correctness of a piece of code which allowed any arbitrary byte to be seen as a bool.  No one could recall if true was defined as not 0 or simply 1.  If it was the latter then the code was...
  • Blog Post: Yet another way to defeat C++ const

    One of my favorite C++ features, and one I feel is terribly underutilized in many code bases, is the const mechanism.  It’s a great mechanism for defining dual roles for the same object type: a mutable and (ideally) non-mutable one.  But as useful as const is it’s also very easy to circumvent...
  • Blog Post: Interesting Late Binding Scenario with ToString

    Not to long ago I received an email from a customer who wanted to report a bug in the VB.Net debugger.  They believed that there was a bug invoking ToString on Integer types in the immediate window and provided the following sample as evidence i = 100 ? i 100 {Integer} Integer: 100 ? i.ToString...
  • Blog Post: Disable copy construction when the type is not copy safe

    A couple of days ago I finished coding up a feature in our C++ code base, hit F5 and was met with a nasty memory corruption debugger dialog. After about an hour of investigation it appeared one of my types was living past the lifetime of it’s owning heap. I decided the next step was to debug on...
  • Blog Post: Avoiding automation bugs when implementing IOleCommandTarget

    Shortly after Visual Studio 2010 shipped I wanted to experiment with the new VSIX format for traditional Package extensions.  I fired up my copy of Visual Studio, ran through the new package project wizard.  But instead of a nice shiny new project I was greeted with a project load error dialog...
  • Blog Post: Nothing is private in the debugger

    The goal of the debugger is to provide rich inspection capabilities for a process.  The main method of inspection is through the evaluation of textual expressions which is handled by a language specific component known as the expression evaluator . This component is the data provider for a good...
  • Blog Post: Type safety issue when assigning CComPtr<T> instances

    Recently while making a bug fix to our selection tracking code I discovered an unexpected behavior with CComPtr<T> instances.  The crux of the fix included creating a new tracking mechanism exposed via COM in the type ISelectionTracking.  The old interface, lets call it IOldTracking,...
  • Blog Post: Code Smell: Psychic classes

    Psychic classes have the appearance of ignoring data provided to it in an attempt to provide you with an answer they predict is better for the situation.   It’s impossible to look at a the data provided to an instance of the class and understand what queries on the object will return because...
  • Blog Post: Is it Serializable?

    I’ve recently run across several APIs that have a dependency on only dealing with objects that are serializable (in the binary sense).  Unfortunately determining if an object is serializable is a non-trivial task and rife with problems.  These problems have a direct impact on the types of guarantees...
  • Blog Post: Properly handling a WinForms Timer event

    The WinForms Timer class allows the user to perform a particular action at a set interval.  Timer objects fire a Tick event at the set time which users can easily respond to.  This is very useful if a developer wants to check for a particular condition say every 2 seconds ( for the remainder...
  • Blog Post: Redefining Success

    Spent about an hour debugging a bit of code today.  I was attempting to read data from a particular source and kept getting back failure codes.  After some debugging I discovered the data didn't actually exist in the source I was reading from.  This put me back to investigating where I...
  • Blog Post: When can you catch a StackOverflowException?

    Answer: When you're the one who threw it.  Starting with the CLR version 2.0, the policy for handling a StackOverflowException was changed.  User code can no longer handle the exception[1].  Instead the CLR will simply terminate the process.  This is not 100% true though.  User...
  • Blog Post: Regular Expression Limitations

    I'm struggling with an introduction line to this blog post so I'm just going to go for bluntness:  Regular expressions are limited and it's important to understand these limitations.  Ok, now that the premise is out of the way, lets go to a sample. For a time in college I was a teaching assistant...
  • Blog Post: A Lesson in Serialization

    A few days ago, I recklessly added a [Serialization] attribute to a few of my immutable collection types.  I needed to pass data between AppDomain's and adding [Serialization] was the quick and dirty fix.  Compiled, ran and I didn't think much about it.  Luckily I was updating some unit...
  • Blog Post: Don't mix using statements and lambda expressions

    Title pretty much says it all but what good is a rule without any explanation. The main issue here is that at the core, using statements and lambda expressions both alter variable lifetimes. Unfortunately they alter the lifetime in different directions. Using will shorten the life time of a variable...
  • Blog Post: Bit by void*

    Recently I got bit by void* again because of another C++ quirk I didn't think through.  I had a class which wrapped a void* which could be one of many different structs.  The structs were POD and didn't have any shared functionality hence I didn't bother creating an inheritance hierarchy. ...
  • Blog Post: Gotcha: CComAutoCriticalSection and copy constructors

    While investigating a crash during a suite run I found the stack walk included the destructor for a CComAutoCriticalSection . This is a fairly reliable class so I immediately suspected my code. I did a couple of quick checks for a double free and didn't find any. Then I looked a little closer at CComAutoCriticalSection...
  • Blog Post: Immutability and ReadOnlyCollection<T>

    I am a huge fan of read only/immutable collections and data. Hopefully the increased exposure through the blogosphere alerted users to the advantages of this type of programming for the appropriate scenarios. I wanted to discuss ReadOnlyCollection<T> in case devs looking around in the BCL discover...
  • Blog Post: Gotcha: Generic overload resolution when called generically

    Both VB and C# have a feature of generic overload resolution that is fairly helpful and yet a source of gotchas. Lets say you have two methods with the same number of arguments. One method has arguments with generic types and the other does not. For Example: class C1 <T> { public void F1( int...
  • Blog Post: Gotcha: CComPtrBase<T> assignment

    Today what started out as a crash due to a pure virtual call turned into finding a gotcha in CComPtrBase<T>. Essentially the code in question boiled down to the following. Can you spot the problem? void GetAStudent(CComPtrBase<T> &spStudent) { CComPtr<Student> spLocal; // Do...
  • Blog Post: Get-Content and File Names

    Another day, another PowerShell feature discovered.  Unfortunately this time it was a feature that made me think I had a bug in my script.  The script read through some directories, did some file parsing and created a data object for every directory in the form of a Tuple .  One of the...
  • Blog Post: Calling Extension Methods on Null Objects

    One of the gotchas for Extension Methods is that it's legal to call them on Null References. This isn't really surprising when you think about the feature. Boiled down to a fundamental level, extension methods are just syntactic sugar for calling a static method and automatically passing the first parameter...
Page 1 of 1 (23 items)