trainings/CreatingReliableSoftwareCpp/Presentation/good_practise_kiss.md

38 lines
No EOL
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# KISS
___
## keep it simple, stupid
* <!-- .element: class="fragment fade-in" --> Writing only enough code to pass a unit test, which relates to TDD and the first SOLID principle Single Responsibility.
* <!-- .element: class="fragment fade-in" --> Intuitive approaches to writing software, approachable and simply understood by everyone.
___
## Small understandable classes and methods
```C++
class ImageStorage {
public:
Image* getImage(const std::string& url) {
const auto it = std::ranges::find_if(images_, [&url](const auto& image) { return image->url() == url; });
if (it != std::cend(images_)) {
return it->get();
}
return nullptr;
}
Image* store(std::unique_ptr<Image>&& image) {
if (const auto* image = getImage()) {
return image;
}
images_.push_back(std::move(image));
return images_.back().get();
}
private:
std::vector<std::unique_ptr<Image>> images_;
};
```
<!-- .slide: style="font-size: 0.74em" -->
<!-- .element: class="fragment fade-in" -->