MRMCD2024 No More Loopy Code: Data Science Goes Functional

Learn how functional programming concepts like pure functions, immutable state, and declarative patterns can make your data science code more robust, testable and maintainable.

Key takeaways
  • Functions in functional programming should be small, pure and declarative - making them easier to verify, test and debug

  • Data science workflows commonly involve chaining transformations like filtering, mapping and aggregating data - functional programming provides clean patterns for these operations

  • Using immutable state and avoiding global variables makes code more maintainable and less prone to errors

  • Map and filter are core functional programming concepts that allow operating on collections of data in a declarative way

  • Functions can be composed together into pipelines, making complex data transformations more readable and maintainable

  • Functional code is often easier to parallelize since pure functions can run independently without side effects

  • There’s no need to go “100% functional” - start by gradually introducing functional concepts that provide value

  • Strong type systems in functional programming help catch errors early in data transformations

  • Small, pure functions are easier to reason about in isolation compared to large imperative functions with side effects

  • While functional programming has a learning curve, it can make data science code more robust and maintainable in the long run