On 23.05.2013 07:49, James K. Lowden wrote:
>
>> You already did. CORBA does solve the problem nicely. Probably
>> "inverse" from the way you want it because you first have to write
>> the IDL and not the C++ classes, but anyhow, it'll do.
>
> So say you. I don't consider CORBA a "library solution" (setting aside
> whether it's a solution at all, to anything). CORBA is not a C++
> library. It's a foreign system with C++ bindings.
So may it be - but does it matter? You need a solution, you got one.
Why does C++ need to address this problem if there is a solution that works.
>> If I had the same problem, I would probably write my "classes to be
>> serialized" in a restricted C++ dialect, then write a yacc or bison
>> code to parse that, and generate the necessary code automatically.
>
> Yup. Instead of using the language you already have, you'd recreate
> the information discarded by the compiler in a bespoke, nonstandard
> way.
Why "nonstandard"? It's probably another standard. But certainly not the
C++ standard. As I already said, I believe there is no need to put this
burden on the shoulders of the C++ standard as there are solutions that
address this problem, and they work with C++. IOW, why do you care
whether this is part of C++ or not?
> What you could not do is extend I/O streams to deal with user-defined
> types.
Why not? Of course I could. It's the matter of generating the code for it.
>> Or I would pick java right away, which has such things built in.
>
> Yeah, except there is no "pick". Stroustrup says there are billions of
> lines of extant C++, and some 3 million C++ programmers. Every one of
> those systems reads and writes data. Many thousands of those
> programmers have dealt with I/O, some not very well.
Why is that an argument against using java? Sorry, I don't understand.
The 3 million lines of code certainly do not need serialization. While I
cannot give you numbers, I would believe that only a minority of them
would profit from it, or solved it otherwise.
In the same vain, one could argue that C++ needs a standard GUI library,
a library that allows users to create graphical front-ends. It's really
missing, there are 3 million lines of C++ out there... and actually, I
(personally) would profit from it.
> C++ has some unique features, even some *good* unique features.
> Judging from the billions of lines and the lousy I/O support, it's safe
> to say it gets picked for good reason, and that I/O isn't one of them.
Probably not. GUIs are neither a strong argument for C++. But then
again, why solve the problem with C++ then in first place. It is
probably not the right language for that.
>> So why do you write C++ libraries if you need to solve database
>> problems? These are typically I/O bound in my experience, and you
>> don't need the low-level control C++ offers.
>>
>>> I didn't say the programs were I/O bound. I am saying they're I/O
>>> awkward. That matters because any useful computation requires input
>>> and output.
>>
>> That is so general that it applies to every program. Actually, a
>> program without output is pretty much useless, I would say.
>
> Good. So we agree, at least that output matters?
Sure. So we need a GUI library, right? Something to make my output
readable by a user, in a convenient way. And output means output to HTML
these days, so actually, we need an HTML + css creator within standard C++.
*Neither* of these features are part of C++ today. I believe for good
reason. There are already solutions for them, so there is no need to put
them into the standard.
> In case it helps, the problems I face day-to-day are compute-bound.
> Efficiency is very important. So is getting data in and out of the
> system, and sharing it with the rest of the organization.
So again, why not java? Have you made benchmarks?
>>> Pointers are nothing more than offsets, counters from zero into
>>> linear memory. To write them out and read them back in requires
>>> only to encode and decode them. If it couldn't be done,
>>> "marshalling" wouldn't be part of our working vocabulary.
>>
>> Sorry, but how is that supposed to work? If I de-serialize two
>> objects, how can one ensure that they have the same offset they had
>> when they were serialized?
>
> I don't see the problem. If, when those objects were serialized, the
> values of their pointers were stored, too, then on de-serialization you
> would have the exact information you needed to know if they were one and
> the same object.
How, and why? You need a unique identifier that identifies all the
objects you have written, then again on input, you need to scan this
information, need to keep the IDs in a local database, and re-set the
pointers correctly. Ok, probably do-able. But why do I need to put all
this stuff into the C++ core?
> I don't know what you mean by "same offset"; they
> don't need to have the same locations in memory, except relative to
> each other.
They will certainly not end up in the same relative offset. At least not
under a multitasking operating system.
>>>> The problem is just that you now assume networking to be part of
>>>> the language
>>>
>>> No. The problem is you're looking through the wrong end of the
>>> telescope. You seem to think the problem is unimportant and can be
>>> solved with a library. It cannot, and it matters.
>>
>> That depends on your problem domain. The problem actually *is*
>> unimportant for most C++ users, which is exactly why it is not part of
>> the language.
>
> That's not clear at all. The language was invented before it was
> used. As I pointed out elsewhere, it predates the Internet, the
> dominance of tcp/ip, and SQL. I rather think C++ reflects
> its era and its origin in the land of C, not what's important to the 3
> million programmers using it in 2013.
...and GUIs, don't forget the GUIs.... (-:
Honestly, for all that stuff are solutions that interact nicely with
C++. So again, why does that have to go into the language core?
> No, I'm simply addressing myself to the problem of I/O because I note
> it's a void in the language and the cause of a lot of work and
> nonstandardized behavior that would otherwise be unnecessary. It's
> something I claim to know something about, and something we cannot
> program around.
You can't? I can. See above, it looks like a practical solution that
works. I mean, CORBA basically works this way. You write the idl, and
the IDL compiler creates the C++ skeletons from that. Works. Ok, the
CORBA C++ binding stinks, but that's a different issue.
>>> We have typeof and sizeof and offsetof. We do not have, say,
>>> memberof or nameof or parentof or childof.
>>
>> In terms of inheritance, it should be possible to do that by language
>> means and template magic
>
> Maybe, but that is not a general solution.
>
>> In terms of "pointers", it cannot be solved by the language in first
>> place. C++ has no language means to identify a tree as a tree
>
> Nor does it need one. Do you deny that the tree exists, or that the
> language could provlde an iterator for it?
Neither, but that's not the problem. Writing out pointers as offsets
from a base address is not a solution either. You need something more
complicated to make it working in general.
>>> Now, suppose you could trap SIGSEGV and walk the stack in your
>>> program, using standard functions to identify each object by name
>>> and type.
>>
>> Which would impose quite an implementation overhead not needed by most
>> programs. But still, an implementation could support it. But,
>> actually, I *don't need it*, so I don't want to pay for the feature.
>> Actually, such a thing would probably require that function inlining
>> adjusts the stack frame, or puts additional data on the stack frame,
>> and that's an overhead I don't want to pay for because my problems
>> are CPU-bound and not CPU-bound, and I'm not willing to pay for a
>> feature I don't need. If I need this feature, I pick Java.
>
> I suppose you know that the debate over what's "needed" is as old as C
> itself. I imagine you've read the Unix Haters Handbook.
>
> It's not clear to me that the stack would need adjustment, or that
> CPU-bound programs pay a measurable price for stack size. I've never
> heard of someone making a program faster by minimizing frame sizes. So
> I'm not sure that argument holds water.
Actually, I did. I do some heavy signal processing here, and believe me,
it does make a huge difference if you can inline a function without
overhead directly into the code implementing a tight loop. It is a world
where you gain customers just because you're 10% faster than your
competitor, and I need this 10% I can gain by clever programming. (Yet,
again, the 10% also require to do some things in assembler, but I'll
avoid using that whenever possible, unless I really have to. And I
rarely have to these days, luckily.)
> I think we both know that on today's hardware small is fast because
> cache is king. That mostly goes to loop optimization, where the stack
> is irrelevant.
Stack is relevant if you need to manipulate it to create a stack frame
for capturing a segfault correctly. And no, I definitely *do not* want
that overhead in my code, because, yes, it does matter, and yes, I have
observed exactly that.
> I hope I've made plain that other languages are beside the point.
Why?
> C++ systems exist. Even if we could write ODBC libraries for them in
> other languages, we couldn't automatically generate the I/O functions.
Why not? I don't see your problem. I'm using makefiles plus parsers for
that.
> You suggest yacc and Corba. I think you actually understand why
> they're nonstarters.
Actually no. I have here a project that uses OpenCL. The openCL source
that is shipped is pre-processed from some other "almost-like" OpenCL by
some parsing plus macro-magic. Embedds nicely into the built system,
simply because the OpenCL that is defined in the language lacked some
features I needed. So I created some "minimalistic" language around it.
Ok, that's not C++ (at least not this part), but its the same type of
solution.
> Until you reach a large number of structures,
> those solutions are *harder* to implement than writing operator<< by
> hand. Both are tedious and made necessary by small but crucial missing
> metadata in the C++ executable image. Neither is a C++ solution to a
> C++ problem.
Why do I need a C++ solution? I need *a solution*.
> You seem to assume that if convenient I/O is important, it's important
> enough to use some other language. That's simply not the case. Lack
> of metadata makes C++ I/O harder than it needs to be. There's no virtue
> in that, and not much defense, just Zero Mostel on the rooftop belting
> out, "Tradition!".
For most of the cases, I/O is too special to have a generic solution for
that. The I/O I need to do is byte-oriented, and I need to build all the
structures themselves. It does not make sense to have that generated by
C++ at all because the I/O format is too far away from any type of
structure or data type C++ might offer. So, when I do I/O, I'll do that
myself. Depending on the problem, even on the bit level if it must be
(and it must be, sometimes). So the solution you're offering is likely
not a solution I would consider helpful - it is too special for me and
doesn't solve my problem. It's not that I'm serializing data structures
right away.
> You say it's not possible to present inheritance metadata or to
> provide pointer extents. That argument loses on theoretical grounds.
> Whether or not it's possible depends entirely on how the language is
> defined, and it's that definition we're discussing.
>
> You're concerned about cost, and you have a lot of company. I don't
> think it's justified. If it is, the feature can be optional. RTTI is
> a compile-time option in all compilers I've used. Heck, some on this
> list don't even use the heap.
RTTI has some storage overhead, but no running time overhead, so that's
acceptable. Still, I turn it off. I don't need it. Sometimes I do not
even need or want exceptions (or have my own mechanisms of dealing with
them). So I can turn them off.
> Why am I skeptical? It's no trouble to find examples of structures
> for which pointer extents aren't needed. For every such example, there
> are thousands of uses of functions like memcpy(3), which pass the
> extent on the stack, by hand, because it's not computable. To me,
> that's obviously wrong, an example of doing by hand -- with the
> attendant error probability -- something that could be done better by
> the machine. If pointer extents were made part of the language, the
> whole standard library could be made smaller, faster, and safer to
> use.
I kinna doubt this, unless you've tried and can show some results.
> Like you, I live in the land of colossal computing where programs are
> measured in compute-hours (or days). Unlike you, apparently, my
> programs also move a lot of data over the wire. I believe the second
> problem can be made more tractable at no expense, and perhaps some
> benefit, to the first. If that's not true, I hope someone will
> demonstrate why not, instead of instantly assuming ispo facto that every
> feature has a cost.
The basic questions I have, and I haven't found a convincing answer is:
*) Why is C++ the right solution for the job?
*) Why is using external tools on C++ not a good solution?
I've used both, i.e. switched languages if I had other problems (like
GUIs, they're working like a charm in Java) or used external tools (like
my OpenCL generator) if I had something that required tight integration
into C++.
So long,
Thomas