Imagine that you have a binding language that enables you to bind values of your system in a text document e.g.
- a directory with key-value pairs and more directories
- or tables that act as collection of rows where each row in the same table has the same set of keys with different values
You can access these values by addressing the chain of directories followed by an optional table and finally the key name…
Here are some examples:
Dear [[input.recipient.name]],
[[UPPER(Input.message)]]
Best regards,
[[user.name]]
The binding language can be seen within the double brackets. E.g. user.name
is the name of the user creating the document. user
is the name of a directory or table and name
the name of the key.
Creating this template would result in a greeting line like “Best regards,\nLotes”.
Also notice that the language provides function calls to built-in functions like UPPER(string).
Ok… puh that was the introduction…
Now imagine that following is given:
- there is a table
students
whose rows are of type STUDENT(name: string, studentId: number) - there is a table
employees
whose rows are of type EMPLOYEE(name: string, salary: number) - a function GET_NAME(person: P) where P needs to be determined…
Now my problem:
Either the typesystem is loose or it is strict.
Typescript
is loose, because the structure of the type is making the type. Its name is very unimportant. If two types have the same structure, they are the same. For example, if P is interface {name: string}
both table row types are implicitly of interface P.
C#
is strict, because the name of the type and their type dependencies have priority over its structure. If two types have the same structure, they are different except they share the same type dependencies. P is again interface {name: string}
, but the table row types need to implement P in order to make GET_NAME work.
My final and maybe naive question is: what are the benefits and pitfalls for each decision? Strict or loose?
Because I think there is no middle way of deciding this. Once you have chosen a way, every action towards the opposite solution might end up in a hack… that is some gut feeling.
Does someone know this problem? Are there any pointers or did I create only a problem in my head? I called these principles loose and strict, maybe there are other names for them?