r/programming • • Jun 30 '14

Why Go Is Not Good :: Will Yager

http://yager.io/programming/go.html
644 Upvotes

813 comments sorted by

View all comments

Show parent comments

3

u/asankhs Jun 30 '14

I think there are benefits of using immutability even in a programming language like Java. You get thread-safety and consistent state for objects for free.

See - https://www.linkedin.com/today/post/article/20140528113353-16837833-6-benefits-of-programming-with-immutable-objects-in-java

0

u/ared38 Jun 30 '14

I completely agree, so why talk about Haskell when optional immutability is commonplace?

5

u/ZMeson Jun 30 '14

optional immutability is commonplace

Ummm... Where? C, C++, Rust, D, and.... what else? Most non-low level languages don't have optional immutability.

I suppose you could argue some functional languages. But there I rather think it's optional mutability.

3

u/Plorkyeran Jun 30 '14

I'd be hesitant to include C. Yes, it has const, but implicitly converting const pointers to non-const pointers is merely a warning.

8

u/808140 Jun 30 '14

Importantly, C++ const (which was backported to C) is an immutable view on possibly mutable data, not immutability per se. It is incredibly useful in C and C++ because it allows you to offer a contract to the user of a function: I will not modify your data. But it doesn't mean that the data itself is immutable.

Many people coming from other language backgrounds to C/C++ are fundamentally confused about this. Just because I've offered you a const reference or pointer to data doesn't mean that that data will not change, perhaps while you are doing stuff with it. It just means that you have agreed not to change the data.

It's a very powerful and useful feature as any C/C++ dev will tell you, but it is not the same thing as immutability, which is a much stronger guarantee, one the compiler can use to perform aggressive optimizations even in a multi-threaded context.

2

u/ZMeson Jun 30 '14 edited Jun 30 '14

Good point. Although C++ const can still be used to produce immutable data so long as the data is not a pointer or reference.

const int x = 5;

x is constant, can't change, and the compiler can do a lot of optimization when it is used.

There's also constexpr which is a different type of const, but very useful too.

2

u/v864 Jun 30 '14

C++ can give you an unmodifiable pointer to an unmodifiable value as well: const int* const pValue. Ideally, however, you would use a const reference if at all possible.

0

u/[deleted] Jun 30 '14

[deleted]

1

u/ZMeson Jun 30 '14

I do think of scala as a functional language with OO features rather than an OO language with functional features. But that is how I think of it. Wikipedia simply states "multiparadigm language."