« 魔兽世界之过? | 返回首页 | 打成了一次大满贯 »

看到一段关于 const 的讨论

摘录的一段:


My experience from other languages (C, C++, Objective C, Java, Smalltalk, etc) suggests that trying to add some notion of const to the language is detrimental. It's rarely of use to the compiler, adds little or no safety barrier for programmers, is confusing, and isn't always helpful documentation. I've seen grown men weep over C's const, and highly paid C++ professionals argue for hours over the meaning of const in C++.

The right place to annotate things with notions of constantness is the type hierarchy. See, for example, java.awt.Raster / java.awt.WritableRaster (from Java's 2D api), NSDictionary / NSMutableDictionary (from Objective-C's foundation classes).

drj


以为然也

TrackBack

链入链接:看到一段关于 const 的讨论:

» GOOD SITE from vvoody
GOOD SITE [Read More]

Comments

shit,没看懂, 加强英语ing

const bar foo() const
也只是让语义清晰嘛...
很多时候,C++不是把简单问题复杂化的语言,而是能够把复杂问题简单化的工具哦

另外在我看来, C++本身就是把简单问题复杂化的一个语系.
类似
const bar foo() const;
的语句的确很容易让人confusing...

我觉得这话说的有失偏颇,const是个标识符,编译器是否去处理是编译器的事情,如果没有进行处理是编译器的问题。跟const本省没有关系。

至少在我的开发中(delphi, java)
const/final是经常使用的,可以使得程序自身的语义更加清晰。

me too!

shit,没看懂, 加强英语ing

"use const as much as you can..."
没什么感觉,至少可以帮助在运行之前能够抓住多一点的error.

最大的噩梦是编译通过,死活找不到运行出错的原因。而且面对的是一个巨大的工程时。

Post a comment

非这个主题相关的留言请到:留言本