7 ms·
Python for Lisp Programmers (2000)
- bgorman 6y agoI have recently been learning python after primarily coding in Clojure and Ocaml the last 36 months. It has been a pretty frustrating experience, lots of the tools from functional languages are there, however Python as a language is extremely inconsistent. All these little quirks take up a significant chunk of cognitive overhead. Python also liberally add different syntax in places where it doesn’t seem to add much value (eg lambdas cannot destructure tuples, and don’t need to use return). Python has really showed me the value of keeping a simple syntax, and having value semantics everywhere). Mutation just isn’t a great way to write code outside of leetcode.
- macintux 6y agoFunctions (and I assume lambdas) could destructure tuples in Python 2.x. I started my first serious Python project in 2.something before discovering it was nearly eol, and learning that all of my tuple management was broken under version 3 was quite demoralizing. I find the mutability of values and object orientation of 3rd party libraries to be among the most alienating aspects of Python, but overall it’s too useful for me to ignore, so I live with it. I just don’t find layering on functional capabilities to an OO language to be nearly as useful as a true FP solution. As you said, too much cognitive overhead.
- BalinKing 6y agoHuh, apparently[0] they removed lambdas' ability to do that in Python 3! [0] https://stackoverflow.com/a/11328422/2391244 https://stackoverflow.com/a/11328422/2391244
- xapata 6y agoI'm not sure why they removed the ability to destructure sequences in args. It bugs me sometimes as well. There's probably a long discussion about the rationale in some PEP and an even longer email thread.
- mesaframe 6y agoThey did? Afaik, it's there.
- pansa2 6y ago> There's probably a long discussion about the rationale in some PEP PEP 3113 -- Removal of Tuple Parameter Unpacking: https://www.python.org/dev/peps/pep-3113/ https://www.python.org/dev/peps/pep-3113/
- xapata 6y agoThat's a decent argument. It's more typing (in both senses!) to use a specific type as the parameter instead of unpacking in the signature, but it's just as or more readable that way.
- carapace 6y agoYeah, I was so bummed when they did that. I had a whole library of functions for a stack-based interpreter that destructured the stack in the function sig, and it was sooooo coooool... def add((a, (b, stack))): return a + b, stack def uncons(((head, tail), stack)): return tail, (head, stack) &c...
- bmitc 6y agoI fully agree with you and have expressed this sentiment many times. I use Racket and F# in my spare time, basically sister languages to what you use (!), and I have the same opinions. Knowing these other more structured, consistent, and principled languages makes Python a frustrating and difficult experience. Whenever I program in Python, never by choice, it's an exercise in unlearning sanity. Knowing these other languages and with others like them out there (F#, Racket, Clojure, OCaml, Elixir), I have no practical or intellectual need for Python.
- Tcepsa 6y agoMy favorite language has been Clojure for a long time, but given Python's popularity and widespread use I often wonder whether there is just some big underlying principle that would cause Python's appeal and superiority become clear, if only I could see it. Comments like yours and GP's help reassure me that there's not just some fundamental thing about Python that I'm missing. (And don't even get me started on Python's concurrency situation!)
- Scarbutt 6y agoPython is easy to get started with and has syntax that's nice to look at, easy/nice almost always wins over better. So now the issue is many have to keep using Python because of the ecosystem not because they find the language good.
- cutler 6y agoThe top 3 programming languages - JS, Python & Java - are all pretty uninspiring. It's all about history and ecosystem unfortunately.
- iLemming 6y ago> The top 3 programming languages - JS, Python & Java - are all pretty uninspiring. And Clojure beautifully solves many pain points of Java and Javascript, and even C#. I haven't tried clj-python mentioned, but I hope someday soon, running Clojure code interoperable with Python in production becomes a reality. The hosted nature of the language is a brilliant idea. Clojure eliminates many small annoyances I hate in other languages - syntactical, semantical, and operational. I wish more programmers have given a heartfelt try to Clojure instead of whining that "Lisp is unreadable" and "the parentheses are awful".
- konjin 6y agoPython has been getting worse with time. I learned it in the 00's in highschool and it was a very nice small scripting language that you could just write dumb code which worked and you wrote C for where you needed performance. For some reason people have pushed it everywhere and lost the spark it used to have.
- aldanor 6y ago> The two main drawbacks of Python from my point of view are (1) there is very little compile-time error analysis and type declaration, even less than Lisp, and (2) execution time is much slower than Lisp, often by a factor of 10 (sometimes by 100 and sometimes by 1). Both have been improved on - in particular (1), with `typing` module, type annotations, mypy and so on. With (2), Python's speed has increased somewhat since, but then again, you won't be doing large-scale math without numpy, and for non-vectorizeable numeric computations you'd probably use something like jit-compiled numba or the like.
- zitterbewegung 6y agoThe big thing that has allowed Python to flourish is the fact that it has a good foreign function interface and was easy to use to the point that both academics and web developers would learn it. It really got a second wind as ML got more and more popular. Not many languages can be used to create an ML application end to end (but building on the shoulders of Google and or other large big tech / ad tech companies).
- Blikkentrekker 6y agoEveryone claims to be able to explain in hindsight why something became popular. I believe that the overwhelming factor of why something does or does not become popular is simply chaotic luck. In an alternate history where Python was designed exactly the same, but a butterfly at Guido's desk flapped his wings slightly differently, Python would have been obscure.
- cutler 6y agoAgreed. Well put.
- mumblemumble 6y ago> I believe that the overwhelming factor of why something does or does not become popular is simply chaotic luck. This seems to me a bit like saying, "That color isn't cerulean, it's blue." Describing the specific instances of serendipity that have led to Python's continuing success doesn't imply that it wasn't dumb luck. It's just a way of saying, "Here's an interesting bit of dumb luck."
- Blikkentrekker 6y ago> Interestingly, Lisp has exactly the same philosphy on this point: everyone uses emacs to indent their code, so they don't argue over the indentation. They don't argue more or less than in, say, C, but they argue.
- nojito 6y agoSwitching to F# from python solves just about every drawback that is listed.
- cutler 6y agoAt the cost of having zero Python libraries in your toolkit. More than any other language I'd say Python's success is due to the available libraries. Without them Python is a very average, boring scripting language with pointless limitations such as single-expression lambdas.
- fmakunbound 6y ago> Macros for metaprogramming ... No macros; write your own parsers Ooof, sounds like a lot of effort. Is anyone doing that in Python?
- benhoyt 6y agoPlenty of people write literal parsers in Python, for things like HTML template languages -- however, that's not really related to macros. The most crazy thing I've seen along these lines (but it leads to really nice syntax) is PonyORM (https://ponyorm.org/ https://ponyorm.org/), which allows you to write Python generator expressions like this: select(c for c in Customer if sum(c.orders.price) > 1000) And Pony will translate it to SQL like this: SELECT "c"."id" FROM "customer" "c" LEFT JOIN "order" "order-1" ON "c"."id" = "order-1"."customer" GROUP BY "c"."id" HAVING coalesce(SUM("order-1"."total_price"), 0) > 1000 But how it does this is pretty funky. Python doesn't actually provide the AST for already-compiled code, just the bytecode. So Pony decompiles the bytecode back to an AST, and then converts the Python AST into SQL. More here (from the PonyORM author): https://stackoverflow.com/a/16118756/68707 https://stackoverflow.com/a/16118756/68707
- jolux 6y agoSounds a lot like LINQ in .NET.
- benhoyt 6y agoYeah, definitely. Though note that LINQ is new syntax (at least with "query" syntax; see https://stackoverflow.com/a/823155/68707 https://stackoverflow.com/a/823155/68707), whereas this co-opts existing Python syntax. LINQ is quite a lot nicer in that it gives you the syntax tree (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/ https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...), whereas PonyORM has to be a huge decompile-the-bytecode-back-to-a-syntax-tree hack.
- jolux 6y ago
- baldfat 6y agoLISP and functional programming through Lisp style program (I prefer Racket) with multi-threading could be the way of the future, but instead we keep getting stuck in general programming languages that are great second best languages at best. Using LISP to create DSP Languages is so powerful but under used.
- HDMI_Cable 6y agoThat is incredibly true. For some reason we all have an obsession to use one language for everything (cough Python cough), rather than different, better suited ones for each task. I really hope Lisp makes a comeback.
- baldfat 6y agoWell LISP does both things. One language to create a personalized language for your issue.
- taeric 6y agoI find the section on hashtables funny. I cannot debt that but having a sethash is odd at first. That said, the beauty of how gethash plays with setf is quite nice once you get used to it. This is even more pronounced when used with mutable lists. (setf (cadr lst) new-element) doing what you'd expect is quite useful. Obviously, this can be abused, but it's a really nice tool in the box.