• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mutating state inside a function

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I understand why mutating instance variables is a bad thing.
But what about mutating state inside a function? To my knowledge, variables inside the function are allocated in the stack and not in the heap, therefore they are not objects of any concurrency issue.

Scala and other functional languages say you should not mutate any state. Why it is so?
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gabriel Beres wrote:Hey,

I understand why mutating instance variables is a bad thing.
But what about mutating state inside a function? To my knowledge, variables inside the function are allocated in the stack and not in the heap, therefore they are not objects of any concurrency issue.

Scala and other functional languages say you should not mutate any state. Why it is so?



That is a good question. Have a look here about Referential Transparency to better answer your question.

http://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29
reply
    Bookmark Topic Watch Topic
  • New Topic