Re: [heycam/webidl] Add a section on overloads vs. union/optional (#426)

annevk commented on this pull request.

I'm somewhat surprised @domenic is in favor of this. I thought there was some agreement that overloads were a bad idea generally.

> +</pre>
+
+the [=overload resolution algorithm=] would treat the <var ignore>path</var> argument as not present
+given the same ECMAScript language code <code>stroke(undefined)</code>, and not throw any
+exceptions.
+
+Additionally, there are semantic differences as well. [=Overloaded=] operations are designed to map
+well to language features such as C++ overloading, and are usually a better fit for operations with
+more substantial differences in what they do given arguments of different types. [=Union types=], in
+contrast, are usually used in the sense that "any of the types would work in about the same way".
+
+That being said, we offer the following recommendations and examples in case of difficulties to
+determine what Web IDL language feature to use:
+
+*   When the operation must return values of different types for different argument types,
+    [=overloaded|overloading=] is almost always a better choice.

I think we should recommend separate operations instead. I don't think overloads are generally a good idea as they lead to weird edge cases around optional arguments.

> +</pre>
+
+the [=overload resolution algorithm=] would treat the <var ignore>path</var> argument as not present
+given the same ECMAScript language code <code>stroke(undefined)</code>, and not throw any
+exceptions.
+
+Additionally, there are semantic differences as well. [=Overloaded=] operations are designed to map
+well to language features such as C++ overloading, and are usually a better fit for operations with
+more substantial differences in what they do given arguments of different types. [=Union types=], in
+contrast, are usually used in the sense that "any of the types would work in about the same way".
+
+That being said, we offer the following recommendations and examples in case of difficulties to
+determine what Web IDL language feature to use:
+
+*   When the operation must return values of different types for different argument types,
+    [=overloaded|overloading=] is almost always a better choice.

And different return value types also doesn't seem like a good pattern necessarily.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/426#pullrequestreview-58583902

Received on Friday, 25 August 2017 07:25:46 UTC