Category: General
-
Area of a triangle
This is a bit specific but that is the way with some algorithms, or formulas in this case. Let’s say you want to calculate the area of a triangle. I’m not sure why. It could be something in a graphics shader for a fancy effect. Winging it It’s been a long time since high school…
-
Diversion ahead
I’m not going to be able to spend as much time on the blog for a bit. Rather than struggle to keep up with the schedule I’m going to drop the schedule for now. I hope to still post occasionally but it won’t be every Tuesday and will be less often. It could mean that…
-
Defer again
I written about defer before. This is a keyword that delays execution of a statement until the end of the block. It’s designed to allow you to perform setup and immediately specify the associated clean up. I thought it made control flow a bit more confusing but could be a useful tool. Simple implementation C++…
-
Missing operator
A couple of weeks ago I was talking about error handling and one option using. short-circuit logic. It had lines that looked like this: But why couldn’t they look like this: While you might understand what that means C++ doesn’t, very few languages do. Short-circuit logic The normal logic operators we deal with are and,…
-
The Law of Demeter
I’ve been doing some more reading and came across the Law of Demeter and train wrecks again. The last time while while reading Clean Code. I’ve one book that tells me this is bad practice: And that I should do this instead: My feeling was to prefer the first as more compact here and it…
-
Error handling
I’ve used a few different error handling techniques since university. Over the last few years a couple of other options have appeared. Lets take a simple problem and see how it works with all of them. A simple problem Let’s say we want to read a text file containing a list of dates and return…
-
Calling functions
I was recently talking about clang-tidy. One of the performance checks it can run is unnecessary-value-param. This makes sense, accidentally passing a big array by value rather than by reference can invisibly ruin the code performance. The rule was pretty easy though, pass simple types by value and everything else by reference. Then along came…
-
The Checklist Manifesto
The Checklist Manifesto is a book from 2010 by author Atual Gawande, an American surgeon and public health researcher. I read it a while ago and it reinforces my belief that we all make mistakes. Unsurprisingly the book is all about checklists. It may not sound like much it can be a great help in…
-
Saving pennies
Imagine your shopping at a different supermarket from normal. You notice that baked beans are 3p per tin cheaper than you’re use to. The news had a story about supermarket price wars on basic goods recently. It’s a bit out of your way but if you switch supermarkets you could save money on beans each…
-
API lock-in
When C# first came out it didn’t have generics, that didn’t come out until version 2.0. That meant that, say, the user interface APIs either had to deal with collections of unknown objects or be use custom written collections. If they did one you don’t know what object you have; if you do the other…