[Pre-RFC] named arguments

I would say this syntax is objectively worse than with kwargs. Not everything is a struct instantiation. To quote a previous example:

// might have headers etc as optional options
http.get("https://www.rust-lang.org/en-US/", timeout: None);

Using a builder pattern would mean changing the API to be quite ugly imo:

let req = HttpRequest::new("https://www.rust-lang.org/en-US/")
   .method(Method::GET)
   .timeout(None)
   .exec();

Another disadvantage of the builder pattern is that you need to implement a fn for each field which can mean lots of code for not much reason.

I would say named arguments (and default args) are one of the main reasons Python libraries like requests or even pandas are so elegant. Making something like http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html simple for both library author and users is quite impressive.

I would say that named arguments really shine when combined with default args though.

3 Likes