每班一个模块,不好主意? [英] One module per class, bad idea?

查看:63
本文介绍了每班一个模块,不好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自Java和C#的背景,通常的做法是在文件/项目结构中为每个文件分配一个类
。据我了解,

在Python模块/文件中有很多类是比较常见的做法。

它背后的动机是什么,它会不好想要在你的项目中有一个指南

,它可以促进每个文件结构的一个类(假设大多数程序员的b $ b b背景与我的类似)?

I come from a background of Java and C# where it is common practise to have
one class per file in the file/project structure. As I have understood it,
it is more common practice to have many classes in a Python module/file.
What is the motivation behind it, would it be a bad idea to have a guideline
in your project that promotes a one class per file structure (assuming most
of the programmers a background similar to mine)?

推荐答案

在你的项目中推广一个类的指南
would it be a bad idea to have a guideline

是不是一个坏主意每个文件结构(假设大多数程序员的b $ b b背景类似于我的)?
in your project that promotes a one class per file structure (assuming most
of the programmers a background similar to mine)?



是的,这不是一个坏主意。 =)

Yes, it would be a bad idea. =)


Matias Jansson写道:
Matias Jansson wrote:

我来自Java和C#的背景通常的做法是在文件/项目结构中为每个文件分配一个类
。据我了解,

在Python模块/文件中有很多类是更常见的做法。
I come from a background of Java and C# where it is common practise to have
one class per file in the file/project structure. As I have understood it,
it is more common practice to have many classes in a Python module/file.



更重要的是,在Python中,你不会为每一个
的东西使用类;如果你需要工厂,单身,多种方式创建

对象,多态助手等,你可以使用普通函数,而不是类

或静态方法。


一旦你完成了它'的所有类,使用模块以对使用你的代码有意义的方式组织

的东西组件。

使导入语句看起来不错。


< / F>

even more important is that in Python, you don''t use classes for every-
thing; if you need factories, singletons, multiple ways to create
objects, polymorphic helpers, etc, you use plain functions, not classes
or static methods.

once you''ve gotten over the "it''s all classes", use modules to organize
things in a way that makes sense to the code that uses your components.
make the import statements look good.

</F>




Matias Jansson写道:

Matias Jansson wrote:

我来自Java和C#的背景,其中通常的做法是

文件/项目结构中每个文件一个类。据我了解,

在Python模块/文件中有很多类是比较常见的做法。

它背后的动机是什么,它会不好想要在你的项目中有一个指南

,它可以促进每个文件结构的一个类(假设大多数程序员的b $ b b背景与我的相似)?
I come from a background of Java and C# where it is common practise to have
one class per file in the file/project structure. As I have understood it,
it is more common practice to have many classes in a Python module/file.
What is the motivation behind it, would it be a bad idea to have a guideline
in your project that promotes a one class per file structure (assuming most
of the programmers a background similar to mine)?



这不是一个糟糕的一般准则。


我们尝试每个文件使用一个类,除非它们真的琐碎或

与另一个紧密相连。


它允许你非常具体地命名文件并隔离

功能。


我们也有''辅助函数''的文件,它通常有几个

函数。


Fuzzyman
http://www.voidspace.org.uk/ index2.shtml

It''s not a bad general guideline.

We try and use one class per file unless they are really trivial or
tightly coupled to another.

It allows you to be very specific in the naming of files and isolate
functionality.

We also have files with ''helper functions'', which often have several
functions.

Fuzzyman
http://www.voidspace.org.uk/index2.shtml


这篇关于每班一个模块,不好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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