4 ms·
There is an important difference between types and objects: types are basic building blocks. An email is not a basic building block nor is money. In the mature
by croo 4y ago
There is an important difference between types and objects: types are basic building blocks. An email is not a basic building block nor is money. In the mature ecosystem of Java there are libs and standard libraries that handles these problems some are even in the standard library (timestamp with timezone, url...)
It would be nice to have stuff for these in the standard libraries but currencies are a moving target and needs constant update to handle the quirks of the real world. For the same reason it's extremely hard to create an "Address" class that handles every possible scenario.
In my book the string is a great way to store a country of origin because everything else depends on the usage of that information.
- mejutoco 4y agoIMO the difference between types and objects is that objects have state and behaviour, whereas types only have state.
- grumpyprole 4y agoTo compare them this way is likely to cause confusion. A type (of a term) represents the set of all possible values for a particular term. An "object" in OOP, does not have any formal definition, but is typically a first-class module with mutable state. As such, they can be represented by a term and therefore can have a type.
- mejutoco 4y ago> they can be represented by a term and therefore can have a type. It is informative, I see what you mean. Let me try again following your terms: An object is a type plus behaviour (mutable state).
- grumpyprole 4y agoI am saying that an object has a type, rather than is a type or some augmentation of it. An object is a term-level construction and therefore is not really comparable to a type. Types can be given to both state and behaviour. For example, a function type describes pure behaviour. Note that statically-typed OOP languages have a name for the nominal types of objects: "classes". One could say that a class is a type representing both state and behaviour.
- mejutoco 4y agoFair enough, seems much more correct: A class is a type representing both state and behaviour.
- grumpyprole 4y ago> types are basic building blocks Yes but they should also be compositional, one should build larger types from smaller types. This is how we scale to solving difficult problems. > but currencies are a moving target and needs constant update to handle the quirks of the real world. This is a separate issue orthogonal to types. The problem of modelling the real world and what models might be more generally useful. No model is perfect, all have trade-offs. > In my book the string is a great way to store a country of origin As an implementation using a string sounds pragmatic, but that should not be its type! You should still create a currency type and parse into it. Then you won't accidentally pass an arbitrary string to a parameter that is supposed to be a currency.