Skip to content

atomic lint iterative methods

hgratten requested to merge atomic_lint_iterative_methods into master

this merge request introduces the clang-tidied iterative methods chapter

LectureCodes/IterativeMethods/*

  • removed cmake_minimum_required(VERSION 2.8), since the cmake version is better handled by the global CMakeLists.txt file
  • reordered includes as good practice (user header first, then system headers, ordered alphabetically
  • wrapped body statement of if-else, for, do while, and while in braces. increases readability and forgetting braces is a common source of bugs for students
  • lifted all things thrown to derive from std::exception, since the C++ standard library's exception handling mechanism is designed around the std::exception base class and otherwise leads to problem in catching (e.g. does not allow polymorphic catching)
  • introduced const wherever possible
  • put functions in header files in a separate namespace if there are using directives, to avoid clutter in the global namespace and clarify dependencies in main files
  • inlined functions in header file to avoid potential ODR (one-definition-rule) violations: since functions are defined directly in the header, including it from multiple translation units would cause multiple definitions, which inlining avoids by duplicating the definition per translation unit
  • integer type hygiene (use Eigen::Index for indexing)
  • avoided multiple declarations in a single line for readability
  • avoided uninitialized variables, instead used NAN to initialize doubles or -1 to initialize indices. this is more likely to show up as an error than accidentally using unitialized memory

LectureCodes/IterativeMethods/dampnewton/Eigen/main.cpp:

  • wrapped calls to exception-throwing functions in a try catch block to avoid exception thrown in main and subsequently crashing. although this is somehat intended behavior for short numerical codes, it is advisable to never intentionally crash programs but to handle exceptions explicitly, since this leads to more readable code as programs get larger and program flow more complicated

LectureCodes/IterativeMethods/mtc/Eigen/wfunction.cpp:

  • replaced M_E by the more modern std::numbers::e and avoid usage of the non-standard _USE_MATH_DEFINES alltogether
Edited by hgratten

Merge request reports

Loading