[ 
https://issues.apache.org/jira/browse/AVRO-2803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chris Hoffman updated AVRO-2803:
--------------------------------
    Comment: was deleted

(was: There's a way I can do this inside the existing `#initialize` signatures.)

> Avro::Schema convenience constructors that only take named parameters
> ---------------------------------------------------------------------
>
>                 Key: AVRO-2803
>                 URL: https://issues.apache.org/jira/browse/AVRO-2803
>             Project: Apache Avro
>          Issue Type: Improvement
>            Reporter: Chris Hoffman
>            Priority: Minor
>
> Between AVRO-2789 & realizing I'd need to add `aliases` as a constructor 
> parameter to `Avro::Schema::NamedSchema` in order to complete AVRO-2651, I 
> really don't want to just keep tacking positional parameters on the end of 
> the `#initialize` signatures for the various `Avro::Schema` subclasses. 
> Ideally the `#initialize` signatures would contain only named parameters and 
> no positional parameters. Getting rid of the positional parameters and only 
> using named parameters would have several benefits:
>  # It would make knowing you've called a complicated constructor (like 
> `Avro::Schema::RecordSchema#initialize`) correctly simpler to determine. The 
> vast majority of Ruby developers don't use IDEs or text editors that 
> automatically look up method signatures on mouse-over. Whether or not you 
> think they should, that's the reality, and personally, it would be much 
> easier if I didn't have to look up the signature and could just provide named 
> parameters.
>  # It would create a uniform constructor interface for all the `Avro::Schema` 
> subclasses. You don't have to check that constructor to remember where the 
> type map dictionary is; if you know how to call one, then you know how to 
> call all of them.
>  # Will decrease the amount of per-subclass logic baked into 
> `Avro::Schema.real_parse`. Currently it has to know a fair amount about each 
> subclass to extract the attributes from `json_obj` to satisfy that subclass' 
> constructor signature. If we could just pass `json_obj` to the constructor, 
> that would be much simpler.
> Now obviously we can't actually change the signature of `#initialize` for all 
> the `Avro::Schema` subclasses in a breaking manner (and this would obviously 
> be a breaking manner) without giving developers who maintain libraries built 
> on Avro time to migrate.
> I propose that I create `::build` convenience constructors for each subclass 
> that will take only named parameters and know how to call their specific 
> class' `#initialize` method with the correct parameters order. That way we 
> can at least contain the pain of dealing with these awkward positional 
> signatures all in one place for each subclass.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to