
The single assignment cargo cult - nickb
http://tonyarcieri.org/articles/2008/07/26/the-single-assignment-cargo-cult
======
jamesbritt
"The overwhelming majority of programmers have only used languages with
multiple assignment. Multiple assignment is the de facto standard, and single
assignment is one of the things that makes Erlang weird to new programmers. "

So what? "But it feels weird!" is not an argument. It is an excuse.

It's like when people dismiss Lisp because of all those parentheses; you get
over it, and eventually find more interesting things to focus on.

~~~
qwph
Although some people, when faced with a problem they don't understand, will
just give up and do something else instead.

Admittedly, I don't have any metrics on how many people have abandoned Erlang
because of single assignment, or Lisp because of the parentheses, but I'm sure
such people exist.

And you might say that it's their loss, and I'd probably agree with you.

~~~
davidw
> And you might say that it's their loss, and I'd probably agree with you.

Enough people give up, though, and it's your loss as a user of that language.
Say out of every 100 people that give up, 1 is someone who is capable of
contributing something good back, and 10 are people who might have answered
questions on mailing lists or IRC, or written some blog entries or something.
Languages do have network effects.

~~~
jamesbritt
Sure, but it's hard to say if adding or omitting a feature is going to be a
net win for a growing user base. All things being equal, I'd rather a somewhat
smaller user base for a language that is more easily internalized than a
larger user base where you really do need the extra help to understand all the
quirks of a language.

Were that language design so simple ...

~~~
davidw
> Sure, but it's hard to say if adding or omitting a feature is going to be a
> net win for a growing user base.

I meant more along the lines of libraries to do useful things, which is a win
pretty much any way you look at it.

------
icky
_> If you’re writing code like in Damien’s example and you want to be able to
insert lines without changing a bunch of variable names, I have a tip:
increment by 10._

    
    
        10 PRINT "BASIC LIVES AGAIN!!"
        20 GOTO 10

------
silentbicycle
So essentially, what they're saying is, Erlang doesn't let you program _in C_?
So much for _that_ language, eh? Psh.

-

I don't have any real Erlang experience, but in every functional language I've
ever touched, doing that would involve function composition, not manually
stuffing the value thus far into a box. (Wasn't Erlang at some point based on
Prolog, btw?)

------
marijn
The dichotomy between single assignment and variable-name reuse seems to be
false. In OCaml, you can just rebind the same variable name again halfway a
function body, which will cause a _new_ variable with that name to be bound,
having a scope of the rest of the function body. Everybody wins.

~~~
silentbicycle
Or, you can use explicitly use a reference variable or mutable variable: (#
lines are input, - : lines are response)

    
    
      type egg_carton = { mutable eggs: int }
      let my_c = { eggs=12 }
      let breakfast carton = carton.eggs <- carton.eggs - 2
    
      # my_c;;
      - : egg_carton = {eggs = 12}
      # breakfast my_c;;
      - : unit = ()
      # my_c;;
      - : egg_carton = {eggs = 10}
    

and

    
    
      type food = Pancakes | Eggs
      let eat f = f := None
      let short_stack = ref (Some Pancakes)
    
      # short_stack;;
      - : food option ref = { contents = Some Pancakes }
      # eat short_stack;;
      - : unit = ()
      # short_stack;;
      - : food option ref = {contents = None}
    

I think the best part here is that OCaml doesn't use = to assign values, it
uses a left arrow (<-) for modifying mutable variables and := for updating
what value a reference is pointing to.

------
cypress-hill
he beats us over the head with the fact that gcc uses ssa yet seems to think
that this fact makes general mutability desirable at the language level. the
compiler is not a magic wand. hey why not make everything a string too? works
for tcl!!!!

~~~
davidw
Everything is representable as a string in Tcl, but internally that's not the
case, nor has it been for over 10 years.

Tcl's a very interesting language by the way - more than most people give it
credit for - and was very successful in its heyday.

