Abstract
DESCRIPTION:
The introduction of generics was met with lots of opinions but I could never find a good spot to use them in my code that wasn’t more than slices.Contains[T]() or such; small functions and not a whole journey of functionality through several modules. When the opportunity provided itself I was keen to grab it and was delighted to find just how useful generics could be!
This talk is about generics on a larger scale, from the API layer to business logic and database. How using generics helped us write less code, what problems they introduced and how we went about solving them.
I will present the audience with my initial problem, having a lot of different endpoints with different payloads but similar functionality, and how I wanted to avoid making a `switch payload.(type)` -kind of code or generate lots of code to deal with different data structures. Generics provided the solution, but it was a path of learning to deal with the limitations they brought on, and in my talk, I will explain them and how we solved them.
I hope to inspire any developers facing similar issues to look at generics as a solution and to learn from our expectations, problems and solutions to have a better view of how they could be used. My examples demonstrate to other developers how generics can be easy to use to write robust and resilient code with ease. I walk them through the initial solution of having a single model that affects the underlying functionality and then expand on it to have several: the original model and the derived models for API responses and requests.
The ‘spiky’ in the name of the talk is because I plan to use lots of hedgehog images in my talk due to my love of them, and provide a way of storytelling the whole talk as a hedgehog going on an adventure, facing challenges and overcoming them in the quest to write clean, efficient, robust and resilient code. At the start, the hedgehog faces a problem with many similar endpoints and data structures and decides to create a template to produce a lot of files with minor adjustments, but feels like this is not the right solution. She stumbles into generics and they provide her with the perfect solution for writing elegant and robust code with easily understandable structure and without messy switch..case or if statements. She meets more problems when she needs to implement request and response models derived from the original one, but the solution is as simple as eating a mealworm for lunch! In the end, she gains the admiration and respect of the rest of the forest.