4 ms·
Someone doesn't like something. News at 11.
by jacobian 17y ago
Someone doesn't like something. News at 11.
- deleted 17y ago[deleted]
- andreyf 17y agoI think his point is a bit deeper than "I don't like it". His point relates to the distinction Alan Kay makes [1] between programming languages which are either an "agglutination of features" or a "crystallization of style". In terms of features, Python is definitely strongly of the former variety: it has objects, but not in "opinionated" sense that Smalltalk or even Java do. It has lambdas, but limits them to one line. It has closures, but until py3, they clashed with the implicit declaration syntax. There isn't "one obvious way of doing a lot of things" more complicated than iteration. dustin's py-github [2] is an especially poignant example which comes to mind: I would never have used classes for something like that, and Python doesn't give a clear reason to use them or not. 1. http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html 2. http://github.com/dustin/py-github http://github.com/dustin/py-github
- jmillikin 17y ago> It has closures, but until py3, they clashed with the implicit declaration syntax. Could you elaborate on what you mean, here? The only issue I know of with Python 2's closures is that there's no scoping keyword for non-local, non-global variables. But that only matters if you're trying to re-define variables in a parent procedure's scope, which is probably not a good idea.
- andreyf 17y agoIt's a great idea if you want to make small callable objects with limited (hidden) state, in a way that's easy to translate between any languages which support closures. For example, in JS: function gencycle() { var args = Array.prototype.slice.apply(arguments), i = 0; return function cycle() { i = (i+1) % args.length; return args[i]; } } I can then use gencycle("red", "green", "blue") when I want a function which gives me a rotation of colors. In py26, I'd write it as: class GenCycle(object): def __init__(self, *args): super(GenCycle, self).__init__() self.args = args self.i = 0 def __call__(self): self.i = (self.i+1) % len(self.args) return self.args[self.i] In Python 3, I'd have to choose between the two versions.
- j_baker 17y ago>>> from itertools import cycle >>> iter = cycle(['red', 'green', 'blue']) >>> iter.next() 'red' >>> iter.next() 'green' >>> iter.next() 'blue' >>> iter.next() 'red'
- jmillikin 17y agoI believe he's using cycle() as a simple example, to illustrate a more complex requirement.
- jmillikin 17y agoThe preferred way to do that in Python is as a co-routine (AKA generator). Besides being easier to read and reason about, generators implement common protocols, such as the iteration protocol. This means you can use generators in for-loops, as a parameter to list(), or anywhere else that accepts an iterator. Here's an example of cycle() as a co-routine: def cycle(*args): i = 0 while True: i = (i + 1) % len (args) yield args[i] for arg in cycle("red", "green", "blue"): print (arg) Alternatively, if you really want to use a callable: gencycle = lambda *args: cycle(*args).next get_next = gencycle("red", "green", "blue") print (get_next()) print (get_next()) print (get_next()) Either way, it'll be cleaner than an explicitly stateful object.
- jacobian 17y agoI think his point is a bit deeper than "I don't like it". How so? Everything in this article -- and nearly any point one could make about a programming language -- comes down to a matter of taste. Take your example -- Python "has objects, but not in an 'opinionated' sense." What you see as a lack of purity, I see as just the right amount of pragmatism. To me, "un-opinionated" classes is a positive point, not a negative one. Where Zidek sees "inherently static" standard libraries, I see inherently stable ones. Where he sees a distressing lack of encapsulation I see a refreshing relaxing of constraints. I'd go on, but I think you get the point. You know what's awesome, though? If you don't like Python you don't have to use it! But you know what isn't awesome? When you complain about this free thing that nobody's forcing you to use. You're just shitting all over someone else's hard work... for what? Page views? Hacker News -- hell, the whole Internet -- would be a better place if people just shut the hell up about whatever's got their undies in a twist this time.
- j_baker 17y ago"I think his point is a bit deeper than "I don't like it". His point relates to the distinction Alan Kay makes [1] between programming languages which are either an "agglutination of features" or a "crystallization of style"." Sorry, but this is flat out wrong. I mean, Python's syntax is pretty consistent over all (aside from a few quirks). Even still, Kay's archetypical example of a "style language" (Lisp) has definitely evolved more over the years than Python has. The point isn't that the language has to be perfect. It's just that it has to have a "feel" to it. Python definitely has its own flavor (I mean idiomatic code is called "Pythonic" after all). The other part of the Python philosophy is "practicality beats purity". Therefore, there are times when the Python developers decided to just implement something practical and simple over something that's ideologically consistent.
- moe 17y agoTherefore, there are times when the Python developers decided to just implement something practical and simple over something that's ideologically consistent. Which cannot be stressed enough. Python acknowledges that the programmer is a human more than any other language I have seen. That's why you can get stuff done and keep it maintainable so easily in python. It gives you just enough rope to be very flexible, but tries very hard to not extend it to the length that people normally use to hang themselves.