Live data from Hacker News

Python Language Features and Tricks

sahandsaba.com

1–10 of 86 posts

Re: Python Language Features and Tricks

#5
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.

For TRE: http://neopythonic.blogspot.com/2009/04/tail-recursion-elimi...

For the GIL, there are alternative implementations of Python (Jython, IronPython, etc.)

Re: Python Language Features and Tricks

#6
post #2

Python's unpacking is a poor man's pattern matching. I'd really love to see them extend it to support user-defined patterns like Scala's extractors or F#'s active patterns.

I think unpacking is just unpacking, languages that have pattern matching allow you to do something identical:

# let i = (1,2,3) ;;

val i : int * int * int = (1, 2, 3)

# let a,b,c = i;;

val a : int = 1

val b : int = 2

val c : int = 3

Re: Python Language Features and Tricks

#7
I have two questions.

1. I'm unfamiliar with the term 'unpacking'. Is it any different from pattern matching in, say, Haskell (but perhaps not as feature-rich)?

2. Aren't slices pretty much a staple in Python? I didn't think using them was considered a 'trick'.

Re: Python Language Features and Tricks

#8
post #6
post #2

Python's unpacking is a poor man's pattern matching. I'd really love to see them extend it to support user-defined patterns like Scala's extractors or F#'s active patterns.

I think unpacking is just unpacking, languages that have pattern matching allow you to do something identical: # let i = (1,2,3) ;; val i : int * int * int = (1, 2, 3) # let a,b,c = i;; val a : int = 1 val b : int = 2 val c : int = 3

Unpacking pretty much does one thing, and it makes that one thing easier and a lot more readable. Combine that with list comprehension (from what I understand C#'s LINQ is similar) and you end up with code that's highly maintainable/readable (as long as you name your variables appropriately, of course).

I believe Python supports pattern matching other than Regex as well.

Re: Python Language Features and Tricks

#9
post #7

I have two questions. 1. I'm unfamiliar with the term 'unpacking'. Is it any different from pattern matching in, say, Haskell (but perhaps not as feature-rich)? 2. Aren't slices pretty much a staple in Python? I didn't think using them was considered a 'trick'.

Tuple unpacking:

  t = (1, 2)
  a, b = t
  # a == 1 and b == 2
Using slices is normal with lists

Re: Python Language Features and Tricks

#10
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.

Every language has patterns or tricks, and every language has deficiencies, but these aren't the same thing at all.

It seems you have read some generic criticism of Python to copy from, and don't have much first-hand experience

Post reply on HN