The Idiocy of Python's Function Parameter Specification

, , …,

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 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 & 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 & semantics.

Perl & Ruby are both better here.

g+ discussion

blog comments powered by Disqus