[swift-evolution] [Review] SE-0030 Property Behaviors

Aditya Vaidyam avaidyam at purdue.edu
Sun Feb 14 14:58:39 CST 2016


It’s my first time using this mailing list, so please do let me know if I’m doing something wrong.

I personally agree with the `[]` syntax because it allows for something more like `[lazy, atomic]` without having to look a lot like Java annotations (which do something completely different). I think the `@` syntax should be reserved for compiler directives. The `[]` mechanism also could be expanded on like so:

/// abc is both lazy and atomic in behavior
var [lazy, atomic] abc: Int = 1234

/// ^ expands to:
var `abc.lazy` = LazyBehavior<Int> { 1234 }
var `abc.atomic`: AtomicBehavior<Int> { `abc.lazy` }
var abc: Int {
	get { return `abc.atomic`.get() }
	set(val) { `abc.atomic`.set(val) }

That is, in the order of appearance of the behaviors within the brackets, their behaviors will become a composed chain. Now this also means that some behaviors can only be initial or terminal, which must be specified through other syntactical means. In addition:

/// abc has behavior `myBehavior` which requires a parameter
var [myBehavior(parameter: true)] abc: Int = 1234

Again, this also further increases complexity, and possibly the need for a separate `behavior` declaration, instead of piggybacking on `protocol` (it could possibly be similar to `operator` syntax?).

Aditya Vaidyam

Purdue University
College of Science ‘17
Neurobiology and Physiology, Computer Science, Pre-medicine

> On Feb 14, 2016, at 3:36 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> I’m sorry if this has already been discussed, but what are the drawbacks of putting the variable's behaviors before the ‘var’ keyword?  Like this:
>> lazy synchronized var x:SomeType
> With no prefix at all, this limits our ability to introduce declaration modifiers in the future. For instance, if the people clamoring for a `local` access modifier win in Swift 4, anyone who wrote a behavior called `local` will be very sad.
> The other problem is, with this declaration:
> 	lazy var array = [1, 2, 3]
> It offers no way to disambiguate between the two meanings of `lazy`:
> 	array.lazy.reset()
> 	array.lazy.map { ... }
> Personally, if we're not going to use the `[]` syntax, I think we should use the `@` prefix and think of all uses of `@` throughout the language as eventual targets for behavior-ization (even if we don't get around to most of them in Swift 3, or some of them ever). It would be nice to have a rational explanation for what `@` means. But I'm reasonably happy with the `[]` syntax.
> -- 
> Brent Royal-Gordon
> Architechies
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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

More information about the swift-evolution mailing list