类对象的工作方式与内置类型相似,但值得吗? [英] Class objects work like built-in types, but is it worth it?

查看:65
本文介绍了类对象的工作方式与内置类型相似,但值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类对象的行为与内置类型一样有价值吗?我看来
整个构造函数都没有返回值,因为

它们被编译器调用事情是为类类型的对象启用类似内置的

行为。这导致了必要性。对于

异常机制,以便构造函数的错误可以处理
。所有这些复杂性是否值得它只是为了从类对象中获得内置的

行为?也许一个更好的架构将是

内置类型和类对象类型从根本上被接受

不同的动物并且放弃了
$所需的大量机器b $ b鞋拔类对象成为他们不是的东西!

How valuable is it that class objects behave like built-in types? I
appears that the whole "constructor doesn''t return a value because
they are called by the compiler" thing is to enable built-in-like
behavior for objects of class type. That leads to the "necessity" for
the exception machinery so that errors from constructors can be
handled. Is all that complexity worth it just to get built-in-like
behavior from class objects? Maybe a better architecture would be for
built-in types and class object types to be accepted as fundamentally
different animals and forego the extensive machinery required to
shoehorn class objects into being something they are not!

推荐答案

10月23日,2:41 * pm,tonytech08< tonytec .. 。@ gmail.comwrote:
On Oct 23, 2:41*pm, tonytech08 <tonytec...@gmail.comwrote:

类对象的行为类似于内置类型有多大价值?我看来
整个构造函数都没有返回值,因为

它们被编译器调用事情是为类类型的对象启用类似内置的

行为。这导致了必要性。对于

异常机制,以便构造函数的错误可以处理
。所有这些复杂性是否值得它只是为了从类对象中获得内置的

行为?也许一个更好的架构将是

内置类型和类对象类型从根本上被接受

不同的动物并且放弃了
$所需的大量机器b $ b鞋拔类对象成为他们不是的东西!
How valuable is it that class objects behave like built-in types? I
appears that the whole "constructor doesn''t return a value because
they are called by the compiler" thing is to enable built-in-like
behavior for objects of class type. That leads to the "necessity" for
the exception machinery so that errors from constructors can be
handled. Is all that complexity worth it just to get built-in-like
behavior from class objects? Maybe a better architecture would be for
built-in types and class object types to be accepted as fundamentally
different animals and forego the extensive machinery required to
shoehorn class objects into being something they are not!



如果我理解你的问题,我想问一下,你想从构造函数中返回什么值



显然,由于构造函数构造了一个对象,你可以接收成功或失败的结果吗?

遵循该逻辑,如果对象发生了什么构造函数

失败了吗?

答案应该是没有任何对象......它不能构建你的b $ b b没有任何对象,其中一个

异常的情况看起来就像你想要的那样。

也就是说,如果没有对象强迫用户对待这个错误

(而不是他忘记检查返回值和段错误

以后的某个时间没有明显的原因)。

If I understand your question correctly I''d like to ask what values
would you like to get returned from a constructor?
Obviously since the constructor constructs an object you can receive
either a success or a failure?
Following that logic what happens to the object if the constructor
fails?
The answer to that should be that there is no object ... it couldn''t
be constructed thus you have no object which a situation where an
exception looks like exactly the thing you''d want have.
That is, if there''s no object force the user to treat that error
(rather than him forgetting to check the return value and segfault
sometime later for no apparent reason).


在2008-10-23 13:41,tonytech08写道:
On 2008-10-23 13:41, tonytech08 wrote:

类对象的行为有多重要喜欢内置类型?我看来
整个构造函数都没有返回值,因为

它们被编译器调用事情是为类类型的对象启用类似内置的

行为。这导致了必要性。对于

异常机制,以便构造函数的错误可以处理
。所有这些复杂性是否值得它只是为了从类对象中获得内置的

行为?也许一个更好的架构将是

内置类型和类对象类型从根本上被接受

不同的动物并且放弃了
$所需的大量机器b $ b鞋拔类对象成为他们不是的东西!
How valuable is it that class objects behave like built-in types? I
appears that the whole "constructor doesn''t return a value because
they are called by the compiler" thing is to enable built-in-like
behavior for objects of class type. That leads to the "necessity" for
the exception machinery so that errors from constructors can be
handled. Is all that complexity worth it just to get built-in-like
behavior from class objects? Maybe a better architecture would be for
built-in types and class object types to be accepted as fundamentally
different animals and forego the extensive machinery required to
shoehorn class objects into being something they are not!



你想要什么" new MyClass()"返回?


-

Erik Wikstr ?? m

And what would you like "new MyClass()" to return?

--
Erik Wikstr??m


10月23日,12日:13 * pm,Eri​​k Wikstr?m< Erik-wikst ... @ telia.comwrote:
On Oct 23, 12:13*pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

2008-10-23 13:41,tonytech08写道:
On 2008-10-23 13:41, tonytech08 wrote:

类对象的行为类似于内置类型有多大价值?我看来
整个构造函数都没有返回值,因为

它们被编译器调用事情是为类类型的对象启用类似内置的

行为。这导致了必要性。对于

异常机制,以便构造函数的错误可以处理
。所有这些复杂性是否值得它只是为了从类对象中获得内置的

行为?也许一个更好的架构将是

内置类型和类对象类型从根本上被接受

不同的动物并且放弃了
$所需的大量机器b $ b鞋拔类对象成为他们不是的东西!
How valuable is it that class objects behave like built-in types? I
appears that the whole "constructor doesn''t return a value because
they are called by the compiler" thing is to enable built-in-like
behavior for objects of class type. That leads to the "necessity" for
the exception machinery so that errors from constructors can be
handled. Is all that complexity worth it just to get built-in-like
behavior from class objects? Maybe a better architecture would be for
built-in types and class object types to be accepted as fundamentally
different animals and forego the extensive machinery required to
shoehorn class objects into being something they are not!



你想要什么" new MyClass()"回来?


And what would you like "new MyClass()" to return?



好​​的,2个回复都错过了我的问题,所以我会尝试

改述并澄清。问题是关于类对象的价值

表现得像内置类型:有价值/有益/可取的是什么?b
?或者更具体地说,是否值得引入所有

辅助机械(例外)来获得该功能?

OK, 2 responses and both are missing my question so I''ll try to
rephrase and clarify. The question is about the value of class objects
behaving like built-in types: How valuable/beneficial/desireable is
that? Or more specifically, was it worth introducing all that
ancillary machinery (exceptions) to get that feature?


这篇关于类对象的工作方式与内置类型相似,但值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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