Repository navigation
WIP: updates2026 - #177
WIP: updates2026#177mmcleod89 wants to merge 30 commits into
Conversation
mmcleod89
commented
Nov 9, 2026
- Adding preliminaries / CS background notes
- Maths background
- Data representation
- Floating point rep is now front loaded here
- Function Representation
- Moving materials around to match new time table
20DM
left a comment
There was a problem hiding this comment.
Thanks for putting these additions together, @mmcleod89 - they all look useful to me. I've added a bunch of suggestions, nerd comments and corrections for typos etc. Happy discuss more when you had a chance to review the review 😅
|
|
||
| ## Strings and Characters | ||
|
|
||
| A single character can be represented using `char`, which takes a single byte. For strings you are advised to use the C++ type `std::string`. In some places you will come across `char*`, an C-style array of `char`, as an alternative to C++ strings. These should only be used where necessary for compatibility. The most common place for this to come up is command line arguments for the `main` function. |
There was a problem hiding this comment.
| A single character can be represented using `char`, which takes a single byte. For strings you are advised to use the C++ type `std::string`. In some places you will come across `char*`, an C-style array of `char`, as an alternative to C++ strings. These should only be used where necessary for compatibility. The most common place for this to come up is command line arguments for the `main` function. | |
| A single character can be represented using `char`, which takes a single byte. For strings you are advised to use the C++ type `std::string`. In some places you will come across `char*`, a C-style array of `char`, as an alternative to C++ strings. These should only be used where necessary for compatibility. The most common place for this to come up is command line arguments for the `main` function. |
There was a problem hiding this comment.
Also, nerd comment: char* is technically a pointer to char, not really an array. Perhaps worth reminding them that the pointer itself carries no length information and could point at rubbish...
There was a problem hiding this comment.
I did originally write up a bunch of stuff about pointers but I was worried that this is the prelim material and they don't know what a pointer is yet. I only really included char* because I was worried they would see it in command line arguments. Perhaps it's better to defer char* to later to avoid confusing them? Most of the time they should be using std::string anyway nowadays.
There was a problem hiding this comment.
Fair - I suppose we would anyway cover it on the first day via a little Hello world program, so maybe we don't even need to cover it in the prereqs then.
| # Basic Types in Programming Languages | ||
|
|
||
| In order to effectively work in any programming language, we need a basic understanding of a number of fundamental types. We will give these types by the names in C++, although there are generally analogues in other languages. | ||
|
|
There was a problem hiding this comment.
Maybe we should add here something like:
The size and range of some C++ types depend on the implementation. We describe common choices on modern desktop and server systems below, and mark these as "typically". Use
sizeof(T)to inspect a type's storage size in bytes andstd::numeric_limits<T>from<limits>to inspect its numerical properties.
?
|
|
||
| - `int`: integers that can be positive or negative, and take 4 bytes of memory. | ||
| - `unsigned int`: integers that can only be positive, and take 4 bytes of memory. Because they don't have to represent negative numbers as well, `unsigned int` can represent larger values than `int`. | ||
| - `std::size_t`: unsigned integers that can represent that size of the largest possible object; this is usually determined by the addressing on an architecture. For example, on a 64-bit system `size_t` will typically be 8 bytes. This is the standard type to use for things like indexing arrays/vectors since it can't be negative and is guaranteed to be able to represent the largest index of an element of an array. |
There was a problem hiding this comment.
Suggest to add something like
Care is needed with subtraction and comparisons involving signed integers. When you only need to visit each element of a container, prefer a range-based for loop.
|
|
||
| ### Floating Point Precision | ||
|
|
||
| Higher precision floating point numbers (like `double` as opposed to `float`) will give more accurate results when doing numerical work, but may also be slower to perform operations. Historically `double` operations have taken more time to compute than `float` operations, although this is no longer typically the case on modern CPUs. Nevertheless, if you are exploiting SIMD registers for maximal performance, fewer `double` values can fit in an available register and therefore fewer operations can be performed in a given amount of time. Some fast algorithms use single precision `float` or even half precision floating point numbers in areas where the results will not be significantly impacted by this. This is particularly common in areas like statistics and machine learning where the statistical variance is much larger than the precision of the floating point numbers. You must always bear in mind that the use of lower precision floating point types can lead to numerical instability from cancellation errors or division/multiplication by extreme values causing under or overflow. You should always have tests for robustness and precision to check that any compromises made to precision are acceptable. |
There was a problem hiding this comment.
| Higher precision floating point numbers (like `double` as opposed to `float`) will give more accurate results when doing numerical work, but may also be slower to perform operations. Historically `double` operations have taken more time to compute than `float` operations, although this is no longer typically the case on modern CPUs. Nevertheless, if you are exploiting SIMD registers for maximal performance, fewer `double` values can fit in an available register and therefore fewer operations can be performed in a given amount of time. Some fast algorithms use single precision `float` or even half precision floating point numbers in areas where the results will not be significantly impacted by this. This is particularly common in areas like statistics and machine learning where the statistical variance is much larger than the precision of the floating point numbers. You must always bear in mind that the use of lower precision floating point types can lead to numerical instability from cancellation errors or division/multiplication by extreme values causing under or overflow. You should always have tests for robustness and precision to check that any compromises made to precision are acceptable. | |
| Higher precision floating point numbers (like `double` as opposed to `float`) can reduce rounding error when doing numerical work, but may also be slower to perform operations. Historically `double` operations have taken more time to compute than `float` operations, although this is no longer typically the case on modern CPUs. Nevertheless, if you are exploiting SIMD registers for maximal performance, fewer `double` values can fit in an available register and therefore fewer operations can be performed in a given amount of time. Some fast algorithms use single precision `float` or even half precision floating point numbers in areas where the results will not be significantly impacted by this. This is particularly common in areas like statistics and machine learning where the statistical variance is much larger than the precision of the floating point numbers. You must always bear in mind that the use of lower precision floating point types can lead to numerical instability from cancellation errors or division/multiplication by extreme values causing under or overflow. You should always have tests for robustness and precision to check that any compromises made to precision are acceptable. |
There was a problem hiding this comment.
Suggest to add something like the following for perspective:
Precision also affects how much memory a calculation needs. For example, storing an array using 32-bit rather than 64-bit numbers halves the memory needed for its elements. This can allow larger problems to fit into a GPU's limited memory and reduce the amount of data that must be moved during a calculation, potentially improving performance. The rapid growth of AI has accelerated interest in lower-precision hardware and algorithms, including their use in scientific computing. Many algorithms use mixed precision: lower precision for much of the work, with higher precision retained for sensitive steps. The aim is to reduce computing costs while still meeting the accuracy requirements of the application; this must be checked for the problem being solved.
| - Optimisation often takes significant work: it is much slower to write a highly optimised implementation than a straight-forward one. | ||
| - Optimised code is often unintuitive and therefore harder to understand for new users. This also makes maintenance harder, especially if it is not obvious what can and can't be changed without breaking the optimisation benefits! | ||
| - Highly optimised code may not be portable, as code may be optimised for specific platforms, architectures, or even individual machines. | ||
| - KISS (Keep It Simple, Stupid) is a good principle for first drafts: focus on writing _correct_, understandable code first. |
There was a problem hiding this comment.
| - KISS (Keep It Simple, Stupid) is a good principle for first drafts: focus on writing _correct_, understandable code first. | |
| - "Keep It Simple" is a good principle for first drafts: focus on writing _correct_, understandable code first. |
20DM
left a comment
There was a problem hiding this comment.
Thanks for putting these additions together, @mmcleod89 - they all look useful to me. I've added a bunch of suggestions, nerd comments and corrections for typos etc. Happy discuss more when you had a chance to review the review 😅
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
…th-cpp into mm_updates2026
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>
…th-cpp into mm_updates2026
Co-authored-by: Christian Gutschow <64213771+20DM@users.noreply.github.com>