Archive for November, 2009

Comparing Prog. Lang in terms of Operator Precedence

November 20, 2009

(I started this blog post yesterday, saved all my work as a draft, and now it’s gone!  I’m not going to do nearly as much work as I did yesterday, so…)

This post is primarily a request for help from y’all — I’m going to create three rough categories, and ask you to place your favorite language therein, or correct my classification, if you wish…

A twitter follower suggested that programming languages could be compared by how they treat operators.

I’m not an expert, but here’s my take on it:

  • compiled languages, notably C/C++ and Fortran, have very detailed operator precedence and variable rules (such as a scalar variable may only be modified once between any two “sequence points”) — this allows optimizing compilers, etc. to make whatever changes they want, as long as the results are consistent.
  • interpreted/scripting languages, such as Python and Ruby, have operator precedence rules, but not quite as strict — and some have no such rules
  • then there are those that have no operator precedence, for various reasons:
    Lisp-like languages (I’m studying Clojure, right now) don’t need them because everything is post-fix and parentheses take care of order of operation);
    in SmallTalk, everything is a method, and there are rules about order of operation of arguments/grouping, but nothing more;
    and some languages don’t care, or behave very differently — I’m thinking of OCaml here (the last language I learned), in which, I found, that operators have a lower “precedence” than even function arguments — but as a functional programming language, functions themselves are the primary “object”…  [that’s not quite right, and perhaps pejorative.  Maybe an advocate could explain better]
  • anything else — here’s your chance to weigh in.   Let me know how your favorite language compares. And, Tracy, if you read this, let me know if it helps, or makes sense…