In the front of the article, first of all, define, the "language" (A) here refers to "language and the use of the language can be very easy to call the basic class library and free or low-cost access to Third-party libraries and open source Class library" (B). In many cases, the context of the choice of "language" in "language" talks refers to B.
One of the purposes of selecting a multi-language hybrid development is to use a class library or an important feature in one of these languages. For example, in OpenCV, the small amount of computation uses a lot of C + + STL data structure and algorithm, instead of using C to achieve a copy.
I've been studying the SIFT operator. A C # written SIFT code processing a 600x600 image processing time is about a minute, and a C-write sift code can be seconds off such an image, so I have to use c+c# mixed programming: In the application layer using C #, at the bottom of the use of C. In order to conveniently use C # to call C, you have to use the C++/CLI.
My last choice of work mode is this: Use C # for application algorithm development, prototyping and presentation (winform/silverlight), and use C + + for final product development (using C # validated algorithms). Prototype development can be done on Windows, but the final code does not necessarily run under Windows. To reduce the cost of translating code from prototype to product, I must make sure that the core classes of prototyping and product development are as similar as possible. To this end, I have introduced a pure C + + layer, forming the following language level:
The role of each layer:
1, c/C + + layer to the main. There are 3 reasons:
(1) Portability. After all, C # needs the CLR, where there is no CLR, and it can't be used.
(2) Performance and memory controllable
(3) Most of the core algorithms have C/p + + version
2, pure C + + layer. C/C + + layer of the API is basically all of the style of the, difficult to use, therefore, need to be encapsulated into objects. I encapsulated the bottom layer into a large object smartimage. Encapsulation in pure C + + without C++/CLI encapsulation is because pure C + + does not require a complex run-time environment.
3, C++/CLI layer. C + + for the use of a lot more, but compared to C #, it is more difficult. and many image processing projects, most of the workload is the algorithm parameter selection, combination and verification, therefore, it is necessary to encapsulate again to facilitate the upper call. The C++/CLI and pure C + + layers are almost one-to-one mappings.
4, Application layer. With the above three layers of work, you can use the elegant C # to do the day-to-day work. I am an otaku, how to Demo demo, demo case, demo progress? A good choice is to use Silverlight to invoke the WebService written by C #, and then call the bottom. How to carry on the daily development, below is I write with WinForm an experimental platform:
A few years ago, I also used a multi-language development, that is the C + +/TCL hybrid development-The underlying language + glue language development model. A lot of projects are using this development model. The game industry uses this kind of development pattern more. Matlab is also such a pattern.
There are two benefits to this development pattern:
(1) Can synthesize the performance of the underlying language and the strong productivity of glue language, lose a small amount of performance, in exchange for strong productivity and better product quality.
(2) The glue language can conceal the complex detail question, provides the more friendly use way, thus expands the product use surface.
The multiple language development mentioned in the fifth chapter of a book, most of which are examples of this kind, I personally think it is appropriate (except for the example of the test, because I do not understand the old Zhao said AAA, he jumped over to see). In many cases, for the sake of comprehensive consideration, people do not expand the class library, but choose other languages directly.
Another natural multi-language development is the web development, the foreground html/js, the backstage language, the multi-language development is so common that we don't develop it as a multi-language. From this multi-language mixed development of the scene can be seen, different languages in addition to grammar, there are many more important constraints. For example, the installation base. One limitation of developing shared Software in C # is that the current installation infrastructure is not enough. Silverlight is not a sufficient installation base. The HTML/JS installation base is very large. For example, the size of the operating environment--lua the required file size of the operating environment is much smaller than the python--for me this will not Delphi, hate Hungarian nomenclature, hate Windows API, hate MFC people, want to develop under Windows only one or two trillion of software, Lua is just as available--d is immature, Python is too big.
One more multi-language development scenario is the integration of the old system, which is not much to say.
Multi-language development is generally the result of the optimal selection of people in the case of engineering constraints. This kind of constraint, has the grammar constraint, has the platform and the class library The constraint, has the operation environment size constraint, has the performance constraint, has the cost restraint, the person's skill constraint.
Everyone, every company, every project has its own constraints. Or as an example of myself (otaku no other example-this is my constraint), I choose a multi-language for two purposes:
(1) For the sake of comprehensive cost consideration. For example, the previous example of my multi-language development;
(2) for the sake of reading code. There are a lot of knowledge in the world, some in C, some in Python, some in Java, many languages, easy to master the knowledge (many times, this knowledge does not have a very good document, only read the source code to the most accurate understanding of it).
And the enterprise chooses the goal of the multi-language, in addition to the technical restriction, I am afraid the main consideration is the cost.
BTW. The constraint condition is a very important concept, and any inference is bound. The binding conditions in the fifth chapter of a book I think there are two:
(1) language is a generalized language (definition B of the first paragraph of my article)
(2) The main reader is the public programmer
Under these two constraints, I do not think that the fifth chapter of the book is poor (except for the test examples, I can not evaluate), and will not give the general programmer a serious misunderstanding. As to how good it is to write, anyway, I can not learn anything from the.
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
About the constraints, and then talk about the digression. Many people think that Mao is the Public Enemy, Ren Zhiqiang is an enemy of the people, in fact, if you read the main article of Mao, read the majority of Ren Zhiqiang's blog, understand their views of the "background", that is their point of view "constraints", you would not think so. The purpose of writing this paragraph is not to want us to be the people who eat Chonghuan meat.
There is a very famous management article "on Hope B but reward a folly" (in the Book of management and Organizational behavior Classics). This article points to a common phenomenon: in many cases, we want to achieve the goal B, in order to achieve this goal, we have developed the rules of the game, and the final result of this game rule (intentional or unintentional) is to reward the violation of B's behavior A.
This phenomenon is sometimes complex. Here is an example of an online search:
Some in the United States would like to open a few baby seats on the plane for babies to reduce the death rate of these babies after the plane crash. But the study found that when a baby seat was opened, a rise in fares would cause many airline passengers to switch to trains or other means of transport, and the death rate for trains and other vehicles was higher than for passengers, with the result that "every time you save a baby that died of a plane crash, 3.5 passengers will be killed as a result of transfer to other means of transport. ”