f*y
2 楼
Read this shocking news. Here's a summary: it says: if your house is built
with chinese drywall, it cannot be insured (sooner or later), and if the
house is not insured, the mortgage company won't allow it and will have to
forclosure your house... sounds really scary...
http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
with chinese drywall, it cannot be insured (sooner or later), and if the
house is not insured, the mortgage company won't allow it and will have to
forclosure your house... sounds really scary...
http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
t*c
3 楼
from douban:
d*n
4 楼
献给gopher们,俺还没踩到,不过惊出一身冷汗。希望对其他gopher有用
http://studygolang.com/articles/5188
坑(s)
每种编程语言都有自己的专属坑(s),Go虽出身名门,但毕竟年轻,坑也不少,在error
处理这块也可以列出几个。
1、 Go FAQ:Why is my nil error value not equal to nil?
type MyError string
func (e *MyError) Error() string {
return string(*e)
}
var ErrBad = MyError("ErrBad")
func bad() bool {
return false
}
func returnsError() error {
var p *MyError = nil
if bad() {
p = &ErrBad
}
return p // Will always return a non-nil error.
}
func main() {
err := returnsError()
if err != nil {
fmt.Println("return non-nil error")
return
}
fmt.Println("return nil")
}
上面的输出结果是”return non-nil error”,也就是说returnsError返回后,err !=
nil。err是一个interface类型变量,其underlying有两部分组成:类型和值。只有这
两部分都为nil时,err才为nil。但returnsError返回时将一个值为nil,但类型为*
MyError的变量赋值为err,这样err就不为nil。解决方法:
func returnsError() error {
var p *MyError = nil
if bad() {
p = &ErrBad
}
return nil
}
2、switch err.(type)的匹配次序
试想一下下面代码的输出结果:
type MyError string
func (e MyError) Error() string {
return string(e)
}
func Foo() error {
return MyError("foo error")
}
func main() {
err := Foo()
switch e := err.(type) {
default:
fmt.Println("default")
case error:
fmt.Println("found an error:", e)
case MyError:
fmt.Println("found MyError:", e)
}
return
}
你可能会以为会输出:”found MyError: foo error”,但实际输出却是:”found an
error: foo error”,也就是说e先匹配到了error!如果我们调换一下次序呢:
... ...
func main() {
err := Foo()
switch e := err.(type) {
default:
fmt.Println("default")
case MyError:
fmt.Println("found MyError:", e)
case error:
fmt.Println("found an error:", e)
}
return
}
这回输出结果变成了:“found MyError: foo error”。
也许你会认为这不全是错误处理的坑,和switch case的匹配顺序有关,但不可否认的
是有些人会这么去写代码,一旦这么写,坑就踩到了。因此对于通过switch case来判
定error type的情况,将error这个“通用”类型放在后面或去掉。
http://studygolang.com/articles/5188
坑(s)
每种编程语言都有自己的专属坑(s),Go虽出身名门,但毕竟年轻,坑也不少,在error
处理这块也可以列出几个。
1、 Go FAQ:Why is my nil error value not equal to nil?
type MyError string
func (e *MyError) Error() string {
return string(*e)
}
var ErrBad = MyError("ErrBad")
func bad() bool {
return false
}
func returnsError() error {
var p *MyError = nil
if bad() {
p = &ErrBad
}
return p // Will always return a non-nil error.
}
func main() {
err := returnsError()
if err != nil {
fmt.Println("return non-nil error")
return
}
fmt.Println("return nil")
}
上面的输出结果是”return non-nil error”,也就是说returnsError返回后,err !=
nil。err是一个interface类型变量,其underlying有两部分组成:类型和值。只有这
两部分都为nil时,err才为nil。但returnsError返回时将一个值为nil,但类型为*
MyError的变量赋值为err,这样err就不为nil。解决方法:
func returnsError() error {
var p *MyError = nil
if bad() {
p = &ErrBad
}
return nil
}
2、switch err.(type)的匹配次序
试想一下下面代码的输出结果:
type MyError string
func (e MyError) Error() string {
return string(e)
}
func Foo() error {
return MyError("foo error")
}
func main() {
err := Foo()
switch e := err.(type) {
default:
fmt.Println("default")
case error:
fmt.Println("found an error:", e)
case MyError:
fmt.Println("found MyError:", e)
}
return
}
你可能会以为会输出:”found MyError: foo error”,但实际输出却是:”found an
error: foo error”,也就是说e先匹配到了error!如果我们调换一下次序呢:
... ...
func main() {
err := Foo()
switch e := err.(type) {
default:
fmt.Println("default")
case MyError:
fmt.Println("found MyError:", e)
case error:
fmt.Println("found an error:", e)
}
return
}
这回输出结果变成了:“found MyError: foo error”。
也许你会认为这不全是错误处理的坑,和switch case的匹配顺序有关,但不可否认的
是有些人会这么去写代码,一旦这么写,坑就踩到了。因此对于通过switch case来判
定error type的情况,将error这个“通用”类型放在后面或去掉。
q*g
5 楼
有,不过影响不大。你还是要想好万一被问到的,你总得给个理由吧。把这个理由变成
个有利条件是最好,千万别减分就行。
个有利条件是最好,千万别减分就行。
w*g
6 楼
炒冷饭了. 他们怎么不sue builder. 如果数十万房子有这个问题. 早就闹大了.
【在 f*****y 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
【在 f*****y 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
f*t
7 楼
我踩到了第一个坑的变种,实在恶心。
type A struct {}
func foo() *A {
return nil
}
AssertNil(interface{} o) {
if o != nil {
panic()
}
}
AssertNotNil(foo()) 会panic,因为o是(*A)(nil),跟无类型的nil不等
type A struct {}
func foo() *A {
return nil
}
AssertNil(interface{} o) {
if o != nil {
panic()
}
}
AssertNotNil(foo()) 会panic,因为o是(*A)(nil),跟无类型的nil不等
p*N
8 楼
那些鼓吹新房子的人又可以HIGH了.
【在 f*****y 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
【在 f*****y 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
a*x
10 楼
这都哪辈子的事了
【在 f*****y 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
【在 f*****y 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
t*t
11 楼
感觉go很坑爹啊
w*j
12 楼
没人逼美国人买啊。世界上这么多国家,美国人到中国去买,无非是价格便宜啊。美国
人自己选择买中国的商品,就要付责,检讨自己的眼光不对。
btw,个人认为这个是变相地贸易保护主义。
【在 f*****y 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
人自己选择买中国的商品,就要付责,检讨自己的眼光不对。
btw,个人认为这个是变相地贸易保护主义。
【在 f*****y 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: Read this shocking news. Here's a summary: it says: if your house is built
: with chinese drywall, it cannot be insured (sooner or later), and if the
: house is not insured, the mortgage company won't allow it and will have to
: forclosure your house... sounds really scary...
: http://news.yahoo.com/s/ap/20091015/ap_on_re_us/us_chinese_drywall
T*7
13 楼
1 很好理解。本来就是一個interface.两部分呢。go programming lang那本书上写的
也很清楚
先在的小孩,真以为一周看看tutorial就可以写production code了?
不看2本书就写代码就是耍流氓阿。
过去老子学c++没看4,5本书都不敢说会写c++
也很清楚
先在的小孩,真以为一周看看tutorial就可以写production code了?
不看2本书就写代码就是耍流氓阿。
过去老子学c++没看4,5本书都不敢说会写c++
r*t
15 楼
其实就是试图写这样的程序
a := nil
如果 nil 可以 polymorphic 那么接下来就有一些困惑的事情
a = &A{...}
a = &B{...}
Go 通过 typed 'nil' 避免了这个问题 但是悄悄发生的
另外发现 Go 还可以避免 a := nil 的问题 很欣慰
a := nil
如果 nil 可以 polymorphic 那么接下来就有一些困惑的事情
a = &A{...}
a = &B{...}
Go 通过 typed 'nil' 避免了这个问题 但是悄悄发生的
另外发现 Go 还可以避免 a := nil 的问题 很欣慰
相关阅读
有什么提高 RemoteDesktop 速度的 办法吗?我这个读写文本文件的程序为什么第一次总是出错?求推荐一个大家觉得很好的 UML tool:刚下载BOUML,不知道功能,效果如何Will it coz memory leakage?top 4 IT company interview question looking for answerdba和程序员,哪个是青春饭? (转载)template控制程序自动化执行, 该用 perl, python or shell script ?underscore usage in C++ nameRe: Win8最大的输家是SL,其次是IE (转载)对STL的set比较熟悉的进来看看Python API 下载google trend总是断掉怎么办? (转载)std::map 为什么没有排序呢C++里用Blas/Lapack的问题 (转载)a pointer to a const addr师傅们指点一下码工防老的出路吧!!!VB 能不能编译 basic 的代码?请教c++ non-vitura interface手工杀spammer太爽了免费送最高五晚酒店入住 任意消费一笔SPG 信用卡