[swift-evolution] Proposal: Introduce User-defined "Dynamic Member Lookup" Types
Benjamin G
benjamin.garrigues at gmail.com
Tue Dec 5 06:32:50 CST 2017
On Tue, Dec 5, 2017 at 12:48 PM, Benjamin G via swift-evolution <
swift-evolution at swift.org> wrote:
>
>
> On Tue, Dec 5, 2017 at 4:30 AM, Chris Lattner via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> > On Dec 4, 2017, at 5:22 PM, Joe DeCapo via swift-evolution <
>> swift-evolution at swift.org> wrote:
>> >> The first one, has no static type info, no compile time checking, it's
>> not self documenting, no type inference so people will be forced to use a
>> dynamic reference at the call site to store the result, leading to more
>> type loss, and all this spirals down.
>> >> I'm already starting to fear dynamic.
>> >> Edit: The danger has passed (Phew!) ... and dynamic wasn't been abused
>> after all, no need to down vote me after 3 years :)
>> >
>> > From what I can gather, `dynamic` is used when declaring types, but
>> there's no indication at call sites that what is being invoked is dynamic.
>> And it even allows for casting basically anything to the `dynamic` type.
>> >
>> > https://docs.microsoft.com/en-us/dotnet/csharp/language-refe
>> rence/keywords/dynamic
>> >
>> > So here we have a language community that was (is?) very vocal about
>> caution when it comes to type inference with `var`, but seems to have
>> accepted the validity of `dynamic`. This seems to show that at least one
>> community has absorbed this sort of change (arguably a more "dangerous"
>> version than what is being proposed here) with no real issues.
>>
>> Right. dynamic in C# is far broader (and more “dangerous”) than what I’m
>> proposing. That said, because there have been absolutely zero specific
>> examples of the sorts of harm DynamicMemberLookup could cause, it is
>> difficult to speculate about exactly which boogieman people are afraid of.
>>
>> > So I have a few questions:
>> >
>> > - Would it be enough to require annotation of the dynamic nature of a
>> type at the declaration sites, if that still means the call sites aren't
>> explicitly annotated?
>>
>> It is impossible to solve a problem if it cannot be explained in enough
>> detail to provide examples. Personally, I don’t see the problem at all.
>>
>> > - Why do some think the Swift community would be more at risk of abuse
>> of this feature than the C# community seems to have been?
>>
>>
>> People are making bizarre claims about what the spirit of Swift is,
>> informing me of things which are obviously not true, and ignoring the
>> evidence I present to them. This is doubly humorous given that I have a
>> fairly good sense for the design balance and tradeoffs of existing features
>> in Swift today, along with detailed rationale for why they were added,
>> when, and all of the discussion that backed them. I chalk this up to the
>> fear of the unknown or perhaps a mistrust for the peers these people work
>> with.
>>
>
> For what i'm concerned, let's be very clear : i do not consider my
> personal opinion to matter AT ALL compared to what people like you, who
> code compilers for a living, think. And i feel even more embarrassed
> participating in that conversation since it's about a language you
> invented. I've only done it because people in the core team said it would
> be interesting.
> Now, the only area where I may have more experience than people like you,
> is working with the average programmer, in the industry. And my personal
> experience shows that what a language doesn't enable is as important as
> what it enables (because every feature that can be abused will be,
> eventually and in ways nobody can expects).
>
> Regarding your proposal regarding the impact it could have on pure swift,
> i think it comes down to letting the developer masquerade dictionaries into
> proper structs or classes. I tried to recreate a dynamic BaseDynamicObject
> based on dictionaries and your new protocols, but it's pretty hard without
> the finished implementation (i will try to recompile swift using your pull
> request wheneve i got the time, if i feel people are sincerely interested).
> The "benevolent" purpose for doing that would be anything regarding
> mocking, proxying, mixins objects and their properties. There are various
> examples of those patterns in every dynamic languages.
>
> About C#, in which i did program a few years ago (but before dynamic was
> in the language), it already had powerful metaprogramming and introspection
> capabilities, as well as very convenient generics and interfaces ( easier
> to work with than what swift offers today, but that was a long time ago so
> my memory may be wrong). So, in some way, the potential for abusing dynamic
> or "stringly typed" programming was a lot lower.
>
>
>
>
>>
>> My goal is to make the design and proposal writeup as good as possible,
>> and the fear mongering about abuse has led me to add several options for
>> further narrowing the potential for abuse, including to the point of
>> requiring every new adoptee to go through the Swift evolution process for
>> review. During the review period for DynamicMemberLookup, people who carry
>> these concerns are welcome to +1 one or more of those.
>>
>
Forgot to answer that part.
"Have the compiler specifically bless individual well-known types, e.g.
Python.PyVal (or whatever it is eventually named) by baking in awareness of
these types into the compiler. Such an approach would require a Swift
evolution proposal to add a new type that conforms to this."
+1
I think there are a very finite number of programming languages Swift would
like to have this kind of interop with, and i think having every new case
reach into core team would also be a good opportunity to reevaluate that
part of the language. IIUC, this is also the most controlled version of the
proposal, and it prevents all abuses, while enabling the most seamless
experience for python developers. So, it looks perfect to me.
>
>> I personally am far more interested in getting to the bottom of Doug’s
>> concerns - it isn’t clear to me what exactly his preferred direction
>> actually is, but that discussion is based on engineering tradeoffs and may
>> well lead to a change to the proposal or a complete change in direction.
>>
>> -Chris
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
>
> _______________________________________________
> 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/20171205/cab77c80/attachment.html>
More information about the swift-evolution
mailing list