这绝对是主观的,但我想尽量避免它变成争论。我认为如果人们恰当地对待它,这将是一个有趣的问题。

这个问题的想法来自于我对“你最讨厌的语言的哪五件事?”问题的回答。我认为c#中的类在默认情况下应该是密封的——我不会把我的理由放在这个问题上,但我可能会写一个更完整的解释来回答这个问题。我对评论中的讨论热度感到惊讶(目前有25条评论)。

那么,你有什么有争议的观点?我宁愿避免那些基于相对较少的基础而导致相当宗教的事情(例如,大括号放置),但例如可能包括“单元测试实际上并没有多大帮助”或“公共字段确实是可以的”之类的事情。重要的是(至少对我来说)你的观点背后是有理由的。

请提出你的观点和理由——我鼓励人们投票给那些有充分论证和有趣的观点,不管你是否恰好同意这些观点。


当前回答

源文件太20世纪了。

在函数/方法的主体中,将过程逻辑表示为线性文本是有意义的。即使逻辑不是严格的线性,我们也有良好的编程结构(循环、if语句等),允许我们使用线性文本清晰地表示非线性操作。

But there is no reason that I should be required to divide my classes among distinct files or sort my functions/methods/fields/properties/etc in a particular order within those files. Why can't we just throw all those things within a big database file and let the IDE take care of sorting everything dynamically? If I want to sort my members by name then I'll click the member header on the members table. If I want to sort them by accessibility then I'll click the accessibility header. If I want to view my classes as an inheritence tree, then I'll click the button to do that.

Perhaps classes and members could be viewed spatially, as if they were some sort of entities within a virtual world. If the programmer desired, the IDE could automatically position classes & members that use each other near each other so that they're easy to find. Imaging being able to zoom in and out of this virtual world. Zoom all the way out and you can namespace galaxies with little class planets in them. Zoom in to a namespace and you can see class planets with method continents and islands and inner classes as orbitting moons. Zoom in to a method, and you see... the source code for that method.

基本上,我的观点是,在现代语言中,不管你把你的类放在什么文件中,或者你定义一个类的成员的顺序是什么,那么为什么我们仍然被迫使用这些古老的实践呢?还记得Gmail出来谷歌说的是"搜索,不排序"吗?那么,为什么同样的哲学不能应用于编程语言呢?

其他回答

低驼峰是愚蠢和没有语义的

使用lower camelCase使名称/标识符(从这里开始使用“name”)看起来像两个部分。然而,Upper CamelCase给出了清晰的指示,所有的单词都属于一起。

匈牙利符号是不同的…因为名称的第一部分是类型指示符,所以它与名称的其余部分具有单独的含义。

有些人可能会认为小写的驼峰大小写应该用于函数/过程,特别是在类内部。这在Java和面向对象的PHP中很流行。然而,没有理由这样做来表明它们是类方法,因为通过它们被访问的方式,很明显它们只是类方法。

一些代码示例:

# Java
myobj.objMethod() 
# doesn't the dot and parens indicate that objMethod is a method of myobj?

# PHP
$myobj->objMethod() 
# doesn't the pointer and parens indicate that objMethod is a method of myobj?

Upper CamelCase对于类名和其他静态名很有用。所有非静态内容都应该通过它们的访问方式来识别,而不是通过它们的名称格式(!)

这是我的同质代码示例,其中名称行为由其他事物表示,而不是它们的名称……(另外,我更喜欢用下划线来分隔名字中的单词)。

# Java
my_obj = new MyObj() # Clearly a class, since it's upper CamelCase
my_obj.obj_method() # Clearly a method, since it's executed
my_obj.obj_var # Clearly an attribute, since it's referenced

# PHP
$my_obj = new MyObj()
$my_obj->obj_method()
$my_obj->obj_var
MyObj::MyStaticMethod()

# Python
MyObj = MyClass # copies the reference of the class to a new name
my_obj = MyObj() # Clearly a class, being instantiated
my_obj.obj_method() # Clearly a method, since it's executed
my_obj.obj_var # clearly an attribute, since it's referenced
my_obj.obj_method # Also, an attribute, but holding the instance method.
my_method = myobj.obj_method # Instance method
my_method() # Same as myobj.obj_method()
MyClassMethod = MyObj.obj_method # Attribute holding the class method
MyClassMethod(myobj) # Same as myobj.obj_method()
MyClassMethod(MyObj) # Same as calling MyObj.obj_method() as a static classmethod

这就是我对camelCase完全客观的看法。

Python用一半的开发时间就完成了其他编程语言能做的所有事情……谷歌也是!!如果你不同意,请查看Unladen Swallow。

等等,这是事实。它还能回答这个问题吗?

规模很重要!修饰你的代码,让它看起来更大。

在. net上开发不是编程。它只是把其他人的代码拼接在一起。

我的编码背景要求你了解硬件,这在我的行业中仍然是一个至关重要的要求,我认为高级语言只是简单地组装别人的工作。这并没有什么本质上的错误,但这是“编程”吗?

微软在为“开发人员”提供符号指令语法方面做了很多艰苦的工作。我现在似乎认识了越来越多的开发人员,他们在执行工作时似乎受到类的存在或不存在的限制。

我的观点来自于这样一个概念:作为一名程序员,你应该能够在你的平台允许的最低水平上编程。因此,如果您正在编写。net程序,那么您需要能够埋头苦干并找出解决方案,而不是依赖于其他人为您创建一个类。在我看来,这是一种懒惰,不符合“发展”的标准。

敏捷糟透了。