News for hackers. Stuff that matters.
Re:Let the Type System do the Work by TheLoneWolfling on Monday April 21, 2014 @02:25PM (#7622692)
I'd disagree with you: named arguments are good, but they don't save you in a lot of cases.

For example when you have one function returning (pos, size) and another function expecting (size, pos).

Re:Let the Type System do the Work by hcarvalhoalves on Monday April 21, 2014 @02:40PM (#7622798)
Named arguments is syntatic sugar for packing/unpacking data structures in some languages, so you can leverage that. In Python:

    >>> from collections import namedtuple
    >>> Vector2 = namedtuple('Vector2', ('x', 'y'))
    >>> PlayerOptions = namedtuple('PlayerOptions', ('position', 'size'))
    >>> opt = PlayerOptions(position=Vector2(100, 100), size=Vector2(50, 50))
    >>> Player(**opt._asdict())
The order arguments are passed doesn't matter anymore. You can also enforce this calling convention with a constructor signature like this (in 3):

    >>> class Player(object):
    >>>     def __init__(self, *, size, position):
Re:Let the Type System do the Work by q845712 on Monday April 21, 2014 @04:18PM (#7623501)
i agree that in languages without compiler defined types, but with other tools such as named arguments, the class of errors described here can be to some extent avoided by making good use of named arguments. I'm gonna do this more often in my python code!