Ben Bowen's Blog
• Home / Blog •
• About •
• Subscribe •
Software Engineering
Game Design
Personal
View All Tags
Popular Highlights
Complete C# Quick Reference - C# 11
August 2023
// Summarizing features in C# 11, including an in-depth look at ref fields and scoping rules.
Common Multithreading Mistakes in C# - III: Unsafe Assumptions
February 2017
// An in-depth look at exactly what the CPU and runtime can do to subvert us when we don't write properly thread-safe code
Fun With __makeref
May 2016
// Explanation on how to use hidden C# keywords to implement generic pointers and related functions
Complete C# Quick Reference - C# 12
// Summarizing features in C# 12.
Software Engineering
• Monday 27th November 2023
.net
c#
Compared to some previous releases, C# 12 is quite a small, incremental update to the language. Here's the feature summary: You can now define a "primary" constructor for a non-record
class
or
struct
alongside the name of the type (similar to the primary constructor syntax for records):...
Complete C# Quick Reference - C# 10
// Summarizing features in C# 10.
Software Engineering
• Saturday 22nd January 2022
.net
c#
I put this one first as it's been on my personal wishlist for
years
. It's probably the thing I've always missed the most from Java and it always frustrated me that no other C# engineer I ever spoke to seemed to care!...
Complete C# Quick Reference - C# 8
// Summarizing features in C# 8.
Software Engineering
• Sunday 28th March 2021
.net
c#
This feature is a large addition to C# that is aimed at helping prevent null reference exceptions at runtime by adding compile-time correctness checking. To enable nullable checking in a project, add
<Nullable>enable</Nullable>
underneath the target framework declaration in the .csproj file: Alternatively, for existing codebases that you want to slowly convert to nullable-checked, compile-time directives can enable/disable this feature in source:...
Complete C# Quick Reference - C# 5 and C# 6
// Summarizing features in C# 5 and C# 6.
Software Engineering
• Monday 22nd March 2021
.net
c#
This feature is a mainstay of C# and has had such an impact on the industry that it's found its way in to other mainstream languages. There are countless tutorials and books that go deep in to this feature; but this post is just meant as a quick reference guide, so I will only summarize it here....
C# 8 Concerns - A Followup
// Revisiting the C# 8 Concerns post from two months prior
Software Engineering
• Tuesday 13th November 2018
.net
c#
About two months ago I made a post explaining some concerns I had with two new features in C# 8 (the range/hat operator and default interface methods). If you haven't read that post, I recommend reading it first before coming back here: C# 8 Concerns....
Postmortems - Tale of Two Casts
// A deep-dive in to a rare difference between the way the CLR and C# handle a given cast
Software Engineering
• Thursday 1st June 2017
.net
c#
About a year ago I came across a bug that took me a while to get to the bottom of. Look at the following code and see if you can predict the output:...
Postmortems - Absolutely Wrong
// An investigation in to a small bug encountered when creating Escape Lizards
Software Engineering
• Wednesday 10th May 2017
c#
When handling input for XBOX controllers in Escape Lizards, I had to tilt the level/environment according to the direction the left analog stick was being held. The left-analog stick's position is returned via the XInput API as two 16-bit signed integers (
short
s), one for each axis (
x
and
y
)....
Common Multithreading Mistakes in C# - III: Unsafe Assumptions
// An in-depth look at exactly what the CPU and runtime can do to subvert us when we don't write properly thread-safe code
Software Engineering
• Saturday 11th February 2017
multithreading
performance
c#
In this series, I'm going to be elucidating some common errors C# programmers make when working with multithreaded systems. I'll be exploring issues from a lower-level point-of-view, and not dabbling too much in higher-level abstractions and libraries (such as the TPL and similar); hopefully the points raised will be pertinent to anyone hoping to write concurrent or parallelized applications....
Common Multithreading Mistakes in C# - I: Incorrect Granularity
// A higher-level overview of the lock keyword and how it is commonly misused
Software Engineering
• Sunday 3rd July 2016
multithreading
performance
c#
In this series, I'm going to be elucidating some common errors C# programmers make when working with multithreaded systems. I'll be exploring issues from a lower-level point-of-view, and not dabbling too much in higher-level abstractions and libraries (such as the TPL and similar); hopefully the points raised will be pertinent to anyone hoping to write concurrent or parallelized applications....
Three Garbage Examples
// Three examples and explanations of situations that can create unnecessary garbage in .NET4/C#5
Software Engineering
• Friday 8th April 2016
performance
.net
c#
C# (and any language that runs on the CLR) is a garbage-collected language, meaning that objects that have no references to them remaining will have their memory reclaimed at some point in the future. Creating too much garbage (by creating too many ephemeral objects or over-using the
new
keyword) can induce the garbage-collector too frequently, slowing down the entire application....
P/Invoke Tips
// Assorted accrued tips on using P/Invoke in C#
Software Engineering
• Monday 18th January 2016
native interop
performance
.net
c#
Not very many C# programmers will ever need to do much with P/Invoke (Microsoft's technology for interoperation with legacy or native codebases), but for those of us who do, I've amassed a few little tips that aren't always included in the various tutorials found on the 'net....
Complete C# Quick Reference - C# 11
// Summarizing features in C# 11, including an in-depth look at ref fields and scoping rules.
Software Engineering
• Saturday 19th August 2023
.net
c#
This new feature allows you to specify that a property or field of a class/struct/record
must
be set in an object initializer: So when is this useful? In my opinion, the right time to use this is when: The benefits here are: ...But what if we want to offer an
optional
constructor that helps set the required members with some simple processing? Here's an example:...
Complete C# Quick Reference - C# 9
// Summarizing features in C# 9.
Software Engineering
• Wednesday 31st March 2021
.net
c#
This new syntax allows creating properties that can be set using object initialization syntax, but never again: Init-only properties can also have access modifiers applied, just like regular setters: This small feature lets you omit the 'boilerplate' in your program's entry-point (i.e.
Main()
function). Here's a before and after to demonstrate:...
Complete C# Quick Reference - C# 7
// Summarizing features in C# 7.
Software Engineering
• Thursday 25th March 2021
.net
c#
Tuples are structures that contain a set of two or more related objects. They're useful for handling or returning multiple related values that would not usually be related together in to a class or struct. What if we want to pass a tuple to another function or store it in a container? We can declare a tuple type using a similar syntax:...
Complete C# Quick Reference - C# 2, 3 and 4
// Summarizing features in C# 2, C# 3 and C# 4.
Software Engineering
• Friday 19th March 2021
.net
c#
These allow you to specify
null
as a potential value on any struct variable (where
null
would otherwise be invalid):...
C# 8 Concerns
// Elucidation on some concerns with upcoming new features planned for C# 8
Software Engineering
• Saturday 15th September 2018
.net
c#
In the following post I'm going to talk about two concerns I have with features planned for C# 8. Beforehand though, I just want to point out a couple of things: Also for previous subscribers, I'm sorry for the huge hiatus in blogging. I've been busy with work and all my spare time has been going in to patching my game. That's finally done however so hopefully normal service will be resumed. :)...
Postmortems - Clearly Too Slow
// An example of a simple everyday operation that needed micro-optimising in my game engine
Software Engineering
• Wednesday 24th May 2017
performance
c#
In my game engine, the following code was called once every frame for every material in the game. We had an average of about 500 materials in most scenes; so on a high-end machine this one function was being called about
100,000 times a second
. C# can definitely handle it (ask any high-scale web developer), but as you can imagine the method had to be fast (especially as we wanted to support average-to-low-end desktops):...
Common Multithreading Mistakes in C# - IV: Everything Else
// A look at some miscellaneous unexpected gotchas when writing multithreaded code
Software Engineering
• Sunday 23rd April 2017
multithreading
performance
c#
In this series, I'm going to be elucidating some common errors C# programmers make when working with multithreaded systems. I'll be exploring issues from a lower-level point-of-view, and not dabbling too much in higher-level abstractions and libraries (such as the TPL and similar); hopefully the points raised will be pertinent to anyone hoping to write concurrent or parallelized applications....
Common Multithreading Mistakes in C# - II: Unnecessary Contention
// Exploring the basics of what makes different approaches to parallelism more or less efficient
Software Engineering
• Friday 14th October 2016
multithreading
performance
c#
In this series, I'm going to be elucidating some common errors C# programmers make when working with multithreaded systems. I'll be exploring issues from a lower-level point-of-view, and not dabbling too much in higher-level abstractions and libraries (such as the TPL and similar); hopefully the points raised will be pertinent to anyone hoping to write concurrent or parallelized applications....
Fun With __makeref
// Explanation on how to use hidden C# keywords to implement generic pointers and related functions
Software Engineering
• Friday 13th May 2016
performance
c#
C#'s list of keywords is ever-growing, but there is also a set of four hidden (dark) keywords that have been in the language since its earliest days that not so many people are aware of. Those keywords are: Today we'll be looking at
__makeref
and its two companion keywords
__reftype
and
__refvalue
. We won't be looking at
__arglist
today....
Simulating Multiple Inheritance In C#
// A longform post describing the need for and implementation of MI in C#
Software Engineering
• Sunday 21st February 2016
oop / api design
c#
Before I begin, I need to point out that this post is lengthy, and is written as a kind of "journey through examples". This is for those who want to understand the reasoning behind the eventual final implementation and perhaps learn about C# along the way. If you, like me, prefer to jump straight to some source code, you can skip to the final implementation first (use the table-of-contents on the right), and perhaps come back after. :)...
© Ben Bowen 2016 to
DateTime.Now
•
About
•
Subscribe
•
RSS