38 lines
No EOL
1.1 KiB
Markdown
38 lines
No EOL
1.1 KiB
Markdown
# 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" --> |