473,466 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Class objects work like built-in types, but is it worth it?

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!
Oct 23 '08
55 3902
tonytech08 wrote:
> Too bad that's impossible.

For C++ it is, but not for some other language.
What language? Haskell? Haha.
Oct 29 '08 #51
On Oct 29, 4:00*pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2008-10-28 23:21, tonytech08 wrote:
I think I've noted before or above that if you start with the thought
that "a built-in array is a container", a perverted definition of
"container" will result. A built-in array is a type rather than a
container (by "my" definition of container anyway).
Actually if we say that an array is a container we say that it fulfils
the requirements of a container, not the the requirements of a container
is to be like an array. Or in OO terms: an array implements the
interface container, but there might be many other implementations of
the same interface.
That's not topical though, and is paradigmical and a very
high-level/abstract "definition" (and even moreso, a definition of
"container interface" rather than "container").
It's a
definition of a container in terms of an interface, i.e. the interface
specifies what a container is and everything that implements the
interface is a container.
Nah, that's just a behavioral specification. A container interface is
not a container just like a remote control is not a television. The
remote just allows interaction with it.

In my work we design nodes in networks (some might call them servers but
I don't think that's a good description) which communicate with each
other and other nodes in networks. The requirements on these nodes are
specified by a standardisation organisation and the way they are
specified are in they way they interact with other nodes in the
networks. In other words the specification of a node is a description of
its interfaces. What I want to say with this is that a specification of
behaviour can be a sufficient definition of a thing. So an interface
description of a container can be a definition of a container.
But would be an incorrect definition given the context of this thread.
Context matters.
>
Containers were brought into the discussion when someone said that
built-in-type-behavior of class objects is required so that
containers can be implemented, which of course is wrong in the
general sense.
Of course, but he only said that it is necessary to implement practical
and useful containers.
Which also is not true.

Says you, but who should I believe?
I'm not here to convince you. I do things my own way and I have
containers that I use that are practical and useful. And obviously I
think they are more practical and useful than their STL equivalents.
A regular who's skills are
programming in general and C++ in particular I've witnessed, or you who
has so far only questioned what is more or less the collective opinion
among C++ programmers?
I just wanted to know what people though on the topic. I was hoping to
get some response from people who actually implement the language
rather than just users of it. And from people who are also good
inventors and have found other ways to skin the proverbial cat. (As in
"a better C++"). Surely if one just says "C++ is just fine" that
doesn't add anything toward discovery of anything new.

Oct 29 '08 #52
tonytech08 <to********@gmail.comkirjutas:
On Oct 29, 3:07*am, Paavo Helde <nob...@ebi.eewrote:
>tonytech08 <tonytec...@gmail.comkirjutas:
When would you _ever_ want to use containers with value semantics
other than
with pointers to objects?

Basically whenever when the objects are not polymorphic. Using
pointers
>instead of objects themselves adds a level of indirection with its own
complexity and problems, this should be avoided when not needed.

We'll have to agree to disagree on that.
>>

Well the container topic got backed into here. The issue of this
thread are
class objects. Using a container (STL) with value sematics for a
object of
class type imposes unnecessary requirements on the class.

Nah, you still have it backwards; if the class supports value
semantics
>one can have value-based containers of the objects (with simplified
semantics), *in addition* to pointer-based containers, which are still
there.

We'll have to agree to disagree on that also.
>>

A point is that exceptions and constructors are pretty much a
package
deal because the alternatives are ugly.

It appears you are claiming that if there are two good features
fitting
>nicely with each other, they should be both banned, for unfair
competition ;-)

Nothing like that.

One things I'd miss if there wasn't class objects that behave like
built-in types are those objects you can code up to do something like
release a lock no matter how the enclosing scope gets exited. What are
those things called? I'd probably be satisfied with only one of those
things though that I could wrap around other objects to get the same
effect.
It seems that what you want is some kind of scripting language. At least
the scripting language developed by our company fulfills almost all
criteria. It has no means for defining new data types, so all types are
built-in. The built-in types include things like Image, Table and
Container. There are no script-defined constructors or destructors. There
is no pointer type. In the script everything looks value-based, but under
the hood almost everything is accessed via pointers. There are exceptions
though, and try/catch. And recently I added exactly what appears to be
your last wish: a MakeDestructor operation which just prepares a function
to be launched when exiting the current scope.

Curiously enough, the script language is itself implemented by quite a
large amount of C++ code, making heavy use of constructors, destructors,
inheritance, exceptions, templates and whatever. I cannot imagine of
doing it in some other language, the full C++ is just a *bare minimum*
for implementing this kind of project.

Paavo

Oct 30 '08 #53
tonytech08 wrote:
[...]
But after pondering the responses here, maybe built-in types are the
"problem" (!). "Everything is an object" (but not a cosmic one), may
be the way to go. I know enough "low level" programming to hinder my
own progress probably. Maybe my initial question was wrong. Maybe I
should have asked: "Why do we still need built-in types?". Which of
course brings in the "hardware" folks. Software that programs the
hardware has been the paradigm. Time for software to influence
hardware?
I haven't done any close-to-hardware programming. Yet I've come
across software that stressed very good desktop computers to their
limits. If "everything is an object" costs, I don't want to have
it. (And if it doesn't, why was there a need to invent C++?)

Schobi
Oct 30 '08 #54
LR
tonytech08 wrote:
On Oct 29, 10:31 am, Juha Nieminen <nos...@thanks.invalidwrote:
>tonytech08 wrote:
>>On Oct 28, 6:00 pm, Juha Nieminen <nos...@thanks.invalidwrote:
tonytech08 wrote:
Ha! C++ is complexity incarnate! Pushing stuff into the compiler is
not
reducing complexity, it's just moving it elsewhere.
It's better to have the complexity in the compiler than in the code
written by the programmer.
It's better to not have the complexity at all.
Too bad that's impossible.

For C++ it is, but not for some other language.
>Programming is a complex thing.

With C++ it is. It doesn't have to be nearly so though.
I'm pretty sure that I do not understand this. I think I may not
understand because I may not understand what you mean by complexity.
Could you please explain what you mean by complexity?

Also:

How might it be possible to not have any complexity? Is this limited to
either the programming language itself, or the problem domain?

Why, according to you, is programming more complex with C++?

Is complexity bad? Why? And under what circumstances? Always?

Which computer language would be simpler in your estimation?

1) A single instruction: Flip the bit at <address1and if the result is
zero branch to <address2(Note this doesn't require an opcode.)

2) Two instructions:
a) Flip the bit at <address>
b) If the bit at <address1is zero goto <address2>

If you had to program in one of the above languages, would you want to
add a macro language of some sort? Would this add or remove complexity
from the programs that you'd write?
Would you prefer to use a slide rule or an electronic calculator? Which
one is more complex? To implement? To use?

Is:
a += 3;
more complex or less than:
a = a + 3;
TIA
LR

Oct 30 '08 #55
On Oct 30, 4:17*pm, LR <lr...@superlink.netwrote:
tonytech08 wrote:
On Oct 29, 10:31 am, Juha Nieminen <nos...@thanks.invalidwrote:
tonytech08 wrote:
On Oct 28, 6:00 pm, Juha Nieminen <nos...@thanks.invalidwrote:
tonytech08 wrote:
Ha! C++ is complexity incarnate! Pushing stuff into the compiler is
not
reducing complexity, it's just moving it elsewhere.
* It's better to have the complexity in the compiler than in the code
written by the programmer.
It's better to not have the complexity at all.
* Too bad that's impossible.
For C++ it is, but not for some other language.
Programming is a complex thing.
With C++ it is. It doesn't have to be nearly so though.

I'm pretty sure that I do not understand this. *I think I may not
understand because I may not understand what you mean by complexity.
Could you please explain what you mean by complexity?

Also:

How might it be possible to not have any complexity? Is this limited to
either the programming language itself, or the problem domain?

Why, according to you, is programming more complex with C++?

Is complexity bad? Why? And under what circumstances? Always?

Which computer language would be simpler in your estimation?

1) A single instruction: Flip the bit at <address1and if the result is
zero branch to <address2(Note this doesn't require an opcode.)

2) Two instructions:
a) Flip the bit at <address>
b) If the bit at <address1is zero goto <address2>

If you had to program in one of the above languages, would you want to
add a macro language of some sort? *Would this add or remove complexity
from the programs that you'd write?

Would you prefer to use a slide rule or an electronic calculator? Which
one is more complex? To implement? To use?

Is:
* * * a += 3;
more complex or less than:
* * * a = a + 3;
As this thread is already more chaff than wheat, I suggest you start a
new thread on "the complexity of C++" if you want to.
Oct 30 '08 #56

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Franz Steinhaeusler | last post by:
Hello, (in wxPython) I want to redirect the SetStatusText to an own method (change the text somewhat) and then call the SetStatusText of wx.Frame. But I have a little problem of...
1
by: JohanS | last post by:
Hi count(v.begin(), v.end(), 5) is easy for a vector of int's. But how do i make it work with a class object? I have tried a few ways but can't get it to work since i don't really understand...
6
by: Brian Ross | last post by:
Hi, I am trying to do something similar to the following: int Func1(int x, int y); double Func2(double x, double y); template <typename FuncT> // <- What would go here class CObjectT {
9
by: sashang | last post by:
Hi I'd like to use metaclasses to dynamically generate a class based on a parameter to the objects init function. For example: class MetaThing(type): def __init__(cls, name, bases, dict,...
2
by: brzozo2 | last post by:
Hello, anyone knows if there is a way to use pointer notation instead of array when it comes to copying one object to another via a pointer of array to objects? Here is a very simple code to show...
3
by: Ole Nielsby | last post by:
I have objects that sometimes overwrite themselves by something else, using placement new. I will spare you for the details, but the objects serve as stack frames and are placed contiguosly, and...
6
by: MattWilson.6185 | last post by:
Hi, I'm trying to find out if something is possible, I have a few diffrent lists that I add objects to and I would like to be able to have a wrapper class that won't affect the internal object, for...
3
by: =?gb2312?B?wfXquw==?= | last post by:
Hi, folks, I'm running into a question as below: template<typename T> class A { private: T _a; public: A(T t): _a(t) { }
5
by: Jonathan Boivin | last post by:
Hi, I've got some problems with loading bills using a bill usercontrol I built. If I load all current bills in my test environment (156) everything is fine once, but repeating the operation...
10
by: hofer | last post by:
Hi, I have multiple objects all belonging to the same class (which I didn't implement and whose code I don't want to modify) Now I'd like to change one method for one object only (after it has...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.