The Idiocy of Python's Function Parameter Specification

By Xah Lee. Date: . Last updated: .

Language design. In python, you can define a function with unspecified number of unnamed keyword parameters, like this:

# -*- coding: utf-8 -*-
# python

# use 「**‹name›」 to receive unspecified number of keyword arguments
def ff(**ddd):
    # ddd is received as a dictionary
    return ddd

print ff( z = 8, c = 7, aa = 4, b = 3) # {'aa': 4, 'c': 7, 'z': 8, 'b': 3}

but, why'd anyone want to do that? No language i know of that lets one define, read:

UNSPECIFIED NUMBER of UNNAMED BUT NAMED parameters

But let's say we do need it. But in that case, just pass one dictionary!

wouldn't that be a simpler design with same power?

what's more, is that python also lets you define unspecified number of positional parameters, as well as keyword parameters, as well as any of all the above mixed.

But, is it simple as that? No. It gets very hairy. Each way you define them, your function receives the arg in a different way. You function may need to process a n-tuple data type, or hash table. Also, in the definition, the parameter needs to be in a particular order.

so, in summary, the syntax is complex, each case has a special form, and the semantics is complex, each case your function body need to process the args in a different way.

complexer and complexer.

really, positional param and keyword param is sufficient. When needed, programer can pass list or hash table. That really solves all problems, yet without introducing any complexity to the lang's syntax and semantics.

Perl and Ruby are both better here.

https://plus.google.com/+XahLee/posts/2yrSbkjuK2K discussion