[swift-evolution] Epic: Typesafe calculations

Matt Whiteside mwhiteside.dev at gmail.com
Wed Jan 13 22:50:44 CST 2016

Hi Dave,

> On Jan 13, 2016, at 11:37, davesweeris at mac.com wrote:
>  Ok, so… what if “where” clauses in the “inheritance" section forced all the initializers to be failable, and there was an implicit “if !(where clause) { return nil }” inserted at the end of every initializer? It’d cut down on boilerplate code, and it’d tell whomever was looking at the public interface two things: 1) That all the initializers had “universal precondition”, and 2) exactly what that universal precondition is. 

Interesting.  Yes, I had been thinking strictly from the compile time point of view, but something like this on runtime side could provide a lot of benefit too.

> *Yes, I know you can use will/didSet to roll back the changes if the new value fails some validation check. I can’t figure out a way to get those to throw errors, though, nor is there currently a way to have subscript() throw an error (somebody’s already filed a radar about that). Since there’s no way to alert the programmer that the assignment they just performed might not stick, this seems like a colossally bad idea (for general code, anyway… obviously if it works in your specific situation, then go for it).

Without having thought about it too much, I wonder if the new behaviors proposal <https://gist.github.com/jckarter/50b838e7f036fe85eaa3> could be helpful here somehow.  Perhaps this type of validation check could be implemented as a behavior.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160113/05cd5df6/attachment.html>

More information about the swift-evolution mailing list