From: nmm1 on
In article <eilt26dg0ghmigp6j2cuudi29pkfqsuvkl(a)4ax.com>,
George Neuner <gneuner2(a)comcast.net> wrote:
>>>
>>> All of Algol 68, Fortran, Genstat, Lisp, Haskell, PL/I
>>> and most of the others I have used or helped with have fundamental
>>> concepts that have no equivalent in C++ - and conversely.
>>
>>Also, I cannot see a truly fundamental programming concept from those
>>languages (ignoring Genstat that appears offtopic, albeit I don't know
>>it) that C++ is completely lacking.
>
>Runtime generics (Lisp), coroutines (PL/I), closures (Lisp, PL/I and
>Haskell). Don't have a clue what Genstat might contribute.
>
>C++0x will have threads and poor excuses for anonymous functions, but
>it's still lacking real closures and runtime generics.

Yes. And first-class support for multi-dimensional arrays (as in
Fortran and Algol 68). Etc. Genstat is the view from the other
edge of the universe :-) I use it as a language example, as it
was designed entirely by statisticians and yet is a full-blown
Turing complete language - I think that computer scientists should
learn it, just as a mind-stretching exercise. It's as different as
SNOBOL or Prolog in different ways - and about as relevant to C++.

Practically, all of those except Genstat demonstrate important and
relevant approaches to C++ programming and design (and conversely,
of course).


Regards,
Nick Maclaren.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andre Kaufmann on
On 04.07.2010 00:50, Dragan Milenkovic wrote:
> Andre Kaufmann wrote:
>> Mathias Gaunard wrote:
>>> On Jun 30, 8:51 am, Daniel <danielapar...(a)gmail.com> wrote:
>>>> It doesn't do functional well.
>>>
>>> It does it pretty well, even if C++0x lambdas are disappointing.
>>
>> It supports all the features of functional languages like OCaml / ML /
>> F# ?
>>
>> Does it support at least function currying ?
>
> This would be my opportunity to learn more. Could you provide
> a real-world example for the usage of function currying?
> I looked it up briefly, and there are only examples for example
> sake, nothing useful. No need to explain if you can provide a link.

I give it a try. I too learn currently functional languages and try to
widen my horizon.
Since I don't use functional languages for my daily work I'm not an
expert (if there is one around, please correct me if necessary):

I think C++ has been influenced by functional languages too and one
result of this influence is that lambda functions have been added.
Function currying can be done by using lambdas in some way:

Short comparison:

OCaml/F#:

let Div x y = x / y
let Div5 x = Div x 5
let value = Div5 10
printfn "%A" value

In C++0x this could be simulated by using lambda functions:

auto Div = [] (int x , int y) { return x / y; };
auto Div5 = [&Div](int x) { return Div(x, 5); };
int res = Div5(10);
printf("%d", res);

More equivalent would be this invalid C++0x code:

auto Div = [] (auto x , auto y) { return x / y; };
auto Div5 = [&Div](int x) { return Div(x, 5); };

But besides readability I think there are two differences between the 2
code samples:

a) Function arguments are not typed - type inference is used
(like auto in C++)

b) If I understood it correctly, function and type expansion is deferred
You deal with functions like with any other types and
variables. You can modify them, pass them to other functions
and so on.
Besides flexibility, it also enables the compiler to efficiently
generate code through deferred function expansion.

It's not about that it can't be done in C++. You would have to use
templates, lambda functions, meta template programming in C++.
But at the cost of readability and flexibility.

> [...]
>> It would add overhead to the file to add meta data information to do
>> reflection appropriately, but not that much to memory - IMHO.
>
> For each and every structure? Unlike in Java, in C++ I write many more
> or less significant structures. Maybe a compromise - enable reflection
> only if a class is marked with an attribute?

Yes, would be a good compromise.
But there would be another advantage to have more meta information:

If there would be meta information about classes, functions and
parameters available, a wrapper generator could emit code, which
would enable other C++ compilers or even other languages to call the
functions or even use the classes directly which are in a (compiled)
library.
A kind of C++ ABI.

> [...]
>> a) Use the C++ source module directly (single file)
>> b) Generate and use a library but don't have to ship the header file,
>> but directly include it in the library itself
>
> IMHO, this is outside of the scope of the language. While it may
> or may not require an amendment to the Standard, a special
> compiler/linker could handle the integration of header+library
> and then name it a "module".

Yes agreed, but since other languages have a much wider scope and
therefore offer such flexibility I miss that in C++.

> However, what would be really nice is something to make
> the pimlp idiom obsolete. :-D

Yep, a module concept is IMHO badly needed in C++. Unfortunately it has
been removed from the first C++0x proposals.

> [snip]

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andre Kaufmann on
On 04.07.2010 00:54, Joshua Maurice wrote:
> On Jul 2, 1:49 pm, Andre Kaufmann<akfmn...(a)t-online.de> wrote:
>> Mathias Gaunard wrote:
>>> On Jun 30, 8:51 am, Daniel<danielapar...(a)gmail.com> wrote:
>>>> Using
>>>> unicode is painful.
>>
>>> No programming language does this right anyway.
>>
>> C# for example has it right out of the box. There are only unicode strings.
>
> It depends. Java, and from what I can quickly google C#, both handle
> [...]
> a Unicode code point, but a UTF-16 encoding unit. Java and C# do a lot
> better than C++ standard strings, which are all but worthless relative
> to std::vector<char> for proper Unicode handling. Let's look at
> possible operations one might want to do with Unicode strings:

Agreed, C# and Java strings are not perfect, but better than C++ standard strings regarding Unicode.
I think C# has been influenced by Windows Unicode support.

> [...]


>
> There's also the point that C++ ICU, Java, and C# force an encoding on
> you, UTF-16, which may not be optimal for your data. UTF-8 tends to
> outperform UTF-16 for most Latin-based languages in terms of memory
> footprint, and thus also execution time. Preferably the string

May be. I would also tend to save my data in UTF8. But at runtime I don't know if there is a significant difference in execution time.


> abstraction would be independent of internal encoding of UTF-8,
> [...]

Thank you for the detailed comparison. Unicode seems to be quite simple at first sight. But is quite complex if you have to use it throughout your application and under multiple operating systems.
We had a lot of trouble adding Unicode support to our C++ applications.
To be binary compatible we used UTF8 for transportation and internally used UTF16 where possible. But it happened more than once that multiple conversions (text / xml / binary etc.) that we missed to convert the characters at one location appropriately. Such bugs where quite hard to find and we are not sure if we found them all already.

Besides the subtle bugs caused by functions dealing with character pointers and number of characters directly.


Andre

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andre Kaufmann on
Mathias Gaunard wrote:
> On Jul 2, 9:49 pm, Andre Kaufmann <akfmn...(a)t-online.de> wrote:
> [...]
> The executable (the file) is mapped into memory in order to run the

Into virtual memory. Resources are only mapped to physical memory if they are accessed.

> program.
> How do you think things work?

In C# for example the information is retrieved from the meta data.
Adds some runtime overhead, if used.

> [...]

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andre Kaufmann on
Jerry Stuckle wrote:
> Andre Kaufmann wrote:
>> Mathias Gaunard wrote:
>>> On Jul 1, 4:14 pm, n...(a)cam.ac.uk wrote:
> [...]
>
>> - Emit code and compile on the fly - C++ scripting ?
> Who cares?

Is that a typical "default answer" ?

> It's an entirely different model.

Many languages offer that. E.g. C#.
And the model is not different. Why can't I simply take a C++ code like

double value = sin(x)/x;

(the formula has been entered in an edit box)

compile it in the background and let it execute instead of interpret it.
Wouldn't that be faster than just interpreting the formula ?
I can exactly do that in C#.

Or take a complex regular expression. Why can't I simply compile it to code. In C# I can do that.

>> - Can you take a function as an argument and parse it's structure?
> Who cares? That's not the intent of C++.

Why do so many try to do/simulate that with C++ meta template programming ?

>> - Can I interchange / directly call code written in other languages
>> without writing C wrappers ?
> Yes.

Ok - call Java code from C++ code which then calls C# code ?
Otherwise there wouldn't be a need for wrapper generators like SWIG.

>> - Can I mix libraries written with different C++ compilers
> Can you do this in ANY language?

C# for example.

>> - Can I mix C++ code libraries compiled for different platforms
> Can you do this in ANY language?

C# for example.

>> - Can I write portable GUIs in C++ (e.g. with Qt but, isn't standard)
> Can you do this in ANY language?

Better than in C++.

>> - I want to write binary data, e.g. a set of integers.
>> How can I do that, that every platform and C++ compiler can read it ?
>> (no fixed size types with defined binary layout)
> Can you do this in ANY language (except, maybe, Java?). But then, how
> important is this?

If I use text format write and read data it isn't important.
But if I pass a structure to a library written in another one I have to care about if the integer is 16 or 32 bit wide and how the compiler aligns the structure members.

>> - Can I initialize class member objects / values directly where
>> they are defined.
>>
> Who cares? That's what constructors are for.

class foo
{
foo(int a) :
value1(10),
value2(10),
value3(10),
{}

foo(string a) :
value1(10),
value2(10),
value3(10),
{}

foo(double a) :
value1(10),
value2(10),
value3(10),
{}

int value1;
int value2;
int value3;
};

compared to:

class foo
{
foo(int a) {}
foo(string a) {}
foo(double a) {}
int value1 = 10;
int value2 = 10;
int value3 = 10;
}


> Nope, that's what constructors are for.

Do you need are more detailed explanation about the advantages ?

Yes I want to call the constructor of the value where I define it ->
RAII - not have to write it multiple times in different constructors.
Though C++0x addresses this problem somewhat with delegating constructors.


Additionally static values do use this initialization scheme already:

class a
{
static int value;
};

int a::value = 0;

Huh ? No constructor involved ?


> [...]
> But virtually everything you want either shows no understanding of the

Sound like you described yourself.

> language itself, or has nothing to do with the language itself.
> Sounds like you want Java instead.

Nope.

I either want the D-Language or C# with RAII.
Or that C++ evolves that way.



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]