POV-Ray : Newsgroups : povray.off-topic : Standard libraries Server Time
6 Sep 2024 11:16:48 EDT (-0400)
  Standard libraries (Message 31 to 40 of 108)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Darren New
Subject: Re: Standard libraries
Date: 6 Mar 2009 12:07:59
Message: <49b1586f$1@news.povray.org>
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> I really have to wonder, sometimes, how far people are going to mutate C++ 
>> before they just give up and decide they're done. :-)
> 
>   You make it sound like C++ is the only language which is constantly
> being developed further by adding new features and new libraries (and
> that this is somehow a negative thing?). That other currently used languages
> are more or less "ready" and do not change much.

No. But I think the current languages don't rewrite themselves as severely 
as C++ does. Other languages tend to add things, while C++ makes them 
fundamental parts of the language.  I'm assuming that the lambdas that C++ 
is adding won't be just a library bit. If it is, then bleh, but OK.

>   Of course that's pure BS. Most currently popular languages are being
> constantly developed further and their libraries enhanced. Look at Java, C#
> or the .NET framework. It's not that long ago that Java didn't even have
> generics. Now it has them.

Generics in Java are syntactic sugar. It still generates exactly the same 
code as the equivalent source done in the obvious way.

> What is the current version of .NET? 3.something?

Sure. And it has new syntax for new stuff, and it's cleanly integrated with 
the rest of the language.

>   Why do you deliberately make it sound like C++ is the only modern language
> for which new features are being added?

I'm not. I'm criticizing the way C++ adds new features, not that it does.

Every new feature in C++ seems to be hurt by (1) not wanting to pay any 
price if you don't use it, (2) not wanting to add any syntax for it, and (3) 
interacting poorly and confusingly with every other feature of the language.

If C++ added lambdas and they actually had things like pointers to stack 
frames and so on, I'd probably not be bothered. But I strongly suspect the 
lambdas they add are going to have so much brokenness to deal with the lack 
of automatic memory management and such that it's going to be harder to use 
lambdas than to just declare your own functions. And I'm betting the syntax 
will be so baroque it's going to be almost impossible to read without doing 
parsing in your head, too. Looking the little I did at the Boost lambda's, 
they're utterly awful compared to any other language with real lambdas built in.

>   I don't know if I'm just being paranoid, but I honestly think that you
> are doing this for the simple reason that you know that you are going to
> troll me.

No. I just don't like C++.  I think the way things get added to C++ is a bad 
thing for a language. They're trying to add sophisticated things from other 
languages on top of a base that really can't support it, so it's wobbling 
like an inverted pyramid, leaving the programmers to run around the outside 
propping it up with flying buttresses in their code.

When C# added LINQ, they didn't try to change the syntax of the language 
without modifying the compiler.

Python added a lot of really ugly stuff under the covers, too. But it's 
under the covers, and doesn't get in your way if you don't use it, and it's 
usable for more than just the one idea the person thought of who suggested 
it. And they didn't make the feature horribly ugly and difficult to use in 
order to save one indirection.


I hereby promise to try to remember to mention I'm trolling you if I ever 
make a post just to troll you, Warp. Fair? I can't promise I won't succumb 
to the urge to tweak you, but I'll try to remember to let you know I'm just 
teasing ya. :-)

-- 
   Darren New, San Diego CA, USA (PST)
   My fortune cookie said, "You will soon be
   unable to read this, even at arm's length."


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Standard libraries
Date: 6 Mar 2009 17:23:23
Message: <49b1a25a@news.povray.org>
Warp wrote:
>   The C++0x (well, C++1x, really) standard will most probably introduce
> lambda functions and closures, which addresses all these problems, and
> more. You will be able to write your function directly as a parameter
> to for_each() (or whichever generic function you want to use) as a
> lamdba function, and this lambda function can (optionally) have access
> to all the variables in scope.

std::vector<int> someList;
int total = 0;
std::for_each(someList.begin(), someList.end(), [&total](int x) {
  total += x
});
std::cout << total;

I read in a blog that Visual Studio already has *many* of those features
implemented (in a version not yet released even as alpha).

And gcc website has a list with C++0x implementation status :)


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Standard libraries
Date: 6 Mar 2009 17:28:09
Message: <49b1a378@news.povray.org>
Darren New wrote:
>>   Of course that's pure BS. Most currently popular languages are being
>> constantly developed further and their libraries enhanced. Look at Java,
>> C# or the .NET framework. It's not that long ago that Java didn't even
>> have generics. Now it has them.
> 
> Generics in Java are syntactic sugar. It still generates exactly the same
> code as the equivalent source done in the obvious way.

Lambdas are just syntactic sugar to defining an anonymous function, where
the code will end up stored somewhere else. Very similar to string literals
really.

> If C++ added lambdas and they actually had things like pointers to stack
> frames and so on, I'd probably not be bothered.

std::for_each(someList.begin(), someList.end(), [&](int x) {
  total += x
});

"The specific internal implementation can vary, but the expectation is that
the lambda function will store the actual stack pointer of the function it
is created in, rather than individual references to stack variables."

> Looking the little I did at the Boost lambda's, they're utterly awful
> compared to any other language with real lambdas built in.
[...]
> When C# added LINQ, they didn't try to change the syntax of the language
> without modifying the compiler.

What makes you think C++0x won't modify the compiler?! *Boost* tries to add
complex stuff without modifying the compiler. C++0x adds stuff to the core
syntax, not via a dozen stacked templates with operator overloads.


Post a reply to this message

From: Darren New
Subject: Re: Standard libraries
Date: 6 Mar 2009 19:10:14
Message: <49b1bb66@news.povray.org>
Nicolas Alvarez wrote:
> Lambdas are just syntactic sugar to defining an anonymous function, where
> the code will end up stored somewhere else. Very similar to string literals
> really.

Uh, no, not really. They're only anonymous functions if you don't have any 
free variables, at which point why bother?

>> If C++ added lambdas and they actually had things like pointers to stack
>> frames and so on, I'd probably not be bothered.
> 
> std::for_each(someList.begin(), someList.end(), [&](int x) {
>   total += x
> });
> 
> "The specific internal implementation can vary, but the expectation is that
> the lambda function will store the actual stack pointer of the function it
> is created in, rather than individual references to stack variables."

So it's not really a closure, but a downward funarg. That's exactly the sort 
of thing I was talking about.  You can't return a lambda, I take it?

What's the type of
    [&](int x) { total += x; }

What kind of variable can I assign that to?

> What makes you think C++0x won't modify the compiler?!

Well, that's good. The syntax, of course, is going to be baroque because 
they're still trying to pretend they're upward compatible with C. :-)

-- 
   Darren New, San Diego CA, USA (PST)
   My fortune cookie said, "You will soon be
   unable to read this, even at arm's length."


Post a reply to this message

From: Warp
Subject: Re: Standard libraries
Date: 6 Mar 2009 20:01:47
Message: <49b1c77b@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
> > Darren New <dne### [at] sanrrcom> wrote:
> >> I really have to wonder, sometimes, how far people are going to mutate C++ 
> >> before they just give up and decide they're done. :-)
> > 
> >   You make it sound like C++ is the only language which is constantly
> > being developed further by adding new features and new libraries (and
> > that this is somehow a negative thing?). That other currently used languages
> > are more or less "ready" and do not change much.

> No. But I think the current languages don't rewrite themselves as severely 
> as C++ does.

  Exactly how are they "rewriting" C++?

  C++0x will be basically fully compatible with the current C++ standard
(give or take a few minor things which will get deprecated). Only additional
functionality and libraries will be added. What rewrite?

> Other languages tend to add things, while C++ makes them 
> fundamental parts of the language.

  I don't understand. How are "adding things" and "making things fundamental
parts of the language" mutually exclusive?

  It's not like the new features would *replace* existing features. They
are pure additions. So I really don't see your point.

>  I'm assuming that the lambdas that C++ 
> is adding won't be just a library bit. If it is, then bleh, but OK.

  Lambdas will be at core language level in the exact same way as eg.
generics in Java are at cure language level. I don't see your problem.

> >   Of course that's pure BS. Most currently popular languages are being
> > constantly developed further and their libraries enhanced. Look at Java, C#
> > or the .NET framework. It's not that long ago that Java didn't even have
> > generics. Now it has them.

> Generics in Java are syntactic sugar. It still generates exactly the same 
> code as the equivalent source done in the obvious way.

  And lambdas in the new C++ are syntactic sugar. The compiler will generate
exactly the same machine code as if you had written a non-lambda function.
(The only difference is the internal name mangling.)

  They are a convenience feature. They will make a lot easier to write
generic code.

> > What is the current version of .NET? 3.something?

> Sure. And it has new syntax for new stuff, and it's cleanly integrated with 
> the rest of the language.

  You say it like the new C++ features aren't. Care to explain?

> >   Why do you deliberately make it sound like C++ is the only modern language
> > for which new features are being added?

> I'm not. I'm criticizing the way C++ adds new features, not that it does.

  Right. When other languages add new features (let's say, for example,
Java adding support for generics), that's ok. But when C++ adds new features,
that's something to be critiqued.

  No, you are not biased at all.

> Every new feature in C++ seems to be hurt by (1) not wanting to pay any 
> price if you don't use it,

  Care to explain how, for example, lambda functions would add some overhead
to the C++ language even when you don't use them?

> (2) not wanting to add any syntax for it,

  Have you even looked at how lambda functions will be written in the new
C++ standard? How is it not adding new syntax for it?

> and (3) 
> interacting poorly and confusingly with every other feature of the language.

  Care to elaborate?

> If C++ added lambdas and they actually had things like pointers to stack 
> frames and so on, I'd probably not be bothered. But I strongly suspect the 
> lambdas they add are going to have so much brokenness to deal with the lack 
> of automatic memory management and such that it's going to be harder to use 
> lambdas than to just declare your own functions. And I'm betting the syntax 
> will be so baroque it's going to be almost impossible to read without doing 
> parsing in your head, too. Looking the little I did at the Boost lambda's, 
> they're utterly awful compared to any other language with real lambdas built in.

  Good thing you are not prejudiced nor biased in the least.

> >   I don't know if I'm just being paranoid, but I honestly think that you
> > are doing this for the simple reason that you know that you are going to
> > troll me.

> No. I just don't like C++.

  And for that reason you have to constantly write prejudiced BS about it.

>  I think the way things get added to C++ is a bad 
> thing for a language.

  What way? Care to explain?

  And which way would you think would be better?

> When C# added LINQ, they didn't try to change the syntax of the language 
> without modifying the compiler.

  I don't even understand what you are saying there.

> Python added a lot of really ugly stuff under the covers, too. But it's 
> under the covers, and doesn't get in your way if you don't use it, and it's 
> usable for more than just the one idea the person thought of who suggested 
> it.

  First you critique C++ because the ideology is that new features don't
have any effect if you don't use it. Now you are praising Python for the
exact same thing, implying that in C++ new features *do* have some negative
effect even if you don't use them.

  You are not writing consistently.

  IMO you are just prejudiced and don't know what you are talking about.

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Standard libraries
Date: 6 Mar 2009 20:05:44
Message: <49b1c868@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> What's the type of
>     [&](int x) { total += x; }

> What kind of variable can I assign that to?

  You don't have to know the type (and in fact, the type is unspecified).
You create a variable like this:

auto myLambdaFunc = [&](int x) { total += x; };

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Standard libraries
Date: 6 Mar 2009 20:08:22
Message: <49b1c906@news.povray.org>
Nicolas Alvarez <nic### [at] gmailcom> wrote:
> std::for_each(someList.begin(), someList.end(), [&total](int x) {
>   total += x
> });

  I think they are also considering adding alternative versions of all
algorithms which take an iterator range. These alternative versions would
take a container and automatically apply the algorithm to all of its
elements, so you could just write:

    std::for_each(someList, [&total](int x) { total += x });

-- 
                                                          - Warp


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Standard libraries
Date: 6 Mar 2009 21:22:44
Message: <49b1da73@news.povray.org>
Warp wrote:
> I think they are also considering adding alternative versions of all
> algorithms which take an iterator range. These alternative versions would
> take a container and automatically apply the algorithm to all of its
> elements

Yes, it's boost::range made standard :D (but probably implemented
differently)


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Standard libraries
Date: 6 Mar 2009 21:30:12
Message: <49b1dc33@news.povray.org>
Darren New wrote:
> So it's not really a closure, but a downward funarg. That's exactly the
> sort
> of thing I was talking about.  You can't return a lambda, I take it?
> 
> What's the type of
>     [&](int x) { total += x; }
> 
> What kind of variable can I assign that to?

"Lambda functions are function objects of a implementation-dependent type;
this type's name is only available to the compiler. If the user wishes to
take a lambda function as a parameter, the type must be a template type, or
it must create a std::function to capture the lambda value. The use of the
auto keyword can locally store the lambda function"

The 'auto' keyword is what Warp mentioned. I guess you can also use
std::function to safely return a lambda.

"However, if the lambda function captures all of its closure variables by
reference, or if it has no closure variables, then its type shall be
publicly derived from std::reference_closure<R(P)>, where R(P) is the
function signature with return type. This is expected to be a more
efficient representation for lambda functions than capturing them in a
std::function."

All this is from Wikipedia article "C++0x". Next time please do some minimal
research before claiming C++ sucks :)


Post a reply to this message

From: Darren New
Subject: Re: Standard libraries
Date: 6 Mar 2009 23:07:48
Message: <49b1f314$1@news.povray.org>
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> What's the type of
>>     [&](int x) { total += x; }
> 
>> What kind of variable can I assign that to?
> 
>   You don't have to know the type (and in fact, the type is unspecified).
> You create a variable like this:
> 
> auto myLambdaFunc = [&](int x) { total += x; };

And when you return that from the function as the function's value, what 
happens with the free variables? How do you declare the function that ends 
execution with "return myLambdaFunc"?  How do you make it a part of a structure?

-- 
   Darren New, San Diego CA, USA (PST)
   My fortune cookie said, "You will soon be
   unable to read this, even at arm's length."


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.