This post originated from an RSS feed registered with Java Buzz
by Weiqi Gao.
Original Post: X = X + 1 Is Evil
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Rich Hickey (in an Artima interview): For example, take a mutable Date class that has year, month, and day. To me, changing a date is like trying to change 42 into 43.
This is as close an elevator pitch for pure functional programming as I've ever seen.
Rich's analogy reminds me of the most painful experience I had when I started programming. So painful that I suppressed that memory ever since. That was when I first saw
x=x + 1;
That's impossible, I thought. That's plainly wrong. It took me days or weeks to "get over" it. My mind fought the rationalization for such stupidity:
The equal sign is not a mathematical equal sign but an assignment. (What?)
The read x and the blue x means different things. (What?)
The blue one is the value before the assignment, and the red after. (Before?)
It's really the location. (Location or value, which is it?)
Of course, given no other practical alternatives, I gave in just like everyone else. And now we are in this concurrency crisis. For countless times, we've been called to "look at" problems where a program is not "working" because the assignments are not happening in the order the programmer envisioned. There clearly is a systemic problem.
Rich Hickey's solution is his clojure programming language. I dabbled with it a bit in the past year. I have gotten tremendous value out of Mark Volkmann's write ups on Clojure and STM.
In Mark's latest tweets and emails, he often mentions these three things in one breath:
Immutable objects
Persistent data structures
Transactional software memory
I wonder if that will become the rallying cry for Clojure and Clojure-like alternatives to main stream languages. If so, a paradigm shift is afoot.
Remember OO got traction after its "encapsulation, inheritance, and polymorephism" motto was coined.