
Ask HN: C++ or java for machine learning - rezaqqq
i&#x27;m wondering which programming language should i learn for machine learning along with python?
other programming languages would be appreciated
======
PaulHoule
You can get higher performance with C++ if you go wild with SIMD intrinsics
and other advanced features. That is, for low-level coding of algorithms with
the highest speed and memory, C++ beats Java. On the other hand, C++ will bog
you down in details that may drive you insane. You might think you are on top
of it, but you're secretly afraid to make any changes to the algorithm because
it takes 20 minutes to build your code, you might make a mistake calculating
derivatives by hand, etc.

The advantage of Java is in building systems that are distributed. You can
build things like

[http://lmax-exchange.github.io/disruptor/](http://lmax-
exchange.github.io/disruptor/)

and Hadoop. On paper you could write systems like that in C++. In practice you
can get C++ code like that to work most of the time in a controlled
environment with a huge amount of work because you have to deal with entropy
at every layer that Java pumps out for you.

On the other hand, for many kind of algorithms, you can get even better
results using tools like Tensorflow which are intended to compile
automatically for parallel computation, will calculate the derivatives for
you, etc.

Related to that is the classic strategy of linking to "old codes". Even in the
1990s, programming in C and Java in grad school for physics, I never wrote
matrix factorization codes, but just used LAPACK written in Fortran but
enhanced by the hardware vendor (IBM, Intel, ...) to take advantage of
parallel features. This was faster than anything I would write, took less of
my time, and had fewer bugs.

Today you would take advantage of that in python by using numpy and related
tools.

Maybe your best bet is to learn how to use FFI inside out so you can use code
other people wrote from the C universe because there is a lot of it.

------
AnimalMuppet
I don't think you should learn a _language_ for machine learning. Learn
algorithms and techniques.

In particular, C++ and Java aren't different enough from each other that one
is going to have a big edge over the other in machine learning. An algorithm
that can be implemented in one can be implemented in the other, without a
radical difference in code size, development time, or execution speed. Java
may be slightly easier due to the possibility of running off the end of
arrays, and following uninitialized or stale pointers, but you're not supposed
to write C++ that way any longer. It's much easier with C++11/14 style coding.

(There may be differences in availability of useful libraries between C++ and
Java, which may be what you're really asking. I don't know enough to answer
that.)

