Refactoring is King!

I love Refactoring Code. I just love it, it feels really good to enhance code you have written a while ago. I am using swift quite a while now and I must admit that optionals keep me busy. This is partly due to the fact that the code for Drumsetlist Manager is now consisting in parts from the beginning of Swift where I did use optionals not in the, let’s say, optimal way.

And here the fun part starts: when you learn how to use the cool Swift concepts in the complete right way your code gets more stable and even shrinks. And less code is good code, not only Clean Code is saying that 🙂

So what did I change? Well instead of unwrapping my optionals with:

If let aPreset = tmpPreset {
  /// Do Something useful
}

I am now using the guard statement:

guard tmpPreset else {
  return nil
}
// Do the useful stuff now here

This is basically the same thing but I also changed to the latest Swift feature where I just need to unwrap the variable itself without introducing a new variable, so cool!

Happy refactoring!

Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *