每个文件中是否存在建议的代码行数? [英] Is there a recommended number of lines of code per file?

查看:256
本文介绍了每个文件中是否存在建议的代码行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类文件,其中包含某个Web应用程序所需的所有类.目前,我在第7269行,它包含许多类.我并不特别担心,但是我已经开始注意到在处理此文件时,Visual Studio的响应速度较慢.我认为这可能是由于文件的大小以及每次按Enter键后Visual Studio的重新编译所引起的.

I have a class file that contains all the classes that are needed for a certain web application. Currently I'm at line 7269 and it contains numerous classes. I'm not particularly worried but I've started to notice that when working on this file Visual Studio responds slower. I'm thinking that this may be caused by the size of the file and Visual Studio's re-compile after every enter key press.

是否有人对每个文件的类的行数有任何建议,或者关于如何/为什么应该将类移动到单独的文件中的准则?

Has anyone got any recommendations for limits to lines per file of classes per file or perhaps guidelines as to how/why I should move classes into separate files?

我发现这与Java有关,但是我特别关注VB和Visual Studio 2005

I found this regarding Java but I'm specifically concerned with VB and Visual Studio 2005

允许的最大代码行在Java类中?

谢谢

编辑 文件中大约有50多个类,有些很小,有些很大!

EDIT There are about 50+ classes in the file, some tiny, some large!

推荐答案

Egad.

几乎每个人都强烈建议每个类的文件中都包含类.

It's highly recommended by just about everyone that classes are contained in a file per class.

线条不是很直接相关,但是这可能是您创建了一个过于复杂的神类,需要打破逻辑的征兆.正确执行单元测试驱动的开发会强制执行此操作.

Lines isn't very relevant directly, but it can be a symptom that you're creating an overly complex god class and need to break the logic up. Unit test driven development forces this when done correctly.

修改(注意到为什么?"):

从您要求的事实来看,它应该很明显:)

from the fact you're asking it should be obvious :)

一些(由于许多原因):

A few (of many reasons):

  • 很难看到大文件中的实际代码布局

  • it's very hard to visualise the actual code layout in large files

大多数IDE是默认设置,可以一次显示多个文件,但不能显示同一文件的多个视图

most IDEs are default set-up to show multiple files at a time, but not multiple views of the same file

对单个文件的源代码控制可能是一个问题:能否请您签入{godfile},以便我可以从事该项目?"

source control over a single file can be a problem: "can you please check in {godfile} so I can work on the project?"

将代码分段到命名空间/程序包/分支中是一个问题

fragmenting code into namespaces/packages/branches is a problem

这篇关于每个文件中是否存在建议的代码行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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