Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Contents tagged with C#

  • Why I dislike tuple return types

    Tuples are great additions to C#. They're simple immutable structures made of a small number of members organized in a specific order. For example, a point on a plane could be represented as a pair of X and Y coordinates, or a person's name could be represented as a title, first, middle and last names. If the types are that simple, and have no custom logic associated with them, using a tuple looks like a lightweight and simple implementation that requires a lot less effort than a simple class or struct. Dynamic and functional languages have long enjoyed tuples, of course, but I like how the C# implementation manages to stay true to the core tenets of the language, in particular type safety.

  • Why I prefer spaces to tabs

    Coding convention discussions are always fun. I just had one of them on the weekly Orchard meeting, where I’ve joked that spaces are objectively superior to tabs, by which I meant that there are objective arguments in favor of spaces that I find subjectively compelling..

  • Sprinkling some C#6 fairy dust on FluentPath

    I moved my FluentPath library’s source code from CodePlex to GitHub, and while I was at it, I vacuumed a bit, removed the cobwebs, and decided to see what applying some C#6 goodness would do to my code. Usually, I would not advise anyone to touch existing, working code that way just for the sake of using the new features: if it ain’t broke… But I wanted to kick the tires, you know? Just don’t start sending people pull request with that sort of crap, that would just be rude ;)

  • A quick helper to work on JSON streams

    Newtonsoft’s JSON library provides lots of different ways to read JSON documents, including a SAX-like way to work with the document by reading it forward-only: JsonTextReader. This is very advantageous if you’re working with very large documents, especially if they are being streamed from a remote source. Using this kind of API, there is no need to have the whole document loaded in memory at once. The downside is that those API are usually quite unfriendly and low-level: you usually have to move a cursor and read values manually. This is not just tedious, it’s also brittle and typically creates excessive coupling with the structure of the JSON document. Last week, I had to read a large JSON document, and I wanted to explore better ways to perform such tasks, which led me to write a small set of helper methods that make it a lot easier to walk JSON documents using Newtonsoft’s JsonTextReader.

  • Reducing friction

    Great libraries don’t just package useful functionality in a re-usable package, they do so while reducing friction. Low friction means that the answer to “hey, wouldn’t it be great if you could just do X?”, is “yes, it would, and you can.” Doing something simple is never complicated, and the way to do it is easily found, if not plainly obvious. Using such libraries is a joy, never a struggle. Of course, getting results like those is far from being easy, and requires smart designs and clean implementations. Most of all, it requires the library author to put himself in the shoes of his users.

  • Deriving from a fluent class

    Here’s an interesting one, and maybe you can help me make my design less crappy. I have this library that I’m a little proud of, called FluentPath. It’s a fluent wrapper around System.IO that enables you to manipulate files not unlike how jQuery manipulates the DOM, with operations over sets, and lots of functional concepts: