Automatic
In normal Python, you can mix types freely:Manual
You can also set the types yourself.Reading values
A key (or an index) might not exist, so Baretta gives you three ways to read a value. Pick the one that matches what you want to happen when it is missing.
No style ever returns
None. The only ways a read can fail are hello[key], which is fatal, and find, which you handle yourself.
Index: hello[key]
Use this when the key must exist.
get with a default
Use this when you always want a value.
get without a default
If you leave the default out, Baretta uses the default value of the type. The compiler decides this, so you never have to write it.
This is different from Python, where
dict.get(key) returns None when the key is missing. Baretta has no None value, so it returns the default of the type instead.find
Use find when you want to handle the missing key yourself. It returns a Lookup.
Lists
Lists work the same way. A missing value means the index is out of range.Which style should I use?
See Lookup for the methods of
find and for functions that can fail.