#2 Swift code refactor in action - price $$$

#2 Swift code refactor in action - price $$$

Swift code refactor in action 👨🏻‍💻 Today, let’s talk about refactoring for clarity, maintainability, and scalability! This time, the scenario is calculating the final price depending on the price and membership status. This initial code has a few code smells: 1️⃣ nested ifs - impacts general readability, making the code hard to understand, 2️⃣ duplicated conditions - “price > 100” which violates the Don’t Repeat Yourself principle, 3️⃣ lack of scalability - not possible to easily add a new discount, it’d require to rework everything....

December 3, 2024 · 2 min · Maciej Gomolka
#1 Swift code refactor in action - user profile name

#1 Swift code refactor in action - user profile name

Swift code refactor in action 👨🏻‍💻 Common scenario: formatting user profile name - I bet any of you faced this kind of task. At first glance, it look straightforward, but when you take a closer look, you’ll notice two potential improvements: 1️⃣ One single return - simplification of the function flow. 2️⃣ Centralised formatting logic - reduces the chance of bugs. Check out the animated gif and the code where I refactor to address these issues....

November 20, 2024 · 2 min · Maciej Gomolka