Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Declare mutability on both ends

Name: Anonymous 2014-08-04 16:55

How come everyone keeps saying that mutable state is the master evil and the source of the worst bugs, yet no language implements the simple idea of declaring mutability on the variable's side? Something like this:

state_type mutableState modifiedBy { foo };

void foo( int x, &state_type mutableState );
//void bar( int x, &state_type mutableState ); -- compile-time error, bar doesn't have the rights to fuck with this var


This would have several benefits:

- superfluous information means more safety (e.g. the compiler won't let you accidentally modify state in a function that's not supposed to)
- self-documenting (seeing what procedures modify the var often reveals the var's purpose)
- debugging (if some asshead on your team starts writing shitcode that modifies your state needlessly, he'll have to add his functions to the declaration)

It also may be useful to make this mechanism more flexible, e.g. add the ability to give read-only rights or modify-once rights to a function. Thus if you give read-write permissons to one function and read permissions to five functions, you can rest assured that the broadcast of the var to those 5 functions will be safe and the only place where the var is actually updated is that one function. This has obvious benefits for concurrency, of course.

The question is, why hasn't anyone implemented that in a programming language? It's so simple yet so beneficial. No type-foo, no dependent types or monads, just simple declarations of what code has the rights to which mutable variable. So why not?

Name: Anonymous 2014-08-05 4:37

>>2
Haskell is shit.

>>4
main()

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List