Thanks! Then looks very interesting and I’ll reach out to the lead there and 
see if they’re interested in working together. It definitely highlights similar 
readability issues I had outlined. I’m curious if there are compiler or other 
advantages to initializing more properties before continuing in the scope. For 
example race conditions, mulitthread support, concurrency... If you want to 
initialize more of an object than any single initializer allows being able to 
create it and set all desired properties before the system denotes it as 
officially initialized might be helpful. This would make a distinction between 
the init then { // do something} model verses init with { // do this to create 
it }.

-Weston

> On Jan 3, 2016, at 9:09 PM, Adriano Ferreira <adriano.ferre...@me.com> wrote:
> 
> Hey there!
> 
> As a suggestion, check out this simple yet very interesting project called 
> Then <https://github.com/devxoul/Then> by @devxoul.
> 
> Best,
> 
> — A
> 
>> On Jan 3, 2016, at 1:37 AM, Weston Catron via swift-evolution 
>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
>> 
>> Ability to write an initializer while initializing an object.
>> 
>> Example
>> 
>> let name = “John Apple”;
>> let person = Person {
>>     self.name = nameInput.first() + " " + nameInput.last()
>>     self.dob = dateInput.datetime()
>>     If (self.age() > 18) {
>>         self.taxableStatus = INDEPENDANT
>>     } else {
>>         self.taxableStatus = DEPENDANT
>>     }
>> };
>> 
>> Helpful examples: Objects with many required parameters that are defaulted 
>> in the initializers. 
>> 
>> SKLabelNode
>> 
>> let label = SKLabelNode(text: "Example") 
>> label.position = CGPoint(x: 0, y: 250); 
>> label.fontSize = 34; 
>> label.fontColor = UIColor.blackColor() 
>> self.addChild(label);
>> 
>> Can become:
>> 
>> let label = SKLabelNode(text: self.package!.title) {
>>     self.position = CGPoint(x: 0, y: 250)
>>     self.fontSize = 34
>>     self.fontColor = UIColor.blackColor() 
>> }
>> self.addChild(label)
>> 
>> Readability Instead of a large amount of code setting up temporary variables 
>> to pass into an initializer, all initializing code could be wrapped in a 
>> closure.
>> 
>> Flexibility Instead of exhaustive initializers covering many use cases. 
>> Simpler initializers can be extended as needed. This can also encourage 
>> required properties over optional ones that are immediately defined. 
>> 
>> Compiler Warnings Closures react the same as initializers within classes, 
>> warning users of incomplete implementation of required properties.
>> 
>> Possible disadvantages:
>> 
>> Sloppy Coding Instead of writing complete initializers programmers can just 
>> rely on in-line initializers.  
>> 
>> Tried Before I found this feature is also available in C# 
>> (https://msdn.microsoft.com/en-us/library/bb397680.aspx 
>> <https://msdn.microsoft.com/en-us/library/bb397680.aspx>). Not sure if it 
>> was helpful then but many languages since don't appear to use it. 
>> 
>> -Weston
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org <mailto:swift-evolution@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to