- Lack of support for blocks - I have a bit of an esoteric desire here: I want to use Python-like syntax to build a DSL for compiling into hardware description language, essentially using Python as a macro language on top of the DSL. I want to be able to create my own control structures (hardware_if:...., etc.). Python doesn't let me do this.
- Stdlib organization (or lack thereof) - Maybe this is inevitable, as the stdlib is made up of all sorts of things integrated from other packages, but it would be nice to have something closer to what the C# and Java people rave about in their respective languages.
- Inefficient tail calls (tail recursion) - Maybe not important to too many people since Python has such cool iteration support, but it would be nice to be able to write a tail-recursive function and know that it will be optimized into a loop.
- No "nonlocal" rebinding of functions - This will be fixed in Python 3, which is cool, but it's not there right now. Basically, you can read variables from enclosing scopes right now, but you can't "rebind them", that is, assign the name to a new object. All assignments are either in the local scope (default) or module scope (if you declare the name "global"). And honestly, the main reason I hate this is that it gives Paul Graham one more negative thing to say about Python relative to LISP.
- No dictionary comprehensions - And it's not gonna happen any time soon. List comprehensions are wonderful, and I'd like to build a dict in the same way. I know I can do dict((k,v) for k,v in seq). But I don't like the double-left-paren there. OK, so it's a nit. But wouldn't it be nicer just to say {k:v for k,v in seq}?
Well, there it is. 5 things I hate. Now I can get on to writing about the things I like.
I too work with Hardware. ASIC & FPGA designs; Verilog VHDL, Specman ...
ReplyDeleteEarlier this year I wrote a preprocessorfor those translate_off/translate_on comments used to remove source fro consideration by synthesizers in Python. I next went on to write a Verilog preprocessor to handle all the backtic macros of Verilog; `define `ifdef `reset `include etc.
I did both in Python without blocks so it ca be done.
- Paddy.
P.S. The thing I hate about Python is it not having a constrained random generator a-la SystemVerilog or Specman-e or Vera.
ReplyDelete- Paddy.
You can definitely use Python to preprocess files of a different syntax, but that's not really what I was thinking of. What I'd like to to be able to create a domain-specific language for hardware design that really looks like Python. Something like:
ReplyDeletedefmodule mymod(s1, s2, s3):
myfor(unrolled=True) i in range(10):
...
With blocks, I'd then be able to use operator overloading and such to build up a parse tree which I could then synthesize into RTL. Without them, I can use Python as a macro language, but not much else. In fact, Cog is a great tool by Ned Batchelder that can be used to give pretty much any language a Python pre-processor. I'd just like to go a bit beyond that.
I think tail call elimination is more trouble than its worth. It messes up tracebacks since scopes disappear in ways that will be mysterious to most programmers. You can avoid this, but then it's just a funny little optimization that avoids some recursion limits -- but not all limits, and not in a way most people will understand, and probably slowing things down as a result. Maybe as a -OO option or something it would be reasonable, otherwise it's kind of lame IMHO.
ReplyDeleteRe: Ian Bicking
ReplyDeleteFirst off, (and way off topic), I really enjoyed your talks at PyCon on WSGI and Zdjango Gears. I can honestly say I have never laughed harder at any technical conference.
You may be right on tail call elimination being more trouble than it's worth. I've never hacked on the Python interpreter, so I'm not really in a position to judge. However, it does seem that Python has a substantial function call overhead (IIRC), and tail call elimination would seem to remove that overhead when the optimization could be applied. So I guess I don't know how this particular optimization could possibly slow things down. (Though again, I don't hack the interpreter source, so I can't say authoritatively).
And hopefully this post made clear that these 5 things are not particularly large obstacles to my use of Python. Just some evidence that I'm not a completely off-base fanboy. None of these things are show-stoppers for me (and I like a lot more about python than I hate).
I just stumbled across your blog and find it very informative! I noticed the comment about writing HDL in Python. Are you familiar with MyHDL (http://myhdl.jandecaluwe.com/doku.php)?
ReplyDeleteI have had good success using MyHDL and Python as a verification language and for writing HDL. I am not familiar with the "block" structure but MyHDL uses generators to describe hardware blocks (oopps may have overloaded a term).
I'll throw my two cents in. It's not a gripe with Python per se, but with its standard library: the datetime module is weak. I can't compare a datetime.datetime instance with a datetime.date instance without jumping through hoops, its arithmetic is weak, and in most ways it's vastly inferior to Egenix's mx.DateTime library. Yet software like Django uses it, which means I spend a lot of time converting values between it and mx.DateTime. Not fun. I hope they pitch the module for Python 3000 and roll mx in instead.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteFor DSL that can be created from an already working functional language. I would recommend to look at Metalua. It is essentially an extension to Lua that lets one create new Syntax constructs (or change the original ones) in Lua.
ReplyDeleteThe way it works is that you give it a Lua source file as an input, and then it gives you the AST of that source file with powerfull Node matching functions. So that you can transform that source code either in place (into another LUa file) or into something different.
I used it to create Lua-based DSL and transform it into javascript. There is a mailing for metalua as well.
Some people use it introduce new operators or other syntactic constructs into Lua.
I kind of thought that Python decorators can be used for DSL, but I do not think they are meant for this task.
@anonymous:
ReplyDeleteThanks for the tip on Metalua! I will definitely look into it.
Have you looked at the parser / ast modules? Gives you access to python parse trees. Might be what you're looking for.
ReplyDeleteThanks for the comment! I have done a few things with the parser and ast modules. Lots of stuff has changed since I wrote this (for instance, dict comprehensions now exist). Blocks would still be nice, but I've discovered I don't really want macros all that badly (see other posts on this blog re: MetaPython).
Delete