C# 11 is the next version of C# coming in .NET 7, and it is introducing a warning wave that issues a warning when a type is declared with all lower-case letters. This is being done so that in the future the language can begin moving away from conditional keywords and instead use full on keywords instead. The warning is alerting customers to types that may become keywords in future versions. C# has…
One request I see fairly often for C# is to add the concept of borrowed values. That is values which can be used but not stored beyond the invocation of a particular method. This generally comes up in the context of features which require a form of ownership semantics like stack allocation of classes, using statements, resource management, etc … Borrowing provides a way to safely use owned values…
Often I see developers debating using String vs. string as if it’s a simple style decision. No different than discussing the position of braces, tabs vs. spaces, etc … A meaningless distinction where there is no right answer, just finding a decision everyone can agree on. The debate between String and string though is not a simple style debate, instead it has the potential to radically change the…
C# 7.2 added the ability to mark a struct declaration as readonly . This has the effect of guaranteeing that no member of the struct can mutate its contents as it ensures every field is marked as readonly . This guarantee is imporant because it allows the compiler to avoid defensive copies of struct values in cases where the underlying location is considered readonly . For example when invoking…
At first glance some customer crash reports look simply impossible. The code in question is so throughly tested or on such a common code path that it simply can’t be broken. If it were broken customers would be breaking your inbox with crash reports. Deeper inspection though almost always reveals that indeed it is a bug in the code. Perhaps there is a race condition, a machine configuration issue,…
It seems silly to celebrate features which should have been there from the start. But I can’t help but be excited about adding deterministic build support to the C# and VB compilers. The /deterministic flag causes the compiler to emit the exact same EXE / DLL, byte for byte, when given the same inputs. This is a seemingly minor accomplishment that enables a large number of scenarios around content…
Errors are the mechanism by which compilers communicate incorrect program to users. Good error messages educate the user about the issue and ideally tells them how to correct it. This is the optimal situation because it allows users to self correct their code. Bad error messages though typically just state the problem, possibly quite cryptically, without any corrective advice and are little better…
A reference assembly is a slimmed down version of an implementation assembly that contains the API surface but no real code. A program can reference these assemblies at compile time but cannot run against them. Instead at deploy time programs are paired with the original implementation assembly. Breaking up assemblies into reference and implementation pairs is a useful tool for creating targeted…
One of my favorite bits of .NET trivia is whether or not it is possible to observe a null value for this ? Most developers I ask either say no, or yes but it requires incorrect IL / unsafe code. Since I’m writing this post you can probably guess that the answer is actually yes, this can indeed be null . To demonstrate this behavior let’s start with a simple command line application: class Program…
Recently I was confused about the interaction between Task and CancellationToken . In particular I couldn’t remember if a Task which was already running was marked cancelled as soon as the associated CancellationToken was cancelled or if it waited until the Task completed. The documentation wasn’t much help so I decided to write up a quick program to test out the behavior: static void Main (…
Debugging MSBuild is usually a three step process: Turn on diagnostic verbosity ( /v:diag ). Piping the gargantuan amount of MSBuild output to a file. Using your favorite text searching tool to find that one line necessary to diagnose the problem. This method is effective but laborous. However this method really only works if the build file can get to the point of processing <Target> elements. If…
A consistent coding style is one of the most undervalued components of a maintainable code base. Code should always be optimized for readability as developers spend far more time reading code than writing it. Having a consistent style helps here because it establishes conventions and locations for well known programming elements. When taken individually items like the naming of fields, the…
For the last four years I’ve been a part of a research team exploring extensions to the C# language. The effort focussed on adding features that improved the reliability, performance and overall correctness of the language. Like any good research project we had some features that were incredibly successful, some which were so-so and others that … well … they failed spectacularly! The project was…
Good developers are always on the look out for unnecessary code. Both to avoid in their own code and to help others avoid during code reviews. One such example is redundant casts: a cast where the type of the expression and cast are the same type. For example: float x = GetValue (); float y = z / ( float )( x * 2 ); The result of x * 2 is a float . Hence the (float) cast here is not changing the…
If you create a VSIX project using the most recent version of Visual Studio on your machine it will spit out a reference section in your project file containing the following: <Reference Include= "Microsoft.VisualStudio.CoreUtility" /> <Reference Include= "Microsoft.VisualStudio.Text.Data" /> <Reference Include= "Microsoft.VisualStudio.Text.Logic" /> <Reference Include=…
A few days ago while discussing VsVim with a coworker it occured to me that I’d been working on this project for 5 years now. It was a bit startling for me because it feels like just yesterday when I finally got permission to release it to the public. After reflecting for a few minutes I decided that I wanted to write a couple of posts on this project and how it shaped up over time. What better…
I joined a discussion recently about a new API being added to a type with well established semantics. The API seemed to violate the key invariants of the type and I was curious about the justifications. Of the various reasons given one in particular stood out to me as questionable: The type can already be used in this manner hence this API adds nothing new to the equation, it just standardizes the…
Easy motion is a plugin for Sublime that allows for quick and simple keyboard navigation within a file 1 . Just 3 key strokes can take you to any visible letter. No neeed for complex regexes or patterns, all you need to know is the letter that you want to navigate to. A user alerted me to this sublime plugin a month or so ago and I immediately started using it. I absolutely loath touching the…
A good portion of my free time, and not so free time, is devoted to Visual Studio extensions. In addition to actively developing them I’m always dogfooding my extensions and those of other developers. On any given day I probably update Visual Studio 3-5 times on various machines with new builds, proposed bug fixes, forks, etc … As with any other repetitive task I like to script this as much as…
One of the fun benefits of running VsVim is that I’m constantly exposed to the amazing ways that vim can be configured. Many bugs in VsVim have to deal with commands that show up in vimrc files. Users are quick to share these files to help in tracking down the bug. The amount of customization that goes into these files is quite daunting and a reminder of just how flexible an editor vim really is.…
To split a line in an ITextBuffer the developer simply needs to insert a recognized new line text into the existing line. Many VSIX extensions just default to Environment.NewLine for this task _textBuffer . Insert ( splitPosition , Environment . NewLine ); This is problematic because this is simply not the only possible new line text. The editor actually recognizes 6 varieties: '\r' , '\n' ,…
The .Net enumeration story based on IEnumerable<T> is a very succesful pattern. It’s the backbone of many different language and framework features including foreach , LINQ, iterators, etc … And yet when switching between C++ and C# and I’m often frustrated by its inefficiencs and quirks: Accessing a single value requires 2 interface invocations: MoveNext and Current. Interface method invocation…
A common bug in VSIX projects is to hold onto an ITextView instance long after it has been closed . This is problematic because it ends up preventing a large number of resources from being collected including the ITextBuffer , language service elements, WPF items, other extension objects, etc … In short it is a substantial memory leak. The vast majority of these leaks occur with the following…
As usual Scott Hanselman wrote a blog post that got me super excited about a new piece of software: AppVeyor . A continuous integration system which had built in integration with github. I couldn’t wait to try it out on a few projects. Getting Builds Working The blog post promised a simple deployment story but I was still skeptical. Many of my OSS projects are VSIX projects (Visual Studio…
There few are phrases in programming that make me shudder more than This type is thread safe Reading this phrase is like hearing nails on a chalk board. It often makes me physically cringe. The phrase thread safe makes it sound like thread safety is on / off property of a type. Nothing could be further from the truth. There is a wide variety of multi-threaded usage scenarios for types that simply…
Inheritting a legacy code base is a rite of passage for developers. This is the event which takes you from the mentality of clean, documented, tested code you wrote during university into the ugly real world of compromises. It is very much a “how the sausage is made” moment My first experience with this was transitioning to the languages team in Visual Studio back in 2006. The C++ code base I…
A short time ago I wrote a post about how to turn a standard VSIX project into one which could be round tripped into any version of Visual Studio. This set of changes also fixed other issues like debugging + SCC, assembly binding, etc … I got a lot of positive feedback and nice links to projects that developers upgraded as a result of my post. While this was working great for developers with…
Lately I’ve been reading a lot about peoples interview processes and it inspired me to share my process for interviewing college candidates. I’ve been doing interviews at Microsoft for ~10 years now and developed this process over that time. The format for the interviews are typically 1 hour with just me and the candidate. Usually in my office or occasionally a conference room. Unfortunately 1…
Visual Studio 2012 introduced project file round tripping feature. This lets developers edit the same project in Visual Studio 2010, 2012 and 2013 without the need to upgrade the project file or modify it in any way. This was a highly requested feature by customers that allowed them to edit their project no matter what version of Visual Studio they had on their machine. The previous forced upgrade…
For the last 6 months the BCL team has been hard at work shipping an out of band release of immutable collections for .Net. Most recently delivering an efficient implementation of ImmutableArray http://blogs.msdn.com/b/dotnet/archive/2013/06/24/please-welcome-immutablearray.aspx Unfortunately with every announcement around these collections I keep seeing the following going past in my twitter…
The 5.0 release of C# introduced the await keyword which makes it extremely easy to use Task 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 expression Task < int > task = ...; int local = await task ; Use ( local ); What most people don’t consider is the…
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 allowing for a large range of invalid bool values to be created. A quick look at the CLI spec revealed the immediate…
As I’ve developed VsVim over the years I’ve authored quite a few reusable Visual Studio components. For the last 6 months I’ve had many of these factored out to a separate utility library and this last week I decided to publish them as a separate NuGet package. Even if no one else every uses the library I want to reuse the utilities in other projects I’m working on and NuGet is the perfect…
I just released an update to VsVim for Visual Studio 2010. This is available on the extension manager in Visual Studio or can be downloaded directly at the following link. 1 Link: http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329 GitHub: http://github.com/jaredpar/VsVim **What does 1.0 mean? ** Several people asked me what 1.0 meant for VsVim’ From the first…
The DebuggerDisplayAttribute is a powerful way to customize the way values are displayed at debug time. Instead of getting a simple type name display, interesting fields, properties or even custom strings can be surfaced to the user in useful combinations [ DebuggerDisplay ( "Student: {FirstName} {LastName}" )] public sealed class Student { public string FirstName { get ; set ; } public string…
I just released an update to VsVim for Visual Studio 2010. This is available on the extension manager in Visual Studio or can be downloaded directly at the following link. Link: http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329 GitHub: http://github.com/jaredpar/VsVim This update includes the following Lots of undo / redo issues Lots of caret positioning…
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 and I’m always interested in learning new ways to do so. While navigating through a stackoverflow question…
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 ( "c02" ) { "Conversion from string " c02 " to type 'Integer' is not valid." } _HResult : -…
I just released an update to VsVim for Visual Studio 2010. This is available on the extension manager in Visual Studio or can be downloaded directly at the following link. Link: http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329 GitHub: http://github.com/jaredpar/VsVim This update includes the following R# 5.1 Support Snippet Support Many fixes to key mapping…
A feature which seems to be getting more requests recently is support for seeing the return value of a function in the debugger without the need to assign it into a temporary. C++’s had this feature for some time but it’s been lacking in managed debugging scenarios. James Manning recently dedicated a couple of blog posts to the subject and noted that the feature appears to already partially exist…
I just released an update to VsVim for Visual Studio 2010. This is available on the extension manager in Visual Studio or can be downloaded directly at the following link. Link: http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329 GitHub: http://github.com/jaredpar/VsVim This update includes the following Full support for :substitute including the confirm option…
Earlier this week I started writing a function which needed to represent three states in the return value, two of which had an associated value. In my mind I immediately came to the following solution type BuildAction = | Reset | LinkOneWithNext of Statement | LinkManyWithNext of Statement seq A discriminated union is perfectly suited for representing this type of scenario. Unfortunately for me I…
In a recent post I discussed the apparent flakiness of extension methods and the debugger being a result of whether or not the DLL containing the extension methods were loaded into the debugee process. Several users asked in the comment section why we didn’t fix the issue by just loading those DLL’s when an extension method was executed. On the surface this seems like a reasonable request. After…
I just released an update to VsVim for Visual Studio 2010. This is available on the extension manager in Visual Studio or can be downloaded directly at the following link. Link: http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329 GitHub: http://github.com/jaredpar/VsVim This is fairly major release from the last announced (0.8.2) which includes the following…
F#’s seq expressions are a frustrating item to inspect at debug time. A seq value is a collection and when users inspect such a value at debug time they want to see the contents of the collection. Instead they are often presented with a view resembling the following The reason this happens is a consequence of how the debugger works. When a value is expanded it essentially enumerates the members…
Interop of delegate style types between F# and other .Net languages is a pain point that results from a fundamental difference in how delegates are represented in the F# language. Typical .Net languages like C# see a delegate as taking 0 to N parameters and potentially returning a value. F# represents all exposed delegates as taking and returning a single value via the FSharpFunc<T,TResult> type.…
Multi-targeting is a feature introduced in Visual Studio 2008 which allows developers to use new versions of Visual Studio to target earlier versions of the .Net platform. It allowed users to target both the new 3.5 and 3.0 and the previous 2.0 profile with the same IDE. Visual Studio 2010 continues this trend by adding support for CLR 4.0 and even allows for further sub-targeting through several…
One source of confusion I find myself clearing up a lot is the use of evaluating extension methods in the debugger windows. Users report evaluation as working sometimes but not others for the exact same piece of code. Such flaky behavior can only be the result of a poorly implemented feature or subtle user error. Right’ Unfortunately no. In this case the behavior described is very possible and ‘By…
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 the heap functions to see where I went wrong. I opened up the file for the heap and almost immediately…
I just released an update to VsVim for Visual Studio 2010. This is available on the extension manager in Visual Studio or can be downloaded directly at the following link. Link: http://visualstudiogallery.msdn.microsoft.com/en-us/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329 GitHub: http://github.com/jaredpar/VsVim This is a bug fix release and contains no large features. Notable Bug Fixes Both normal mode…