Java – Should we avoid language features that C++ has but Java doesn’t

ccode-qualityjava

Suppose I am limited to use C++ by the environment in the project. Is it good to prevent the use of some language features that C++ has but Java doesn't have (e.g.: multiple inheritance, operator overloading)?

I think the reasons are:

  1. As Java is newer than C++, if Java doesn't provide a feature that C++ has, it means that the feature is not good, so we should avoid using it.
  2. C++ code with C++ specific features (e.g.: friend functions, multiple inheritance) can only be maintained or reviewed by C++ programmers, but if we just write C++ like Java (without C++ language specific feature), the code can be maintained or reviewed by both C++ and Java programmers.
  3. You may be asked to convert the code to Java some day
  4. Code without C++ specific features is usually more maintainable
  5. Every C++ language specific feature (e.g.: multiple inheritance) should have alternatives to be implemented in Java. If it doesn't, that means the design pattern or code architecture is problematic.

Is that true?

Best Answer

No. This is woefully and terribly misguided.

  • Java features are not somehow better than C++ features, especially in a vacuum.
  • If your programmers don't know how to use a feature, train or hire better developers; limiting your developers to the worst of your team is a quick and easy way to lose your good developers.
  • YAGNI. Solve your actual problem today, not the ghost of some future problem.
Related Topic