Functional programming

Marko Rauhamaa marko at pacujo.net
Wed Mar 5 13:11:56 CET 2014


Chris Angelico <rosuav at gmail.com>:

> C++ has something very like this, with the 'auto' keyword. It's not
> particularly useful for the examples you give, but can be much more so
> when you have templates, iterators, and so on - where the exact type
> declaration might be a couple dozen characters of pure syntactic salt,
> since you're initializing it to some function's return value.

Java has a widely practiced ideal that you should not tie variables to
class types but instead stick to interface types. Thus, you want to
declare:

   List<Integer> li = new LinkedList<Integer>();

Thing is, though, you can't automatically guess this. After all, you
might be after:

   Iterable<Integer> li = new LinkedList<Integer>();

or maybe:

   Collection<Integer> li = new LinkedList<Integer>();

This principle doesn't concern only collections. A well-designed
application should specify interfaces for pretty much all classes to
separate design blocks and APIs from implementations du jour.

(Again, something that has no relevance for Python users.)


Marko



More information about the Python-list mailing list