From e8574b940f590993e7f048727c4baaa13d39ef50 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Sun, 12 Nov 2023 13:49:00 +0100 Subject: [PATCH] Added Why Do We need This? --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 352a98c5..d7b8f835 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,6 @@ ![image](banner1.png) - - **reflect-cpp** is a C++-20 library for **fast serialization, deserialization and validation** using compile-time reflection, similar to [pydantic](https://github.com/pydantic/pydantic) in Python, [serde](https://github.com/serde-rs) in Rust, [encoding](https://github.com/golang/go/tree/master/src/encoding) in Go or [aeson](https://github.com/haskell/aeson/tree/master) in Haskell. As the aformentioned libraries are among the most widely used in the respective languages, reflect-cpp fills an important gap in C++ development. It reduces boilerplate code and increases code safety. @@ -25,7 +23,22 @@ Design principles for reflect-cpp include: - Simple extendability to custom classes - No macros -## Example +## Why do we need this? + +Suppose your C++ program has complex data structures it needs to save and load. Or maybe it needs to interact with some kind of external API. If you do this the traditional way, you will have a lot of boilerplate code. This is annoying and error-prone. + +reflect-cpp is not just a reflection library, it is for **serialization, deserialization and validation** through reflection. + +That means that you can encode your assumptions in the type system and have them validated upfront. This is why the library also includes algebraic data types like tagged unions and numerous validation routines. Having your assumptions encoded in the type system is the most reliable way of ensuring they are fullfilled. If your assumptions are violated, the user of your software gets a very clear error message. + +This increases user experience and developer experience, it makes your code safer (fewer bugs) and more secure (less prone to malicious attacks). + +For a more in-depth theoretical discussions of these topics, the following books are warmly recommended: + +- *Category Theory for Programmers* by Bartosz Milewski (https://github.com/hmemcpy/milewski-ctfp-pdf/releases) +- *Domain Modeling Made Functional* by Scott Wlaschin + +## Basic Example ```cpp #include