Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As a C++ developer, I see things entirely the other way. Java templates are much less powerful than C++ templates. In Java, templates were basically just a convenient way to do type erasure. That's better than nothing, but the inability to specialize templates makes them quite limited. In C++, you can define a common base class if you need one, but being able to optimize based on the template type is very useful.

Function templates are great for writing concise, efficient math that handles half-precision, single-precision, double-precision, single-precision complex numbers and double-precision complex numbers (and more) with minimal duplication.

Templates are also what make interfaces like std::format efficient and easy to use.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: