Live data from Hacker News

Python Language Features and Tricks

sahandsaba.com

81–86 of 86 posts

Re: Python Language Features and Tricks

#81
post #58
post #55

Earlier quoted context omitted.

In isolated offline code, I think Ruby approaches the unreadable - but only because DSLs are fashionable, and you have to understand the library involved to understand the magic that's going on behind the scenes. With sufficient online searching, you can understand things at a surface level, and with enough time with a debugger you can appreciate all the mechanics that are happening, but IMHO it still leaves you with…

Been thinking about Python vs Ruby lately. I dread reading other people's Ruby code (eg. if there is a problem in a library I'm using) but I don't have that same dread reading Python code. Now if Python had blocks and RubyGems then I would never give Ruby a second look.

What does RubyGems provide that isn't covered by pypy/eggs? I thought ruby and python packaging was approximated feature parity here (which is to say, both leave something to be desired, but work quite well).

Re: Python Language Features and Tricks

#82
post #11

Why are there so many negative comments? Maybe those posters are vastly underestimating how many people that just start out read HN. I think it's a pretty good post to read after something like "X in Y minutes - Python" to get a very quick grasp of what the language is like. I'm also not ashamed to say that despite having written quite a few LOC of Python I wasn't aware of named slices for some reason and I think the…

> ... I wasn't aware of named slices for some reason ....

I wasn't either. But I wouldn't call them a hidden feature of the language. A slice object is an object. So you can make it the value of a named variable, just like any other object. Somehow that wasn't obvious, though.

Now I'm wondering how else I might be able to improve my code by giving names to non-obvious things.

Re: Python Language Features and Tricks

#83
post #4

patterns / tricks = language deficiencies Wake me up when Python will support tail call elimination and will get rid of GIL. For now this language is no better than PHP.

There are only handful of language runtimes that got rid of GIL entirely. Namely JVM, .NET, and Rubinius. Other languages either use non-native threads or doesn't support threading at all. (E.g. Nodejs has no threading.)

Re: Python Language Features and Tricks

#84
post #54
post #46

Earlier quoted context omitted.

https://ghc.haskell.org/trac/ghc/wiki/ViewPatterns That's the haskell extension. To see a very nice use of them, check out this paper (pdf) http://strictlypositive.org/CJ.pdf

How do view patterns make patterns "first-class"? To me that means able to manipulate them as values, I don't see how view patterns allow that, they're just syntactic sugar for case expressions.

http://www.reddit.com/r/haskell/comments/1vpaey/pattern_syno...

I spoke too eagerly—the new feature is just named and namespaced patterns. It's a bit of a bump in power, but it's not fully general yet.

For true(-ish) first-class patterns take a look at Prisms in the lens package or some of the other first-class pattern libraries.

Re: Python Language Features and Tricks

#85
post #48

Earlier quoted context omitted.

Yes. And the order of the two for's in the list comprehension was deliberately kept the same as the order of the two for loops in your explicit code, on purpose, for ease of remembering how the former (i.e. list comp) works.

That order is the part that confused me. I expected to read it right-to-left, instead it's left to right for the for statements, then the expression on the left at the end. I see now that the Python docs explain this very clearly...

Yes. Meant to say that but forgot - that the Python docs explain it. That's where I read it myself :)

Re: Python Language Features and Tricks

#86
post #67

Earlier quoted context omitted.

I don't know Clojure, but I do know Python, and I'd like to say that unpacking is more flexible than you may realize. For example, you can do this: a,(b,c),d = [1,[2,3],4]

I don't mean to belittle Python here, I think its a great language and I find its unpacking useful. I'm only trying to demonstrate that the concept can be (and is in some other languages, like Clojure) taken further to make it more useful still. I think that Python's unpacking allows most, if not all, of Clojures sequence destructuring for tuples and lists. Clojure takes it a bit further, however, by applying it to a…

neat!
Post reply on HN