| rapidcoder (736) | ||||
|
No, they are not the same, they are different. Duck typing is bad. Especially in a language that calls itself "statically typed".
So none of C++ IDEs fully support them.
| ||||
|
Last edited on
|
||||
| L B (3806) | |||
Intellisense/autocomplete should NOT work there and for good reason.
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
|
|||
| Oria (71) | |
|
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
|
|
| rapidcoder (736) | ||||
I can compare, because they are serving the same purpose.
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)
Duck typing is bad, because errors are detected late. | ||||
|
Last edited on
|
||||
| L B (3806) | |||||||
| |||||||
|
Last edited on
|
|||||||
| ResidentBiscuit (2645) | |
| 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? | |
|
|
|
| L B (3806) | |||
|
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.
http://en.cppreference.com/w/cpp/types | |||
|
Last edited on
|
|||
| chrisname (6181) | |
| If you agree that they're used for the same purpose, why did you argue when rapidcoder said as much? | |
|
|
|
| L B (3806) | |
| I thought rapidcoder was arguing that they were the same? I probably misunderstood, sorry... | |
|
Last edited on
|
|
| cire (2347) | |
| Since when does similar mean same? | |
|
|
|
| L B (3806) | |||
| |||
|
|
|||
| xerzi (605) | |
| 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
|
|
| rapidcoder (736) | |||||
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.
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.
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 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
|
|||||
| Cubbi (1925) | ||
My experience has been the opposite. | ||
|
|
||
| L B (3806) | |||||||||||
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.
| |||||||||||
|
Last edited on
|
|||||||||||
| JLBorges (1754) | ||
|
> 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:
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
|
||
| rapidcoder (736) | |
|
JLBorges, by resorting to personal arguments you lost the discussion. EOT. | |
|
|
|
| chrisname (6181) | |
|
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. | |
|
|
|
| JLBorges (1754) | |
|
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
|
|
| L B (3806) | |
| I guess we just can't have nice things in the lounge area. | |
|
|
|