News for hackers. Stuff that matters.
Re:Ask PG: Lisp vs Python (2010) by pg on Monday October 18, 2010 @12:38PM (#1804145)
This question sounds like it's from 2005 rather than 2010. Lisp seems to have become fashionable again now, thanks to Clojure.

I'm sure Python has very good libraries, but I would find it constraining to program in a language without proper macros.

Re:Ask PG: Lisp vs Python (2010) by metageek on Monday October 18, 2010 @02:32PM (#1804558)
The problem with the Blub paradox is that there's no total ordering.

I do Common Lisp and C++ at my day job (ITA), and I do much of my personal hacking in Python. In Python and C++ I miss macros; in Lisp and Python I miss RAII and strong typing; in Lisp and C++ I miss dictionary literals.

And, in all of them, I miss algebraic datatypes.

Re:Ask PG: Lisp vs Python (2010) by DanWeinreb on Monday October 18, 2010 @04:49PM (#1805089)
Hello, my co-worker, whoever you are. Yes, Common Lisp should have dictionary literals. I don't know why there hasn't been a commonly-used reader macro for this. (Emacs Lisp mode and other tools would have to know about it, so it needs to be a widely-accepted convention.)

Common Lisp does have strong typing. What it does not have is static typing.

I am at the SPLASH conference, and the Dynamic Language Symposium is happening right now. There is controversy over whether we can find a way to have the benefits of both static and dynamic typing in the same language. The great advances in type inference make me hopeful. The keynote speaker, Allan Wirfs-Brock, replied to my question about this with more pessimism. It is not a simple question; for one thing, not everybody even agree about which factors are "pro" or "con" for either static or dynamic. I am not doing programming languages these days (I'm doing databases) but I continue to be hopeful.

Re:Ask PG: Lisp vs Python (2010) by metageek on Monday October 18, 2010 @06:07PM (#1805363)
Hello, my co-worker, whoever you are.

John Stracke. (I've been staying pseudonymous, but today I mentioned Adder, which is tied to my real identity.)

Common Lisp does have strong typing.

True. I need to remember to be more precise; "doesn't have strong typing" just means "doesn't have type feature Blub". Common Lisp has runtime type safety, and type hints for efficiency; what it does not have is the pervasive typing that I'm used to from C++, which has a separate set of benefits. The most obvious is that, in C++, I can change the interface to a class and be certain that the compiler will catch any caller that uses it incorrectly. (Although I suppose it may be possible to do something like that with CLOS. I haven't used much CLOS, since ITA avoids it.)

There is controversy over whether we can find a way to have the benefits of both static and dynamic typing in the same language.

I'd say that type inference already brings us nearly there: the convenience of dynamic typing, with the rigor of static typing.

I may be wrong, though; I've used ML and Haskell, but not enough to really feel where the pain points of type inference are.

Re:Ask PG: Lisp vs Python (2010) by ohyes on Tuesday October 19, 2010 @10:13AM (#1807169)
'True. I need to remember to be more precise; "doesn't have strong typing" just means "doesn't have type feature Blub". '

That might be less precise, but more correct :-P.

"Common Lisp has runtime type safety, and type hints for efficiency; what it does not have is the pervasive typing that I'm used to from C++, which has a separate set of benefits. "

The type declarations aren't just for efficiency (although they are frequently (ab)used for it).

"The most obvious is that, in C++, I can change the interface to a class and be certain that the compiler will catch any caller that uses it incorrectly."

I'm not sure what common lisp version you use, but wouldn't this be fixed by simply declaring types of everything? You can declare the types of on the slots of a struct, you can declare the types of arguments to functions, results of functions, variables, slots of objects, contents of sequences... (having trouble thinking of something you can't declare types on, maybe a hashtable? Although you could wrap the accessors in a function).

Then SBCL (at least) yells at you when you go to recompile the project.

Re:Ask PG: Lisp vs Python (2010) by metageek on Tuesday October 19, 2010 @11:53AM (#1807532)
wouldn't this be fixed by simply declaring types of everything?

Yes, but I'm not so sure about the "simply". It's only marginally easier in C++; but at least you know that haven't forgotten to declare anything.

Re:Ask PG: Lisp vs Python (2010) by chaitanya on Tuesday October 19, 2010 @09:58AM (#1807128)
> I haven't used much CLOS, since ITA avoids it.

Interesting. Is it for performance reasons?

Re:Ask PG: Lisp vs Python (2010) by metageek on Tuesday October 19, 2010 @11:45AM (#1807508)
...actually, I don't know. When I started, I was told we don't use it; I don't remember whether I was told a reason. If I was, it was performance; anything else would have been surprising enough to remember.
Re:Ask PG: Lisp vs Python (2010) by sausagefeet on Wednesday October 20, 2010 @10:05AM (#1811228)
I wonder if it's similar to why Jane St doesn't make a lot of usage of the O in Ocaml (from what I've gathered at least, I don't work there.....yet). Object systems can be nice but they tend to make understanding your code all the harder since you have all the dispatching. I don't know anything about CLOS but this is pointed out as a reason against using Java and the object system in Ocaml in the Caml Trading video.
Re:Ask PG: Lisp vs Python (2010) by pg on Monday October 18, 2010 @03:13PM (#1804724)
I did mention in the original essay that it was only a partial order, in footnote [4].
Re:Ask PG: Lisp vs Python (2010) by tome on Tuesday October 19, 2010 @06:07AM (#1806660)
Ah, but metageek's point is that it's not an order at all. It contains cycles.
Re:Ask PG: Lisp vs Python (2010) by metageek on Monday October 18, 2010 @03:15PM (#1804737)
Sorry, I haven't read it in a while.
Re:Ask PG: Lisp vs Python (2010) by lisper on Tuesday October 19, 2010 @01:15AM (#1806299)
> in Lisp and C++ I miss dictionary literals

So roll your own. Or use mine:

http://flownet.com/ron/lisp/dictionary.lisp

Re:Ask PG: Lisp vs Python (2010) by milesvp on Tuesday October 19, 2010 @08:20PM (#1809416)
Forgive me, but I think you mean in python you miss static typing.

Python is strongly typed.

Also, just to jab at C/C++, pointers to void... really? It all but makes C/C++ a weakly typed language.

http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%... http://www.artima.com/weblogs/viewpost.jsp?thread=7590 http://en.wikipedia.org/wiki/Duck_typing http://articles.sitepoint.com/article/typing-versus-dynamic-...

Re:Ask PG: Lisp vs Python (2010) by jcromartie on Monday October 18, 2010 @03:20PM (#1804755)
I can't help you with strong typing, but I'm pretty sure a macro would go a long way towards implementing RAII in a Lisp.
Re:Ask PG: Lisp vs Python (2010) by masklinn on Monday October 18, 2010 @05:56PM (#1805323)
> I'm pretty sure a macro would go a long way towards implementing RAII in a Lisp.

Well yeah, just build the macro you need on top of unwind-protect, that's pretty standard common lisp fare.

Re:Ask PG: Lisp vs Python (2010) by metageek on Monday October 18, 2010 @03:33PM (#1804807)
That's true; we've already got special cases like WITH-OPEN-FILE.
Re:Ask PG: Lisp vs Python (2010) by masklinn on Monday October 18, 2010 @05:54PM (#1805316)
Actually, you already have something better than RAII in unwind-protect. Just create whatever macro you need on top of that (I'm pretty sure with-open-file is just a macro on top of unwind-protect, Siebel seems to agree in his chapter on files) and you're done.
Re:Ask PG: Lisp vs Python (2010) by akkartik on Tuesday October 19, 2010 @01:18AM (#1806306)
Why do you miss dictionary literals? Syntax similar to arc's seems to do it for me:

  (obj a 1 b 2 c 3)
Re:Ask PG: Lisp vs Python (2010) by gruseom on Tuesday October 19, 2010 @03:50AM (#1806489)
We do the same thing:

  (make :a 1 :b 2 :c 3)
which macroexpands into a plist in CL and {a:1, b:2, c:3} in JS. I've grown to like this idiom a lot. Yeah, you have to type OBJ or MAKE or whatever but in return you get something that integrates completely smoothly with the rest of the language.
Re:Ask PG: Lisp vs Python (2010) by metageek on Tuesday October 19, 2010 @06:20AM (#1806675)
Y'know, I'm not sure. Next time I need to use a hash, I'll create something like that and see how it feels.
Re:Ask PG: Lisp vs Python (2010) by swannodette on Monday October 18, 2010 @03:52PM (#1804895)
What about Qi? What about Typed Racket?
Re:Ask PG: Lisp vs Python (2010) by djacobs on Monday October 18, 2010 @08:54PM (#1805758)
One question I've had about Typed Racket since I first saw it: why all the colons? Seems to mess with the elegance of Lisp, and especially Scheme.

There has to be another friendlier syntax for typing, no?

Re:Ask PG: Lisp vs Python (2010) by manu3000 on Wednesday October 20, 2010 @06:39AM (#1810668)
why not ? colons are used to denotes values type in ML
Re:Ask PG: Lisp vs Python (2010) by namekuseijin on Wednesday October 20, 2010 @12:49PM (#1811869)
Typed Racket combines all the inconvenience of type declarations with all the performance provided by a dynamic language.
Re:Ask PG: Lisp vs Python (2010) by deadwisdom on Monday October 18, 2010 @02:35PM (#1804567)
The Python philosophy is that macros do more harm than good, making it harder for someone to read/understand your code in the long term. These and other "constraints" make the code more accessible to others and even yourself.
Re:Ask PG: Lisp vs Python (2010) by aidenn0 on Monday October 18, 2010 @03:11PM (#1804708)
Macros are just another abstraction tool. If you poorly use an abstraction tool, it makes the code harder to read, if you properly use an abstraction tool, it makes the code easier to read.

Here's a function that makes code harder to read:

def sumAList(aList): return 7

This doesn't mean that functions are bad.

Now there is an argument that macros make code harder to read in that I've yet to see a really good macro system that isn't dependent on the code having very little syntax (e.g. S expressions), since the more different the code is from the AST, the harder it is to manipulate the code successfully.

Combined with the fact that more syntax can make code much easier to read, there is a conflict here.

However, I don't think that's the argument you are making.

Re:Ask PG: Lisp vs Python (2010) by deadwisdom on Monday October 18, 2010 @04:23PM (#1805004)
Yes, but any given function is usually extremely easy to understand, because it's only, say one level of abstraction, then a macro is a few levels higher than that. And as you go up in your levels of abstraction, it gets harder and harder to really understand what's going on. Sure, some macros are intuitive and easy to follow, but those are usually easily replicated with other things, especially in a dynamic language like Python.

I also don't mean to imply that Lisp is lesser for using macros. I love Lisp and any implementation clearly requires macros. But Lisp is also, undeniably, harder to read for this and other reasons.

Re:Ask PG: Lisp vs Python (2010) by aidenn0 on Monday October 18, 2010 @06:02PM (#1805342)
Hmmm. I think your argument is roughly that there is a "sweet-spot" for abstraction when it comes to readability?

That is a point at which less abstraction makes the code harder to read, and more abstraction makes the code harder to read?

I will agree with this in specific cases (i.e. for any given solution, there is a point at which adding abstraction can't improve readability), but I'm not certain I agree in the general case (i.e. that using macros cannot improve readability).

I guess it also depends on what you mean by "really understand what's going on." I started out programming in C. Now in C, if you know your compiler well, you can predict fairly accurately what binary code will be generated when you compile with optimizations off. Moving to higher level-languages you lose this ability, and no longer "really understand what's going on."

For systems programming, I may still use C to get this advantage. For other problem domains, I sacrifice this knowledge because representing my problem more tersely in a higher level language makes the code more readable and easier to understand. Now I will never know exactly which instructions will be executed when I write in Python.

Similarly, with sufficiently fancy macros, I may not know what LISP code is generated, but if the macros do what they say they do, it can make my code less verbose, more understandable, and easier to maintain. There are times when really understanding what is going on trumps the terseness, and those times I don't use macros.

Also, I love Python. It embeds well in C (which is where my original background is), and it has very good portability, and a good set of libraries.

I also implied, but didn't say straight out that Python has a good reason for not having macros: Part of its design is to look like pseudo-code. See also Norvig's comment to the OP. Macros that operate on text rather than trees (C preprocessor, m4, etc) are far more error prone, and probably a Bad Idea. Therefore if you want your language to look like something other than a tree, you have to forsake macros that operate on code as it is written. I have seen for several languages (Python among them I believe) Lisp-like macros that operate on the AST of the language. They have not caught on. I have several theories why this is so, but right now my preferred one is that it feels too much like you're hacking the compiler, and Compilers Are Scary.

Re:Ask PG: Lisp vs Python (2010) by gruseom on Tuesday October 19, 2010 @03:56AM (#1806497)
right now my preferred one is that it feels too much like you're hacking the compiler

I think what you implied just before that is a stronger argument: it's way too distant from the base language, and this semantic distance is so costly that it's not worth the trouble.

Re:Ask PG: Lisp vs Python (2010) by sedachv on Monday October 18, 2010 @07:21PM (#1805556)
"And as you go up in your levels of abstraction, it gets harder and harder to really understand what's going on."

There is a difference between abstraction and indirection. Just because you've added the latter doesn't mean you've gained any of the former.

"Sure, some macros are intuitive and easy to follow, but those are usually easily replicated with other things, especially in a dynamic language like Python."

How would you implement SETF in Python? Or how about compile-time link checking for a web application (http://carcaddar.blogspot.com/2008/11/compile-time-inter-app...)?

Re:Ask PG: Lisp vs Python (2010) by ssp on Monday October 18, 2010 @04:35PM (#1805046)
The argument is that macros have non-local effects; they interact with the code in which they are applied. This means that the macro definition and the code surrounding the macro invocation can't necessarily be understood in isolation.

This is also essentially the argument against global variables.

Re:Ask PG: Lisp vs Python (2010) by DanWeinreb on Monday October 18, 2010 @04:54PM (#1805107)
A function definition is, in general, far away from the function call. If you think this problem is more severe for macros than for functions, then you should articulate why. You may well have a very valid point in your mind but I think it needs to be expressed somewhat more specifically.
Re:Ask PG: Lisp vs Python (2010) by ssp on Monday October 18, 2010 @05:59PM (#1805333)
For non-hygienic macros, it's essentially the variable capture problem.

For hygienic macros, I don't know of a good argument that they are inherently more difficult to understand separately from their invocation than a function.

(I'm not personally arguing against macros - or global variables for that matter - just trying to state the argument).

Re:Ask PG: Lisp vs Python (2010) by cypherpunks on Wednesday October 20, 2010 @04:02AM (#1810422)
I think it should be obvious that you use programming constructs only when difficulty of understanding it is less than the difficulty of understanding code without it (over the whole program). This applies to functions, classes, macros, frameworks etc.

Full macros (like in CL where they are just functions that don't evaluate their arguments) give the programmer same power as compiler writer or programming language designer.

ps. To really get benefit from Lisp macros, you would need to standardize code walker. Without code walker, macros can't reach their full potential.

Re:Ask PG: Lisp vs Python (2010) by dataangel on Wednesday October 20, 2010 @11:17PM (#1814142)
What is code walker?
Re:Ask PG: Lisp vs Python (2010) by jules on Monday October 18, 2010 @06:18PM (#1805392)
If you want local reasoning you will have to reject Turing completeness, otherwise you could implement a language with global variables and eval a bunch of code in that language.

I think we shouldn't be limiting our tools. We should instead limit their use. Global variables can be nasty, but it's nice to have them when your code is best expressed with global variables. Same for macros.

Re:Ask PG: Lisp vs Python (2010) by DanWeinreb on Monday October 18, 2010 @04:52PM (#1805101)
At the International Lisp Conference last year, I put in an evening event called the "Great Macro Debate", in which these issues were discussed. (We encouraged humor, and flaming as long as it was witty, so it was a lot of fun.) What you say is true to an extent. Macros, like most things, can be abused. If you have a group of Lisp programmers, one thing you can do is have the junior ones request advice from the senior ones about what constitutes "tasteful and idiomatic" use of macros, and vet particular macros, since it is rather hard to crisply "pin down" just what those things mean.
Re:Ask PG: Lisp vs Python (2010) by namekuseijin on Wednesday October 20, 2010 @12:56PM (#1811896)
I wish there was a language called harmless which common folk could use to express common thought without any fear. It would go like this:

do this do this and that and that too do this amen

No branching nor decision trees as not to confuse common folk. Now programming is a socially acceptable activity!

Re:Ask PG: Lisp vs Python (2010) by illumen on Monday October 18, 2010 @05:06PM (#1805153)
Macros can be used in python.

There are a few libraries that help make it easier(so you do not need to manipulate the ast yourself). For example:

  @macro
  def macroname(arg1, arg2):
     ... macro contents ...
There's some current information for you old time lispers, so next time you don't sound so dated in your Battles with Trolls in the great never ending language war flames ;)
Re:Ask PG: Lisp vs Python (2010) by forensic on Monday October 18, 2010 @09:13PM (#1805800)
I like how you imply that you don't participate in the language wars. When you just did.
Re:Ask PG: Lisp vs Python (2010) by apgwoz on Tuesday October 19, 2010 @06:20AM (#1806674)
Link? The only "macro" library I've seen for python has been "MetaPython" (http://metapython.org/), which is more of a let down than it is useful, unfortunately.
Re:Ask PG: Lisp vs Python (2010) by jpr on Wednesday October 20, 2010 @03:15AM (#1810351)
Even if that happened to work correctly (which I don't believe), you would still be missing a bunch of macro-related stuff that makes CL the programmable programming language it is, and Python isn't:

-reader-macros

-symbol-macros

-compiler-macros

-macrolet

-symbol-macrolet

EDIT: Fixed layout

Re:Ask PG: Lisp vs Python (2010) by lpsmith on Wednesday October 20, 2010 @04:13AM (#1810437)
Well, those kinds of claims are kind of par for the course for the Python community. I remember that it was commonly claimed that Python 1.5 had the "full power of the lambda calculus", when all it had was anonymous function definitions, and not true higher order functions.