Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 142107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:53:02+00:00 2026-05-11T07:53:02+00:00

One of the arguments I’ve heard against functional languages is that single assignment coding

  • 0

One of the arguments I’ve heard against functional languages is that single assignment coding is too hard, or at least significantly harder than ‘normal’ programming.

But looking through my code, I realized that I really don’t have many (any?) use patterns that can’t be written just as well using single assignment form if you’re writing in a reasonably modern language.

So what are the use cases for variables that vary within a single invocation of their scope? Bearing in mind that loop indexes, parameters, and other scope bound values that vary between invocations aren’t multiple assignments in this case (unless you have to change them in the body for some reason), and assuming that you are writing in something a far enough above the assembly language level, where you can write things like

values.sum 

or (in case sum isn’t provided)

function collection.sum --> inject(zero, function (v,t) --> t+v ) 

and

x = if a > b then a else b 

or

n = case s    /^\d*$/ : s.to_int   ''      : 0   '*'     : a.length   '?'     : a.length.random   else    fail 'I don't know how many you want' 

when you need to, and have list comprehensions, map/collect, and so forth available.

Do you find that you still want/need mutable variables in such an environment, and if so, what for?

To clarify, I’m not asking for a recitation of the objections to SSA form, but rather concrete examples where those objections would apply. I’m looking for bits of code that are clear and concise with mutable variables and couldn’t be written so without them.

My favorite examples so far (and the best objection I expect to them):

  1. Paul Johnson’s Fisher-Yates algorithm answer, which is pretty strong when you include the big-O constraints. But then, as catulahoops points out, the big-O issue isn’t tied to the SSA question, but rather to having mutable data types, and with that set aside the algorithm can be written rather clearly in SSA:

     shuffle(Lst) ->      array:to_list(shuffle(array:from_list(Lst), erlang:length(Lst) - 1)).  shuffle(Array, 0) -> Array;  shuffle(Array, N) ->      K = random:uniform(N) - 1,      Ek = array:get(K, Array),      En = array:get(N, Array),      shuffle(array:set(K, En, array:set(N, Ek, Array)), N-1). 
  2. jpalecek’s area of a polygon example:

    def area(figure : List[Point]) : Float = {   if(figure.empty) return 0   val last = figure(0)   var first= figure(0)   val ret = 0   for (pt <- figure) {     ret+=crossprod(last - first, pt - first)     last = pt   }   ret } 

    which might still be written something like:

    def area(figure : List[Point]) : Float = {     if figure.length < 3         0       else         var a = figure(0)         var b = figure(1)         var c = figure(2)         if figure.length == 3             magnitude(crossproduct(b-a,c-a))           else              foldLeft((0,a,b))(figure.rest)) {                 ((t,a,b),c) => (t+area([a,b,c]),a,c)                } 

    Or, since some people object to the density of this formulation, it could be recast:

    def area([])    = 0.0   # An empty figure has no area def area([_])   = 0.0   # ...nor does a point def area([_,_]) = 0.0   # ...or a line segment def area([a,b,c]) =     # The area of a triangle can be found directly     magnitude(crossproduct(b-a,c-a)) def area(figure) =      # For larger figures, reduce to triangles and sum     as_triangles(figure).collect(area).sum  def as_triangles([])      = []  # No triangles without at least three points def as_triangles([_])     = [] def as_triangles([_,_])   = [] def as_triangles([a,b,c | rest) = [[a,b,c] | as_triangles([a,c | rest])] 
  3. Princess’s point about the difficulty of implementing O(1) queues with immutable structures is interesting (and may well provide the basis for a compelling example) but as stated it’s fundamentally about the mutability of the data structure, and not directly about the multiple assignment issue.

  4. I’m intrigued by the Sieve of Eratosthenes answer, but unconvinced. The proper big-O, pull as many primes as you’d like generator given in the paper he cited does not look easy to implement correctly with or without SSA.


Well, thanks everyone for trying. As most of the answers turned out to be either 1) based on mutable data structures, not on single-assignment, and 2) to the extent they were about single assignment form easily countered by practitioners skilled in the art, I’m going to strike the line from my talk and / or restructure (maybe have it in backup as a discussion topic in the unlikely event I run out of words before I run out of time).

Thanks again.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:53:02+00:00Added an answer on May 11, 2026 at 7:53 am

    I’ve never identified such a case. And while you can always just invent new names, as in conversion to SSA form, I actually find it’s easy and natural for each value to have its own name. A language like Haskell gives me a lot of choices about which values to name, and two different places to put name bindings (let and where). I find the single-assignment form quite natural and not at all difficult.

    I do occasionally miss being able to have pointers to mutable objects on the heap. But these things have no names, so it’s not the same objection. (And I also find that when I use mutable objects on the heap, I tend to write more bugs!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You are correct. The CF TreeView is a simple wrapper… May 11, 2026 at 3:12 pm
  • added an answer I think you can use jQuery UI library's datepicker: use… May 11, 2026 at 3:12 pm
  • added an answer The first one will work fine. 100 will be converted… May 11, 2026 at 3:12 pm

Related Questions

One of the arguments I've heard against functional languages is that single assignment coding
Say I have a class called PermissionManager which should only exist once for my
I have a multiple menu's on my page which all use the same mouseover
Suppose I want to create a set of observers based on type. That is
In a C# program, I have an abstract base class with a static Create

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.