Follow Us
Categories
Archives
- February 2024
- January 2024
- August 2023
- December 2022
- November 2022
- October 2022
- February 2022
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- January 2021
- November 2020
- October 2020
- August 2020
- April 2020
- February 2020
- January 2020
- October 2019
- September 2019
- July 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- October 2018
- September 2018
- August 2018
- July 2018
- April 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- April 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- November 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- February 2013
- January 2013
- November 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- December 2011
- November 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
Author Archives: Glennan Carnie
Practice makes perfect, part 3 – Idiomatic kata
Previously, we looked at some of the foundational C++ code kata – that is, elements of C++ coding that are absolutely key to master if you’re going to be programming in C++.
Practice makes perfect, part 1 – Code kata
Practice makes perfect, part 2 – foundation kata
In this article I want to introduce what I call ‘idiomatic’ kata. These exercises have a bit more latitude (and variation) in how they can be implemented. In that respect they are closer to traditional […]
Posted in C/C++ Programming, Design Issues, training
Tagged Code kata, exercises, Modern C++. C++11. C++14, training
Leave a comment
Practice makes perfect, part 2 – foundation kata
In the previously article we looked at the need for repetitive practice – code kata. In this article I want to present some of my preferred foundational kata.
If you’re a beginner to C++ I recommend you fully internalize all these examples before having a look at the idiomatic kata.
If you’re a more experienced C++ programmer you may be looking at these kata and thinking “Jeez – these are so basic! Who couldn’t do this!”. Bear in mind though – we […]
Posted in C/C++ Programming, Design Issues, training
Tagged Code kata, exercises, Modern C++. C++11. C++14, training
1 Comment
Practice makes perfect, part 1 – Code kata
Imagine you’re at a Jazz club, enjoying a smooth jazz quartet. It’s time for the sax player’s solo. All of a sudden, he stops the band, rifles in a bag a pulls out a book of music theory.
“What the?!” you think.
The saxophonist looks to the audience, “I’ve just got to look up the notes for E-flat minor. I can never remember them.”
It’s understandable you’re unlikely be too impressed with this particular musician.
If you’re a musician, a sportsperson, a dancer, martial […]
Posted in C/C++ Programming, Design Issues, training
Tagged C++, Code kata, exercises, Modern C++. C++11. C++14, practice
3 Comments
Function function return return values values*
The latest C++ standard is now upon us, so it’s time to have a look at some of its new features.
To put one of the new features into context we’re going to have a look at – as the title suggests – multiple function return values
I should really distinguish between the following:
A Subroutine (or Subprogram) is a parameterised block of code that can be called multiple times from within a program.
A Procedure is a subroutine that may have multiple input […]
Posted in C/C++ Programming
Tagged C++17, C++2a, Function return values, Modern C++. C++11. C++14, structured bindings
Leave a comment
Contract killing (in Modern C++)
If you work in high-integrity or safety-critical software then you have a duty-of-care to:
Ensure your code does what it should
Ensure your code doesn’t do what it’s not supposed to.
Moreover, you’re typically required to both demonstrate and document how you’ve achieved this duty-of-care. Typical mechanisms for demonstrating compliance include unit testing and static analysis; documentation usually includes function specifications and test results. The amount of testing, static analysis and documentation you (have to) do depends on the integrity level of your […]
Posted in C/C++ Programming
Tagged assert, attributes, C++11, C++14, C++17, C++20, C++2a, Contracts, deprecated, ensures, expects, maybe_unused, Modern C++, nodiscard, noreturn
3 Comments
Celebrating 10 years – my top 10 blog articles
It’s difficult to believe we’ve been writing articles for 10 years. In that time I’ve written over 90 technical articles on C, C++ and embedded system design.
To celebrate I’ve picked my ‘Top 10’ articles, with a little background into why I enjoyed writing them so much, or the story behind them.
So, sit back, cue up “At the Sign of the Swinging Cymbal“* and enjoy.
(* This really dates
Posted in C/C++ Programming, Design Issues, Testing, UML
Tagged arrays, casting, forwarding, Modern C++. C++11. C++14, move semantics, priority, Testing, unit test
Leave a comment
Brace initialization of user-defined types
Uniform initialization syntax is one of my favourite features of Modern C++. I think it’s important, in good quality code, to clearly distinguish between initialization and assignment.
When it comes to user-defined types – structures and classes – brace initialization can throw up a few unexpected issues, and some counter-intuitive results (and errors!).
In this article, I want to have a look at some of the issues with brace initialization of user-defined types – specifically, brace elision and initializer_lists.
Read on for more…
Like (4)
Posted in C/C++ Programming, General
Tagged brace elision, brace initializer syntax, C++11, C++14, C++17, initialization, Modern C++, std::initializer_list
1 Comment
Thanks for the memory (allocator)
One of the design goals of Modern C++ is to find new ways – better, more effective – of doing things we could already do in C++. Some might argue this is one of the more frustrating aspects of Modern C++ – if it works, don’t fix it (alternatively: why use lightbulbs when we have perfectly good candles?!)
This time we’ll look at a new aspect of Modern C++: the Allocator model for dynamic containers. This is currently experimental, but has […]
A brief introduction to Concepts – Part 2
In part 1 of this article we looked at adding requirements to parameters in template code to improve the diagnostic ability of the compiler. (I’d recommend reading this article first, if you haven’t already)
Previously, we looked at a simple example of adding a small number of requirements on a template parameter to introduce the syntax and semantics. In reality, the constraints imposed on a template parameter could consist of any combination of
Type traits
Required type aliases
Required member attributes
Required member functions
Explicitly listing […]
Posted in C/C++ Programming
Tagged C++, C++20, C++2a, concepts, generic programming, Modern C++, requires, Templates
4 Comments
A brief introduction to Concepts – Part 1
Templates are an extremely powerful – and terrifying – element of C++ programs. I say “terrifying” – not because templates are particularly hard to use (normally), or even particularly complex to write (normally) – but because when things go wrong the compiler’s output is a tsunami of techno-word-salad that can overwhelm even the experienced programmer.
The problem with generic code is that it isn’t completely generic. That is, generic code cannot be expected to work on every possible type we could […]
Posted in C/C++ Programming
Tagged C++, C++20, C++2a, concepts, generic programming, Modern C++, requires, Templates
Leave a comment