osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

can someone explain the concept of "strings (or whatever) being immutable"


On Tuesday, June 3, 2014 10:36:37 AM UTC+5:30, Deb Wyatt wrote:
> That was just the first question.  What does immutable really mean
> if you can add items to a list? and concatenate strings?  I don't
> understand enough to even ask a comprehensible question, I guess.

It is with some pleasure that I see this question: Most people who are
clueless have no clue that they are clueless -- also called the
Dunning-Kr?ger effect.

Be assured that this question is much harder and problematic than people believe.

There are earlier discussions on this on this list, eg

https://groups.google.com/forum/#!topic/comp.lang.python/023NLi4XXR4[126-150-false]

[Sorry the archive thread is too broken to quote meaningfully]

Here's a short(!) summary:
Programmer's live in 2 worlds.
1. A timeless mathematical world. Philosophers call this the platonic world
after Plato's allegory of the cave:
http://en.wikipedia.org/wiki/Allegory_of_the_Cave

2. An in-time world that is called "Empirical" in philosophy

You cannot reject 2 because your programs run in time and produce
effects (hopefully!) in the empirical world.

You cannot reject 1 because the time at which you - the programmer -
function is in another space-time from the run-time of your program.
The very fact that you write a program means you have (been able to)
algorithmize out a complex *process* into a simpler recipe - a *program*.

Once you see the need for both worldviews 1 and 2 you will see why even the most
deft=footed trip up doing this dance. eg. When someone says:
3 is immutable but [1,2,3] is mutable this is not a necessary fact but
an incidental choice of python's semantics.

Functional languages make everything immutable

Assembly language makes everything mutable -- you can self-modify the
code containing 3 as an immediate operand in an instruction into one containing
something else.?

However the basic (necessary not incidental) fact remains - you need to dance between
the two worldviews:
- platonic and empiric (in traditional philosophy lingo)
- declarative and imperative (in computer theory lingo)
- FP and OO styles (the two major fashions in programming languages)


Choose absolutely only the first and your program can have no effect
whatever including writing a result to the screen

Choose absolutely only the second that you can have no comprehension of your
program's semantics.

You can find this further elaborated on my blog whose title is a summarization 
of what Ive written above:  http://blog.languager.org/search/label/FP

--------------
?Heck! Steven showed some trick to make it happen in python also
But Ive not fathomed the black magic!