Make it immutable unless you've got a good reason not to.
For example, in #Python, prefer tuples to lists.
good advice. Though a frozen list is probably a better suggestion as a tuple is subtly different than a list.
@freemo I haven't really worked with frozen lists. Can you give an example where a tuple wouldn't suffice?
Quite a few differences, but for a concrete example here is one...
Write a python function that takes a single argument, a collection of integers of any length strictly containing integer type.. have the function add all the members of the collection together and return the value. Ensure that if the wrong type of value is passed in that it fails at **compile** time, not runtime.
If you use typles to represent immutable lists you cant do this. If you use frozen lists you can..
Worse yet you wont realize it is even a problem until you actually come across some function in a library that does this (or worse yet explicitly checks the type).. so you may have your whole app coded up before you realize you have to change all your tuples to lists..
So yea the proper way to do this is to feeze your lists and not consider a tuple interchangable with a list, they are not.
@freemo Hmm. I'm not even sure how to write that function using a list. Is it done with type hints?
I wasn't aware that tuples and lists interacted with types differently.
@peterdrake yes its done with type hints. There is no way with tupples using type hints to say "a tuple of any size where all members are integers".
@freemo @peterdrake Huh,... Not sure if I misunderstand you but:
```
from typing import Tuple
def function(intup: Tuple[int, ...]):
print("%s" % (intup,))
```
would literally be it. Type hint `Tuple[int, ...]` literally means - tuple of any size, with all items being integers.
With that particular type hint you could pass in (5, "hello") since it only type checks the first entry and all other entries can be anything.
@freemo @peterdrake As far as Python, interpreter, is concerned - you can still pass anything there. Type hints are just that - runtime doesn't enforce anything. But any decent toolkit will read this as - tuple of any size with all items being int.
Ok so just checked and the standard is explicitly written to accept it as a homogonous type if there is just one argument and the ellipsis
@freemo @casastorta Could you use Sequence as a type?
@peterdrake @freemo Not completely sure what's the ask, but along the same line as we've discussed before in this thread, according to Python doc - yes:
https://docs.python.org/3/library/typing.html#type-aliases
It's literally given as example:
```
def broadcast_message(message: str, servers: Sequence[Server]) -> None:
...
```