Named Parameters vs. Positional Parameters

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Named parameters or positional parameters?

Named! functionCall(b=2, a=1);
Positional! functionCall(1, 2);
No votes
Total votes: 29

Posts: 79
Joined: Thu Jun 21, 2012 5:09 pm UTC

Named Parameters vs. Positional Parameters

Postby willaaaaaa » Thu Jun 21, 2012 5:44 pm UTC

Take a side and stick with it to the bitter end.

User avatar
Posts: 426
Joined: Thu Nov 15, 2007 8:34 pm UTC
Location: Massachusetts

Re: Named Parameters vs. Positional Parameters

Postby tetsujin » Thu Jun 21, 2012 11:29 pm UTC

Named can make calling interfaces very versatile and the significance of the parameters very easy to discern, and positional can make them very compact (which can also lead to improved clarity under certain circumstances).

So, both. Python is awesome.

(One case where I dealt with named parameters in Python was dealing with the serial library. I couldn't tell you the right order for the calling arguments when creating a serial port object, but supplying named arguments makes it pretty easy to get up and running without a major hassle.)
I want to create a truly new command-line shell for Unix.
Anybody want to place bets on whether I ever get any code written?

Posts: 28
Joined: Fri Jun 22, 2012 5:13 am UTC

Re: Named Parameters vs. Positional Parameters

Postby ycc1988 » Fri Jun 22, 2012 5:33 am UTC

Named parameters allow for simple use of default values. For example, a plotting function may have default font faces, line styles, etc. MATLAB/Octave doesn't have true named parameters, but gets around this with some clever (i.e. annoying to implement) parsing.

User avatar
My HERO!!!
Posts: 5198
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Named Parameters vs. Positional Parameters

Postby Xanthir » Mon Jun 25, 2012 11:33 pm UTC

Both. Positional parameters for the arguments that are absolutely necessary. Named optional params for *everything* else. And, for consistency, let the required parameters be nameable too.

I agree - Python is awesome in this respect.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Posts: 1510
Joined: Sun Oct 19, 2008 5:28 pm UTC
Location: Space Florida

Re: Named Parameters vs. Positional Parameters

Postby Quizatzhaderac » Tue Jul 17, 2012 6:44 pm UTC

If I had to pick one: positional.

That said I don't see good reasons not to have both. Though it does seem that positional has a relative advantage for strongly typed languages and named for weakly typed. In Java, a method that takes a bean, a string, an int, then a boolean is a lot clearer than a ruby method that takes an object, a second object, another object, then finally an object.
Last edited by Quizatzhaderac on Tue Aug 19, 2014 8:20 pm UTC, edited 1 time in total.
The thing about recursion problems is that they tend to contain other recursion problems.

User avatar
Posts: 1692
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: Named Parameters vs. Positional Parameters

Postby Jplus » Mon Jul 23, 2012 1:13 pm UTC

I'm missing the otter/duck option. Named parameters can be useful but positional ones are fine too, so really I couldn't care less. :)
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 2 guests