4 ms·
> Since Go doesn't have a concept of immutable data types (except consts) I believe this is incorrect. Strings are immutable, for example. You could also say
by hdjjhhvvhga 4y ago
> Since Go doesn't have a concept of immutable data types (except consts)
I believe this is incorrect. Strings are immutable, for example. You could also say the same about pointers and maybe a few other data types.
- bheadmaster 4y agoYou are right. Now that I've had more time to think about it, I think the problem of Python-like tuples in Go is that they require Pythonesque everything-is-a-reference paradigm in order to function the same way, otherwise they just act as heterogenous arrays in Go (which exist as arrays of empty interfaces, with a slight runtime cost). Go is mainly value-oriented language like C, with the exception of built-in container types and strings (and maybe a few others that slipped my mind). I suppose that adding fixed-type pass-by-value tuples would essencially be reimplementing struct. Go doesn't like duplicating functionality.
- eru 4y agoSee my other comment: tuples should be thought of as syntactic sugar over structs, not arrays. Whether to pass by reference or value and other design decisions should probably be taken (as much as practicable) from the design decisions for structs in your language.