如何在Visual Studio中组织大型项目(> 300类)的F#源? [英] How to organize F# source of large project (>300 classes) in Visual Studio?

查看:154
本文介绍了如何在Visual Studio中组织大型项目(> 300类)的F#源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,您可以将文件放在与它们的命名空间相对应的文件夹中,然后在解决方案资源管理器中查看它们。

在F#中,看来我必须将所有内容放在明确的有序列表中进行编译。当我达到大约300个类的规模时,它变得有些混乱和混乱,我开始羡慕C#,并认为这可能是类型推断的代价。

In F# it seems I have to put everything in plain specifically ordered list for compilation. When I get to scale of ~300 of classes it gets a bit confusing and disorganized and I start to envy C# and think that probably it is the price for type inference.

是否有比拆分成多个程序集更好的选择?

由F#判断编译器提供了它们采用的路由,但是我有一个很大的互连组件系统(Controller-ViewModel-View,> 300个类),由于即使在接口级别上也存在循环依赖关系,所以我想成为一个程序集。

Judging by F# compiler source its the route they have taken but I have pretty large system of interconnected components (Controller - ViewModel - View, > 300 classes) I want to be in one assembly because of circular dependencies even at level of interfaces.

我应该忘记一个文件-一个类并创建一些大文件吗?(例如,在F#编译器中,您有多个100kb的源文件可以300kb的范围,大约1Mb会自动生成!)

Should I forget about one file - one class and create some huge files? (e.g. in F# compiler you have several source files in 100kb to 300kb range and some auto generated around 1Mb!)

您对大型F#项目有何经验?

推荐答案

您提到的是循环依赖,很明显,F#绝不会让您在文件之间散布循环依赖。如果类型 Foo 是指类型 Bar ,而类型是 Bar 是指键入 Foo ,然后 Foo Bar 定义在F#中相同 type ...和... 组的同一文件中。

You mention "circular dependencies", to be clear, F# will never let you spread circular dependencies across files. If type Foo refers to type Bar and type Bar refers to type Foo, then Foo and Bar must both be defined in the same file in the same type ... and ... group in F#.

问题这是组织和导航之一,主要涉及工具。 VS解决方案资源管理器显示文件列表。文件夹可让您折叠文件组,从而更轻松地组织思想或浏览许多文件的远距离。但是,对于导航,还有其他各种工具(转到定义,在当前项目中搜索文本,...)可让您导航到例如特定的类定义。 (希望这些工具在将来的版本中将特别针对F#和VS继续改进。)

The issue here is one of organization and navigation, that is mostly about the tooling. The VS solution explorer displays a list of files; folders enable you to 'collapse' groups of files which can make it easier to organize your thoughts or navigate across 'great distances' of many files. However for navigation there are various other tools (Go To Definition, search for text in the current project, ...) to let you navigate to e.g. a particular class definition. (Hopefully these tools will continue to improve for F# in particular, as well as VS in general, in future releases.)

无论如何,我坚信互连组件(控制器-ViewModel-视图,> 300个类)的大型系统是一种代码异味。如果您无法解开这些内容以使其具有建筑层次结构,从而使某些部分不依赖于其他部分(因此可以在F#中的先前文件中将其定义为第一个),那么您将面临比如何组织您的F#代码。我的观点也许是表达最好的此处

In any case, I firmly believe that a "pretty large system of interconnected components (Controller - ViewModel - View, > 300 classes)" is a code smell. If you can't untangle these to have an archetectural layering such that there are portions that do not depend on other portions (and thus could be defined 'first' in a prior file in F#), then you have bigger problems than just "how to organize your F# code". My opinionated view is perhaps best-expressed here.

编辑(2018):同时,该工具得到了改善,其中包括定义定义,查找所有引用,标识符的全局重命名,文件夹支持,文件重组等。在过去的几年中添加了等。对于需要在类之间相互引用的解决方案,引入了 namespace rec module rec 来限制对<$的需求。 c $ c> type ...和... 。

EDIT (2018): meanwhile, the tools have improved, among many other things, go-to-definition, find-all-references, global renaming of identifiers, folder support, file reorganization etc have been added in the past few years. For solutions that require mutual references between classes, namespace rec and module rec have been introduced to limit the need for type ... and ....

这篇关于如何在Visual Studio中组织大型项目(&gt; 300类)的F#源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆