F # Adventure Tour (VI): Organization of F # code

Source: Internet
Author: User
Tags static class

Objective

Yes, we've learned how to program in F # using a variety of paradigms (functional, imperative, object-oriented). However, it is currently limited to writing in a single module, knowing that, regardless of the language or paradigm of programming, if the project is large, it is not appropriate to put all the code in a single module.

In the regular. NET projects, such as c#+asp. NET), we often choose to use the concept of solution as the solution to the whole (standalone) problem domain, solution The following is Project, File. These concepts are often physically represented as assemblies (class libraries or executable programs), class files, and so on, and if the number of projects and files is large, consider how to organize them. Here are some of the three levels that are discussed separately.

Solution level

The main consideration here is the relationship between project, at this time basically we can ignore the differences in language, it can be said that at this level, the impact of language is not small. So we're moving in with the code organization principles that are used in C # development. For example, Martin Fowler in the enterprise Application architecture model, such as Robert Martin's reference to package design principles in agile software development, also included. NET community on the PetShop architecture of the discussion, and so on, can be used for reference. There has been a great deal of discussion on this subject, and there is no longer much to repeat.

Here's a specific question: how to add a reference to another assembly. Before the F # CTP 1.9.6.0, adding references to assemblies requires #i and #r directives, #I用来指定要引用的程序集的目录, #r则用来指定要引用程序集的路径 (including file names, either relative or absolute). These two directives can be placed either in the code file or in the compilation options. There's a little trick in the registry. The NETFramework node contains some information about each. NET version, with several directory information in the AssemblyFoldersEx, which can be used directly if the assembly's directory appears in AssemblyFoldersEx R and filename to add a reference.

In the CTP version, you can look like a regular c#/vb. NET project, you add references to other assemblies for your project, including references to other projects in the same solution:

#r can only be used for FSX script files or in compilation options.

Project hierarchy

Now that you have a good understanding of the design principles outlined above and used these principles to complete the design, the next step is to use F # to implement these designs. Now that we are at the project level, we need to consider the relationships between the various code entities in project, which can be physical source files, or logical modules, types, configurations, and so on. The most basic organizational structure in F # is namespaces and modules, and the concept of namespaces is the same as in C #. With the help of reflector, you can see that the module is static after compiling, and when we add a member to a module, we need to know that it is adding members to a static class. For information on namespaces and modules, it is highly recommended to lvxuwen how to organize programs (up and down).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.