[
https://issues.apache.org/jira/browse/THRIFT-242?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12659569#action_12659569
]
Jonathan Ellis commented on THRIFT-242:
---------------------------------------
1) True, but since this addresses a special case of the "having the constructor
silently do nothing if nonsense is passed" problem, I think it's worth causing
(very) minor trouble if someone is actually explicitly passing {} -- or worse,
a non-empty dict or any other value, all of which have the same effect! Which
illustrates the problem. Basically, if they are doing any of those things, it
is an error, and we are not doing them a favor by preserving the existing
behavior.
(Obviously we also break back-compat for any parameters named "d.")
2) This is a stylistic preference; IMO, it's more clear (for users of help() as
well as code divers) to have d be an empty instance of the type it expects, but
certainly there is a lot of Python code out there that does things the way you
suggest. (You didn't bring up performance as an argument, but for the record,
the extra if may be more or less performant depending on what the common case
is, so I think that is a wash.) I don't much care here since ultimately I want
the d argument to go away. :)
3) Good catch.
> Python struct constructors are clunky and error-prone
> -----------------------------------------------------
>
> Key: THRIFT-242
> URL: https://issues.apache.org/jira/browse/THRIFT-242
> Project: Thrift
> Issue Type: Improvement
> Components: Compiler (Python)
> Reporter: Jonathan Ellis
> Attachments: init.patch
>
>
> The python constructors are clunky and unnecessarily difficult to use.
> Instead of
> Cls(value1, value2, ...)
> you must write
> Cls({'arg1': value1, 'arg2': value2})
> (or use the dict constructor instead of literal notation).
> Additionally, having the constructor silently do nothing if a non-dict is
> passed in (an object of the type being created would be another reasonable
> guess) or if an argument is mis-spelled causes users unnecessary trouble
> debugging.
> Since removing the d argument entirely would be backwards-incompatible, the
> attached patch keeps it, but puts real keyword parameters in for
> forwards-compatibility. Thus, old code will work with this patch, but new
> code can be written using keyword args that will still work when the d
> argument is removed in a release that allows backwards-incompatibility.
> (Removing the d argument is desireable because otherwise positional arguments
> can't be used.)
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.