4 ms·
In 99% of programming languages, infix operations are only used for arithmetic -- and more than 99% of the programming I do doesn't involve that. Even the nume
by ken 8y ago
In 99% of programming languages, infix operations are only used for arithmetic -- and more than 99% of the programming I do doesn't involve that. Even the numerics software I've written is >90% non-numeric parts.
Arithmetic doesn't even look right in programming languages with infix operators. Go to the "Chalk is still one of the primary tools of mathematicians" article here, and try typing the inequality in Java. Mathematicians aren't writing "Math.floor()" and "% 2" on their blackboards.
I think you're optimizing for the wrong thing. Arguing that we need infix operations for 1% of our programs, so that arithmetic looks like how we entered it on a TI-81 or Apple II, is a false economy. It was a good tradeoff 25 or 50 years ago, but the majority of programming has moved past writing programs in terms of arithmetic on registers.
That said, there is a nifty macro [1] which adds infix support to Clojure, if you really want that. It even supports symbols like "√", unlike any other language I can think of!
[1]: https://github.com/rm-hull/infix https://github.com/rm-hull/infix
- lmm 8y ago> In 99% of programming languages, infix operations are only used for arithmetic I've been spoiled by Scala, but certainly most languages allow a "subject.verb(object)" style for general-purpose code, and that reads a lot better (particularly for those looking from the business domain) than "(verb subject object)". > It even supports symbols like "√", unlike any other language I can think of! Heh, again I'm spoiled by Scala, where √ is just another method/operator (there's no distinction) name if you want it to be.
- ken 8y ago> most languages allow a "subject.verb(object)" style for general-purpose code, and that reads a lot better Why do you think this? Programming isn't natural language, and I don't even know what the "subject" or "object" is in most cases.
- lmm 8y ago> Programming isn't natural language It's not, but it should be close; readability is important, and particularly when you want to express domain logic it's important to be able to hew closely to the actual language of the domain. Arithmetic is the most obvious example of this but it's just as true for other domains.
- yogthos 8y agoYou're right readability is important, and Scala fails terribly in that department. I worked with Scala for around 6 months or so at one point, and I was still constantly looking things up after months of using the language. There's simply too much syntax and weird quirks in the language that it becomes impossible to keep it all in your head.
- lmm 8y agoNot my experience - I found Scala's syntax is a lot more consistent than most mainstream languages (though, yes, it certainly doesn't go as far as lisps). Operators are just normal methods. Rather than complex rules about which constructs require braces, everything permits an expression or you can put a braced block of statements anywhere you could put an expression. Rather than a bunch of different special case syntaxes for collections / async / possibly-absent values, you have a single lightweight syntactic sugar (for/yield) that translates directly into plain old method calls. There are some libraries out there that make poor choices of method name, but that's about all.
- yogthos 8y agoMy experience with Scala matches this pretty closely https://www.reddit.com/r/scala/comments/4246qc/heres_why_scala_sucks/ https://www.reddit.com/r/scala/comments/4246qc/heres_why_sca...
- lmm 8y agoThat's a strange set of complaints for a clojure advocate, since most of what they're complaining about is not too much syntax but too little - no mandatory braces, mandatory brackets, mandatory types. Indeed "a -> b" for "(a, b)" is not syntax or even a macro, but just a function. _ is genuinely costly syntax, as are by-name parameters (though less costly in an age of IDEs). I consider _ to be worth its while (indeed I miss it a lot when writing lambdas in any other language); if you're going to have syntax in your language at all then it's one of the most general-purpose, effective constructs I've seen.
- lincpa 8y agoScala has three styles, OO, FP, Python. When learning, people can find their comfortable style. But at work, any style of preference must endure the other two styles.
- vmchale 8y agoPeople use non-arithmetic infix operators in Haskell constantly. It's great. It's also pretty easy to add prefix operators in e.g. Haskell or ATS (for something like square root)