Alexito's World

A world of coding 💻, by Alejandro Martinez

Some interesting proposals for Swift

Since Swift was open sourced I've ben scanning trough the mailing lists and there has been some interesting proposals for the future of the language. There are other places were people summarizes the conversation, but I just wanted to write here the proposals that are the most interest to me.

Deriving / newtype

This is one of the most interesting ones for me. This will solve a lot of the issues that I’ve found myself when trying to write code that relies on the type checker for almost every type (Solving the Strings Problem in Swift and Type Systems and Domain Driven Development). That means no generic numbers or strings.

One of the issues with that is that is quite verbose to make a custom type behave like another. This will hopefully solve a lot of those pain points and will help us rely a lot more in the type system.

Method cascading

This is a technique to have fluent interfaces but way better than the ones provided by returning self in the setters. One of the bigger improvements is that the designer of the API doesn’t have to think about this usages beforehand. This allows the user of the API to use fluent interface if they want even if the designer didn’t thought about that use case.

One of the most interesting aspects for me, and that I still don’t know if this will solve, is the possibility that this could improve the usage of large inits, for those objects that have some dependencies or simply models will a lot of properties.

Swift at compile time

I opened a conversation about the ability to run Swift at compile time. That would substitute any future macro system and will allow anybody to use the language that already knows and love to make things at compile time.

I was surprised that the idea was not immediately rejected and I will love to see this being talked again after Swift 3.

Improvements on enum values

Since the begging of Swift enum has been the one of the most interesting types, but it still has its limitations ( Mainly no ability to inspect the list of cases or even the number of cases. It has received some improvements to dela with Strings that has been really nice, but there is still some things to be done in that realm.

If you liked this article please consider supporting me