What is a strong type?
The so-called strong type, saying that it is possible. Out of type, such as book.name, book.price. Then what is it. Can't come out? Naturally, the indirect type, such as a collection, table, etc. Other structures, for this type, we can only find objects through its index, such as Books [0]. Maybe it's not something that readers can't see it now, but for this. Can't come out, call is not intuitive is the first, more operation is more, it is difficult to understand, so it is very It is necessary to have strong types, especially (should also be) when we know these. The structure that does not come out. Maybe I said that the readers didn't understand, let us give an example.
Very typical example is when we use DataTable, we save data on a piece of data, we only use this DataTable to save this data table, then I will definitely know this DataTable structure, why can't I ? Coming out? For example, Customerrow1.customername? Is this called not very convenient? It is more than possible. Can't come out, and you can know this strong type of public structure when compile, you can also write it as a real type (such as a method that is delivered to a special handling) In summary, it is a predictable, type safe. The following is a strong type of advantages and disadvantages:
advantage:
The call is simple. Predictable, type is safe. You can increase the codes of codes to make the code logic clearer.
Disadvantages:
Tightly with the structural binding, once the structure of the source changes, strong types need to change.
The advantage is not to say, everyone also looks at its advantages, the light evaluation simplifies calls and clear logic I want everyone to consider it. I want to talk about its shortcomings, how can I get a shortcoming of it to really use it? As we all know, strong type is to make a known structure to make a type, but this known structure may change over time, how do we respond to this structure change?
Code generator rescue
Now that we know that the structure is very likely to change, then the re-handwritten code is not practical. In this case, why should we use the code generator tool? Using the code generator, we can dynamically generate strong types. After each structure changes, we only need to regenerate once, it is not necessary to write, so it uses a strong type of advantage, but also overcomes its shortcomings, not Do you have two in one fell? However, wait, the code generator is not so easy, the code generator is indeed a good idea, but because the application code generator, the code generator has brought the shortcomings of the code generator, that is, after the generation Any changes will be wrapped when regenerated. This is very cruel, which affects the efficiency of code generators and whether doubts generator can really improve efficiency? How to do it? Is there any solution? The author's solution is based on the author's own code generator DCG. I add this change to DCG. For details, you can see the article about DCG version 1.4.1.1. This way I can someway, pay attention to solve the problem of code generator to some extent. Another way to use according to specific situations is if your output is an OOP language, you can consider the structural pattern in the application design mode to make the part generated by the code generator forever, and the specific method The implementation is outside the scope of the code generator, so it is not afraid that each change will be rushed away by the code generator. But I have to declare that this is not a good way. The reason is very simple. This will lead to the programming of the program. I personally recommend that OO design is to be biased towards responsibilities, not problem-oriented. So I still recommend the use of DCG's change retention, but the decision is still in everyone's hand. to sum up
Strong type has many unique advantages, but there is also a disadvantage that it can be overcome through the code generator, and the code generator also has a disadvantage, but some code generators provide a function of overcoming its corresponding disadvantages. For example, DCG . Therefore, the author feels that the use of good dynamic code generators to generate strong types that can be considered in the design, especially the value of this approach and its efficient ratio!