Leveraging a Functional Approach for More Testable & Maintainable ROS 2 Code
Talkat CppCon 2023 · on Tuesday, 2023-10-03· at 15:15· Cottonwood 8/9, 6700 North Gaylord Rockies Boulevard·
summary
Claims that refactoring a ROS 2 node into pure functions, higher‑order functions, monadic error handling and dependency injection yields 100% coverage, deterministic unit tests and far fewer flaky tests. Uses C++20/C++23 features and a TL::expected polyfill (TL::expected) to return errors instead of logging, moves middleware calls to the edges so core logic is pure, and tests by injecting a mocked middleware handle so no middleware invoked during unit tests.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:08Talk overview
- 3:35Why ROS 2
- 5:21Conventional ROS 2 challenges
- 8:11Problem statement
- 9:34Conventional ROS 2 walkthrough
- 14:29Limitations of conventional approach
- 15:53Testing challenges
- 19:04Functional programming principles
- 23:36Closures and partials in C++
- 25:24Higher order functions
- 29:21Monadic error handling
- 33:57Functional testing benefits
- 34:19Refactoring to functional style
- 38:36Testing without ROS 2 API
- 41:26Key takeaways
- 42:29Q&A
related talks
38mSurgical Refactoring of Non-Tested Code – A Worked Example
25mWriting Testable Code
37mClean Test Code
01h 32mFuture of Testing With C++20
01h 07mPragmatic Unit Testing in C++
01h 02mRefactoring C++ Code for Unit testing with Dependency Injection
01h 03mMaking Hard C++ Tests Easy: A Case Study From the Motion Planning Domain
01h 31mFunctional Programming in Test Automation
