Hacker News new | past | comments | ask | show | jobs | submit login

I think the Fortran problem was that f(x) = x^2 + 1 looks a lot like a normal statement, with only a subtle clue on the left hand side ("Hey, f isn't an array!...") Whereas in python, having 'lambda' is a bigger clue. Hard to know without trying it out on some test subjects. I don't think anyone really studied why the Fortran thing was a problem, but of course lots of people (including me) have guesses.

As for type hinting, Python 3 does support it: https://docs.python.org/3/library/typing.html but I think the better lesson to learn is that it can be hard to future-proof alternative syntax or syntactic sugar. I looked at the 3.X docs, and PEP 484 and 526, no mention of how this typing can work with lambdas, and no comment that it doesn't (!)




Mis-seeing it as an array makes a lot of sense for the f(x) syntax. That's probably even more true than it would be in a higher level language like python, because you're doing more stuff like that.

But for Python3 lambda type hints, I'm reading a definitive comment in PEP 3107 that it isn't supported [0]. Anecdotally, that also jives with what I'm seeing on the REPL.

    Python 3.6.0 (default, Jan 18 2017, 02:51:38)
    [GCC 4.9.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import typing
    >>> f = lambda x: int: x * 6 
      File "<stdin>", line 1
        f = lambda x: int: x * 6 
                         ^   
    SyntaxError: invalid syntax
[0] https://www.python.org/dev/peps/pep-3107/#lambda


The docs pointed me to PEP 484 and 526, that's why I mentioned exactly what I'd looked at. PEP 3107 is not mentioned in https://docs.python.org/3/library/typing.html

Not trying to be pedantic here, just illustrating the point that this style of function can collide with future language developments, and confuse users.

Here's someone complaining that PEP 484 doesn't mention the impact of the new syntax on lambda: https://mail.python.org/pipermail/python-dev/2015-April/1397...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: