Tag: c#

C# 9.0 Immutable Records – Yes!

Mads Torgersen, C# Lead Designer recently posted about development for upcoming C# 9.0. There’s a whole bunch of features that made me say Yes, Do It, When Can I Get It, Just Yes! But first a story to explain why I’m so enthusiastic. F# What? I thought this was about C#! Patience, grasshopper… Project Last year I was lucky enough to build a small system in F#. I work for a large company with development mostly in C# and TypeScript. We’re in the middle of a major shift into the cloud so there’s a lot of learning going on for…

Read More »

Teaching .NET Dispose Better

I’ve been struck recently by strong parallels between how resource handling and exception safety are usually taught and presented in C++ and in .NET, or more accurately how poorly I think they are often taught. This post focuses on .Net and the Dispose pattern. I’ll look at C++ in a future post. What’s Wrong with the .NET Dispose Pattern? The .Net Dispose Pattern is the standard resource-management pattern for C# and VB programmers, taught as an essential technique to new developers. I think it is unnecessary and promotes bad programming practices. // Full IDisposable pattern from https://msdn.microsoft.com/en-us/library/fs2xkftw%28v=vs.110%29.aspx // For Reference…

Read More »

Contrasting Active Objects vs Tasks vs Actors

Contrasting ideas helps me see what’s special about each idea and what they have in common but maybe in different forms. Different tools, different languages show off different ideas, and while some work best with specific language features there’s always something to help in other languages in my day-job. So today I’ve been thinking about some models of concurrent programming. The Coursera course on Reactive Programming explored the Actor model and I’m contrasting that with the Active Object pattern from POSA2 which I saw in detail in another Coursera course last year and with Tasks which have quickly become one…

Read More »

WPF/Silverlight Layout Gotchas

Coming from WinForms or even older technologies like MFC, WPF and Silverlight are a revelation. A consistent framework to layout simple forms, draw graphics, add video and 3D images and animation and styling. All in the same window. Woo! But there some places where WPF and Silverlight behave differently to initial expectations and which can waste a lot of developer time or even put some off entirely from experimenting with them. Interactive Demo Most layouts in WPF use a Grid control. It’s very flexible and has a lot of powerful features. The classic demos for WPF for WinForms developers show…

Read More »

Experiments with Silverlight

So how easy is it to take a WPF project and run it as Silverlight instead? As with so many things – it depends. OK, so the code I converted was fairly trivial and completely unrepresentative but it was interesting to see just how easy it can be, and how frustrating it can be. How things change Basic classes Exception – in .Net – Serializable, in Silverlight – not so much. So simple exception subclasses need conditional code. I wasn’t expecting problems with code quite so trivial. My approach was basically try and compile it and if it broke flip…

Read More »

Improvements in UI

I’ve been playing with WPF. I’ve seen some good talks and demos of quite beautiful user interfaces and wanted to start getting some practical experience. I’ve also read a lot about the MVVM pattern which sounds like it gives a clean, easily understood separation of display and code, reducing those moments when you look at something and have to ask “should this be in the model or the controller/presenter?” So new project. I’m going to write Noughts and Crosses. On a computer. Because no-one’s ever done that before! Ok, so not very original but the point was to give a…

Read More »