-
Extract a logic from collections processing
Once again, you as a developer, get a task to simplify the below code: You can simplify a little with streams: but this is not what we want to achieve, because the logic/condition is sunk in collection processing and testing is not easy and as you see, leads to testing many cases (good client, bad…
-
Functional programming styles
Your task as a developer is to write a code for selecting clients that have a good credit history and age is above 30 and live in NY city. You wrote a code like this: A senior programmer seeing your code: You know that programmers don’t express any emotion, so you start to think that…
-
Do not clutter production code with test code
As a developer, you are writing new functionality. The implementation is ready, but you have to write tests. To simplify the tests, you create additional helpful methods in one of the production class: Completed. Code review – comments are not allowed, removed. Merged. After some time … a problem appeared in production. The financial report…
-
Pure function
What is a pure function? What are its advantages? Why include logic in a pure function is awsome? The answers you will find in this post. The story. You, as a perfectionist developer, are wandering how to simplify the following class and testing, that is not very easy: You you feel that it could be…
-
Pass all parameters to function
Your task is to simplify the testing of this function logic: How easy is it to test this function? Not complicated, but not trivial either. We can use mocking: As you can see, a certain amount of test code is needed. This example is simple, but imagine that you have more complex logic and classes…