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

Pages: 123456... 8
No, they are not the same, they are different.

Duck typing is bad. Especially in a language that calls itself "statically typed".


I'd like to know why you would try using autocomplete with C++ templates in an IDE that didn't fully support them.


So none of C++ IDEs fully support them.

1
2
3
4
template <typename T>
void someFunction(T arg) {
  arg.  // here does autocomplete work? 
}

Last edited on
Intellisense/autocomplete should NOT work there and for good reason.
1
2
3
static <T> void someFunction(T arg) {
  arg.  // here does autocomplete work? 
}
Obviously not, because it doesn't make sense in Java. It makes sense in C++ because you can't compare C++ templates to Java generics. Please stop trying.

Also, it's template<typename T> and not <template typename T>

What I would enjoy discussing, however, is why you think duck typing is bad, and why you think it has anything to do with C++ being statically typed. It's static duck typing...
Last edited on
This thread is one argument after another...

First Java generics compared to C# generics
http://www.jprl.com/Blog/archive/development/2007/Aug-31.html

then C# generics compared to C++ templates.
http://msdn.microsoft.com/en-us/library/c6cyy67b.aspx
Last edited on

Obviously not, because it doesn't make sense in Java. It makes sense in C++ because you can't compare C++ templates to Java generics.


I can compare, because they are serving the same purpose.


Intellisense/autocomplete should NOT work there and for good reason.


In Java it works in this case. Especially with the presence of type bounds, which C++ lacks (you can only simulate them like here: http://stackoverflow.com/questions/6803100/achieving-bounded-genericity-in-c, but again - it doesn't play well with IDEs)

What I would enjoy discussing, however, is why you think duck typing is bad, and why you think it has anything to do with C++ being statically typed. It's static duck typing..


Duck typing is bad, because errors are detected late.
Last edited on
rapidcoder wrote:
I can compare, because they are serving the same purpose.
C++ templates are used for Template Metaprogramming, Java generics are used for convenience of syntax. At the very basic std::vector<Type> and java.util.ArrayList<Type>, I can see how many people would say they are used the same way, but they are actually very very different. You can do things with C++ templates that you just can't do with Java generics, because they are not the same. Whether or not you should actually be doing those things with C++ templates is not my point, my point is that C++ templates and Java generics are not the same and should not be compared. I'm not hating on Java or Java generics, not am I glorifying C++ or C++ templates - I'm just trying to say that you shouldn't be comparing them because they're so vastly different. So far you have been arguing every one of my side points, rather than explaining how C++ templates and Java generics are the same. I'm not going to argue your knowledge of Java (I don't doubt that), but I am going to argue your stance that C++ templates and Java generics are closely related.
rapidcoder wrote:
In Java it works in this case.
Let me guess: it only gives you access to the fields from Object and whatever else you specified T to extend. I definitely was wrong when I said it didn't work; I meant that you couldn't know what the used type of T was (because it wouldn't make sense).
rapidcoder wrote:
Duck typing is bad, because errors are detected late.
Duck typing in C++ is bad, or duck typing in general is bad? Because I think duck typing is pretty useful (see Google's Go programming language), though I can agree that its use in C++ is problematic.
Last edited on
How are templates and generics not accomplishing the same thing? Seems to me they are both just used to present a single interface that can be used with varying data types. Is this wrong?
C++ templates are literally a "template" for the compiler to use to generate functions and classes. Java generics are for static type checking at compile time and are not dealt with in the same manner as C++ templates.

While they are often used for similar purposes, they are vastly different.

ResidentBiscuit wrote:
Seems to me they are both just used to present a single interface that can be used with varying data types. Is this wrong?
C++ templates are used by the compiler to actually generate brand new functions and classes. With specializations, it gets even more different from generics. Check out type traits:
http://en.cppreference.com/w/cpp/types
Last edited on
If you agree that they're used for the same purpose, why did you argue when rapidcoder said as much?
I thought rapidcoder was arguing that they were the same? I probably misunderstood, sorry...
Last edited on
Since when does similar mean same?
rapidcoder wrote:
I can compare, because they are serving the same purpose.
This is probably what I misunderstood. I took this to mean that templates are used for the same things as generics, which they are in only a few cases. In most cases they are not.
closed account (o1vk4iN6)
Java has made you soft if you can't program without auto-complete rapidcoder :P. Templates are turing complete, saying Java generics are easier to debug and has auto-complete is like saying my language XXYY can auto-complete a program simply by naming the source file what you want it to do.
Last edited on

Java has made you soft if you can't program without auto-complete rapidcoder :P.


Who's saying I can't code without autocomplete? I can, but it is slower.
In C++ you don't have choice, considering how badly autocomplete works. It helps usually only in trivial cases, where you don't need it anyway.


Templates are turing complete, saying Java generics are easier to debug and has auto-complete is like saying my language XXYY can auto-complete a program simply by naming the source file what you want it to do.


For 99% of code out there being turing completeness is less important than having good tooling. If you want Turing complete generics, Scala has one. Built on top of Java. So Java can definitely do it. BTW: As for Scala, Scala 2.10 has something more - typesafe macros, which offer much more flexibility for metaprogramming than templates.


C++ templates are used for Template Metaprogramming, Java generics are used for convenience of syntax.


Nope. C++ templates are used mostly for convenience of syntax, i.e. to implement library goodies that are in STL and Boost: strings, containers, smart pointers, atomics, etc. They have nothing to do with metaprogramming. These are all the things that Java generics are used for. Metaprogramming is academic topic - people talk about it at OOPSLA or write nice books, but it is rarely used in production level software.

C++ template metaprogramming is like a car that can swim. Technically sophisticated. Probably complex to operate. Probably less safe. Obviously more functional than an ordinary car. But, honestly, how often do you need one, if there are bridges?


I thought rapidcoder was arguing that they were the same? I probably misunderstood, sorry...


I was not saying they are the same. I'm saying they are used mostly for the same purpose. And for the purposes they are used for, Java generics are better. For real metaprogramming, templates feel very limited compared to what other languages offer (LISP, Scala, even Python).

BTW: As we are at metaprogramming, Java can do it too, and does it, but not with generics. Things like ASM / CGLIB / instrumentation agents are doing it for years. And it is again stronger than templates, because they can modify/generate code dynamically, not only at compile time.
Last edited on
Metaprogramming [...] is rarely used in production level software.

My experience has been the opposite.
I'll admit I don't know too much about template metaprogramming, but I thought there was a lot of it used in the new stuff added in C++11. I'm probably wrong. I thought all the static template stuff was metaprogramming.

rapidcoder wrote:
In C++ you don't have choice, considering how badly autocomplete works. It helps usually only in trivial cases, where you don't need it anyway.
This depends on your IDE :p

rapidcoder wrote:
So Java can definitely do it.
No, Scala can definitely do it.

rapidcoder wrote:
typesafe macros
lol - that's a pretty poor name. Macros are a literal find-and-replace text substitution that don't care about the language they're being used in. They'd suddenly have to be aware of the language they're being used in to be typesafe. I don't doubt that they're cool, it's just a funny name.

rapidcoder wrote:
C++ templates are used mostly for convenience of syntax, i.e. to implement library goodies that are in STL and Boost: strings, containers, smart pointers, atomics, etc.
Unlike in Java, in C++ there is no Object class which all classes extend. There is no way to replicate Java generics in C++. You try implementing boost without templates, since they're only "convenience of syntax".

rapidcoder wrote:
I'm saying they are used mostly for the same purpose. And for the purposes they are used for, Java generics are better.
"Better" in what way? What are Java generics doing better than C++ templates? (in the context of similar use) It needs to be a majority.
Last edited on
> I thought rapidcoder was arguing that they were the same? I probably misunderstood

Yes, you misunderstood completely.

This JBigot is a JFrog in the JWell; in the pipsqeak language which he fanatically champions, crude, poorly designed support for parametric polymorphism goes under the rather pretentious name of 'generics'.

When the JBigot says:
C++ templates ... dah dah dah ... STL and Boost: strings, containers ... dah dah dah ... They have nothing to do with metaprogramming. ... dah dah dah ... Metaprogramming is academic topic ... dah dah dah ... it is rarely used in production level software.

He is merely saying that anything outside the narrow bounds of his ignorance just can not exist. Did I hear someone say std::advance()? You must be kidding; that is metaprogramming, just can't be used in production level software.

The JBigot likes to pontificate - at excruciating length - on things that he knows nothing about. And that this character knows almost nothing about production level C++ software has been demonstrated time after time in the past. Keep that in mind, and there is will be no cause for any misunderstanding.
Last edited on
JLBorges, by resorting to personal arguments you lost the discussion. EOT.
To be fair, he's not saying your argument is wrong because you're an "ignorant JBigot", he's just calling you that while arguing your actaul position (sort of). So, these aren't ad hominems, they're just plain old insults.

He's still an asshole though.
EDIT: > JLBorges, by resorting to personal arguments you lost the discussion. EOT.

There is no discussion.

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.


EDIT:
> he's not saying your argument is wrong because you're an "ignorant JBigot",
> he's just calling you that while arguing your actaul position

No, I'm not arguing any position; just saying ignorant bigot because the arguments (so to speak) are grounded on both ignorance and bigotry.


> He's still an asshole though.

Yes. I agree.
Last edited on
I guess we just can't have nice things in the lounge area.
Pages: 123456... 8