Im learning java, do they have a forum as simple and easy going as this one

Pages: 1... 345678

One can only discuss C++ templates with people who know C++; for instance, people who realize that std::function() / std::bind() or their boost equilvalents are powered by metaprogramming; that std::iterator_traits<> is not a figment of imagination; that these are routinely used in real-life C++ programs.


Nice, but all these things are in Java, e.g. in Guava libraries. Sometimes they may be little more verbose, but again - these are only syntactic differences. So even if in C++ they are powered by metaprogramming, metaprogramming is not needed to implement them. It is only one of many ways of achieving the same.

You completely misunderstood what I was saying: 99% of uses of templates is not metaprogramming. It is like I'd say most of code created today is not machine code. And you say, that "no, it is machine code, because all the programs at some level are machine code".
Last edited on
With all the goodies in C++11 I'd say template metaprogramming is getting used more often.
closed account (o1vk4iN6)
The argument that it can't be done is pointless, that is the point of it being turing complete. I can calculate the factorial of a constant before run time, sure you can do that in Java but that isn't really the point where in Java it'd be calculated at run time in C++ the result would simply be stored in memory. Not everyone has 1000 servers in their basement where they can run their scalable Scala programs like you apparently do.
> Nice, but all these things are in Java, e.g. in Guava libraries.

No, they are not. Guava is a very useful library for Java programmers; primarily because the containers and iterators in Java suck big time. But it can't do even a fraction of what the C++ standard library can do.

Many of the .NET libraries have much greater expressiveness. But then, .NET has always had far better support for generic programming than Java.



> So even if in C++ they are powered by metaprogramming,
> metaprogramming is not needed to implement them.
> Sometimes they may be little more verbose, but again - these are only syntactic differences.

Yes; there is nothing that can be done in C++ that can't be done in machine code. Any difference between C++ and machine code is mere syntactic difference.



> You completely misunderstood what I was saying: 99% of uses of templates is not metaprogramming.

A large part of the use of templates in C++ is the use of the standard library; another significant part is the use of boost libraries. Every one who drives a Ferrari does not build its engine, they just use it. So?



> And you say, that "no, it is machine code, because all the programs at some level are machine code".

No, that's what you are saying when you attempt to compare C++ templates and Java generics. Even in comparison to .NET generics, Java's offering looks like something the cat brought in during the night.

Many of the .NET libraries have much greater expressiveness. But then, .NET has always had far better support for generic programming than Java.


I cannot take much part of this discussion as I've only used generics in C# and I've not yet started learning templates yet in C++, though they do look very similar to C# generics/interfaces at a first glance.

However, in every article and documentation I've read about Java, it seems to be missing some of the features I've come to love in C#/.NET which I hope I will find in C++. And because I don't think Java as an equivalent to LINQ, (correct me if I'm wrong); I would assume Java generics would not be as useful.

But it can't do even a fraction of what the C++ standard library can do.


The number of things that are not in the C++ STL and that are in Java Standard Library is an order or two of magnitude larger than the number of things missing from Java.

And many of the goodies of STL are only for dealing with problems caused by limitations of C++, e.g. std::bind (lack of currying), or std:shared_ptr (lack of GC) or std::lock (lack of synchronized). You may say that this is actually good to move complexity from the language into libraries, but the cost for that is ugly syntax and lower performance.


No, that's what you are saying when you attempt to compare C++ templates and Java generics. Even in comparison to .NET generics, Java's offering looks like something the cat brought in during the night.


Don't forget that Java has had 100x more marketshare than .NET at the time generics were added. It is much harder to evolve popular language that offers backwards compatibility. Without that constraint Java's generics would be probably something similar to what is in Scala (and without erasure) - Scala's generics are designed by exactly the same guy.


I cannot take much part of this discussion as I've only used generics in C# and I've not yet started learning templates yet in C++, though they do look very similar to C# generics/interfaces at a first glance.


They look similar, they are used for the similar things, but diehard C++ coders will tell you they are something completely different. When you use them in form of e.g. std::functor you are enlightened by an amazing C++ light, you become a master of metaprogramming, and you get +100 to the karma. This is of course totally different than those Java code monkeys using lame generics and function objects for exactly the same purpose... They are not doing metaprogramming, you know. :D
I don't understand, you bash C++ for adding in stuff to make up for missing features in a way that is reverse compatible, and then you defend Java for adding in stuff to make up for missing features in a way that is reverse compatible.
They invented a great feature called the pen. which is great because the crayons were not that easy to read on legal forms. On a side note, I love crayons... but lets argue one which is better, a blue pen or a red pen... or are they the same?
I'm trying not to be biased, but I keep feeling like rapidcoder is biased against C++ for Java, and I feel compelled to correct that.
but I keep feeling like rapidcoder is biased against C++ for Java, and I feel compelled to correct that.
You can't "correct" a bias, it's a personal opinion/feeling. Its more likely you'll enjoy pissing into the wind then it is that you'd change his (or anyones) bias.
> The number of things that are not in the C++ STL and that are in Java Standard Library ...

Read once again, first your statement, and then the response:

> Nice, but all these things are in Java, e.g. in Guava libraries

>> No, they are not. Guava is a very useful library for Java programmers; primarily because the containers and iterators in Java suck big time. But it can't do even a fraction of what the C++ standard library can do.


And if you still do not understand what is being talked about, (all these things refers to std::function() / std::bind(), std::iterator_traits<> etc., things that are woefully lacking in the Java Standard Library), which you incorrectly claimed were all there in the Guava library, what the term 'it' refered to, go back and read a third time.



> Without that constraint Java's generics would be probably something ...

The preposterous earlier claims were on what the so-called generics in Java are. Not on what it probably could (or rather should) have been.



> I've only used generics in C# and I've not yet started learning templates yet in C++,
> though they do look very similar to C# generics/interfaces at a first glance.

>> They look similar, they are used for the similar things


No they are not used for similar things. There is some commonality in that .NET generics and C++ templates are both used for generic programming. C# generics have far greater expressive power than the caricature of generics that Java has.

In stark contrast to Java, a comparison of .NET generics and C++ templates would not be entirely grotesque.
1
2
3
4
5
6
7
8
9
IEnumerable<Customer> customerQuery = 
        from cust in customers
        where cust.City == "London" 
        select cust;

foreach (Customer customer in customerQuery)
{
    Console.WriteLine(customer.LastName + ", " + customer.FirstName);
}


To my curiosity, what would be the equivalent to this in C++ and in Java.
Last edited on
C++03 or C++11?
Java 5 or Java 7?
C++ 11 because that's what I am learning at the moment.

Java (whatever version). I don't think I will ever learn Java, since I am bias towards C# :p just curious to see how it would look.

on a side note, I dont think Java has an equivalent to LINQ in any versions.
Last edited on
Last edited on
http://github.com/hjiang/linqxx/wiki


Thank you Chrisname, that looks very promising! I found LINQ to be very quick and efficient, even for games.
I might have read that it's usually slower than pure C#, but I might have made that up.
Using just the standard library and nothing elser, an equivalent (with C# style references) would be:
1
2
3
4
5
6
std::vector< std::reference_wrapper<Customer> > customerQuery ;
std::copy_if( customers.begin(), customers.end(), std::back_inserter(customerQuery),
                [] ( const Customer& c ) { return c.City == "London" ; } ) ;

for( const auto& c : customerQuery )
    std::cout << c.get().LastName << ", " << c.get().FirstName << '\n' ;


In practice, to implement LINQ or any other DSEL, C++ programmers would typically use boost::spirit.
http://boost-spirit.com/home/
I tried to do that ^ but I didn't know about std::copy_if. Mine was identical except that I was trying to figure out how to do it with std::copy. Ah well.
Thanks JLBorges. I quickly had a look at Boost libraries and I liked what I saw. And your code example brings my hopes up in using C++ for everything. Besides, if I feel desperate, I can use .NET libraries with C++/CLI.
Pages: 1... 345678