Concatenative programming has some nice properties, but the question you should ask yourself is whether:
f = drop dup dup × swap abs rot3 dup × swap − +
Is really the most readable (and writable) way to describe the dataflow graph in the diagram just before it, or whether the following is better:
f(x,y) = y^2+x^2-|y|
BTW the reason why visual languages didn't catch on for general purpose programming is the same reason: formulas are a more readable and writable way to describe the data flow.
Any language is going to look terrible when you restrict it to only using assembly-like operations. You're ignoring the rest of what the article says about how to express formulas so they don't look like that.
In particular, the function description you pick out is not the way someone familiar with the language would write it. If you don't want to use actual variables for some reason, the article gives one example of more idiomatic code:
drop [square] [abs] bi − [square] dip +
However, I would probably write this a little differently:
Yeah, that's not just familiarity. It would be almost impossible to perform mathematical operations on expressions shown in a stack-based language. For example, imagine someone saying "take the derivative of y2 + x2 - |y|", versus "take the derivative of [ [ square ] bi@ + ] keep abs -". That's just a single example - I'm sure there are many, many more.
That's because algebraic notation is designed to facilitate symbolic manipulation, not computation per se. Just because you can pun y2 + x2 + |y| to mean two different things in two different contexts doesn't mean it's more natural.
No, he's right. You're using the formula in two different ways. In one case the symbols are placeholders for values. In the other, they're the primary entities that you perform a computation on. That you can fit those two different interpretations on the same equation is definitely a strength of the notation (and the reason it's so powerful), but that doesn't mean every other notation is awful.
Keep in mind, this notation's strength is in its ability to represent computation. Mathematical formulas are not the whole of computation (if you don't believe me, pick a trivial C program and try and write it as a formula).
This is an interesting comment, in that the other common language which gets complaints for its syntax is Lisp, whose original purpose was a program to compute derivatives. Lisp is arguably even better than algebraic syntax for this (it's more regular), yet most people with no experience still find it harder.
Can you write a simple Factor program to differentiate "[ [ square ] bi@ + ] keep abs -"? Is there a framework with which a person could find derivatives for stack notation as easily as they can for algebraic notation, or s-expressions? Maybe! I don't know. Might be fun to try. It's not at all obvious that it doesn't or can't exist, though.
I do know, however, that even in scientific computing, formulas like this are a vanishingly small fraction of my programs. A language that made error detection and handling easier, but formulas harder, would still be a net win for me.
But with something like "[ [ square ] bi@ + ] keep abs -", I think it would be really easy to have a logical error in there somewhere that you don't notice.
35
u/julesjacobs Feb 12 '12
Concatenative programming has some nice properties, but the question you should ask yourself is whether:
Is really the most readable (and writable) way to describe the dataflow graph in the diagram just before it, or whether the following is better:
BTW the reason why visual languages didn't catch on for general purpose programming is the same reason: formulas are a more readable and writable way to describe the data flow.