3 ms·
I really don't see the advantage of C++. To me it feels verbose and the code is difficult to read, especially templates! What is the point of all that syntax?
by owyn 4y ago
I really don't see the advantage of C++. To me it feels verbose and the code is difficult to read, especially templates! What is the point of all that syntax? Is there some actual advantage or purpose to it? :) (Types, yes I know...)
More seriously. :)
The parens are definitely necessary. Think of it as sort of indentation too? Taking a typical factorial and just making up some kind of language which just uses indentation and infix notation, I mean, they're pretty similar? But the nice thing about lisp is that zerop, -, factorial are all equivalent and in the same place in the expressions. You could remove all the parenthesis and just use indentation. If you want to introduce strong typing, you can do that too.
(defun factorial (x)
(if (zerop x)
1
(* x (factorial (- x 1)))))
def factorial (x)
if zero? x
then 1
else x * factorial(x - 1)
Mentally, the parenthesis go away when you get used to them, and that happens pretty quick because there isn't any syntax to worry about. In many ways, Lisp is the simplest possible language that can do useful things. It's a thin layer on top of lambda calculus, and the early versions of lisp were more like machine language (CAR, CDR are left over from this history) but it's survived so long with almost no changes because it's pretty much the ur-language, spanning high level and low level abstractions. I expect almost any useful feature from another language could be implemented in lisp.
One benefit is that code == data. It lends itself to all kinds of meta-programming fun, the REPL, etc. The parenthesis become invisible to the reader after a while and for me, the difficulty in understanding lisp code is not the parenthesis at all, but knowing the behavior of the different special forms and macros and functions available in common-lisp (read the documentation for LOOP sometime for a good time).
Oh, here's a good example of the complexities of LOOP from "Practical Common Lisp" https://gigamonkeys.com/book/loop-for-black-belts.html https://gigamonkeys.com/book/loop-for-black-belts.html
As that chapter describes, LOOP is a DSL just for doing "looping things", of which there are a lot! But it's implemented as a macro, not a special keyword that can only do one boring thing.
(loop for i in *random*
counting (evenp i) into evens
counting (oddp i) into odds
summing i into total
maximizing i into max
minimizing i into min
finally (return (list min max total evens odds)))
- lobstrosity420 4y agoI'm following the Common Lisp tutorial that was posted here on HN a little while ago, and the section where it goes over the little loop DSL made me take a step back and reconsider! It's pretty wild. I'm definitely starting to see the beauty of it all though.
- medo-bear 4y agoi would also like to add that the benefit of doing it in a lisp like Common Lisp is that you get Smalltalk-type interactive development environment (if you want to see how cool this can be on a system level try StumpWM, fire up SWANK, and live-hack your window manager), AND a language with implementations (CL is an ANSI language specification abstracted from any one implementation) that have C-level benchmark speed, eg. SBCL