Suppose you need to implement a tool to effectively solve an NP-hard problem, with the inevitable possible explosion of memory usage (the output size in some cases is exponential to the size of the input), and you are especially concerned about the actions of this tool during operation. The source code must also be readable and understandable after the known theory is known, and this requirement is as important as the effectiveness of the tool itself.
I personally believe that 3 languages can be suitable for these three requirements: C ++, scala, java. All of them provide the correct abstraction by data types, which allows you to compare different structures or apply the same algorithms (which is also important) to different data types.
C ++ has the advantage that it is statically compiled and optimized, as well as with the inlining function (if the data structures and algorithms are carefully designed) and other optimization methods can achieve performance close to that of pure C, while maintaining pretty good readability. If you also pay a lot of attention to the presentation of data, you can optimize the cache performance, which can gain orders of magnitude in speed when the cache skip speed is low.
Java is compiled instead of JIT, which allows optimization at runtime, and in this category of algorithms, which can have different types of behavior between different runs, which can be a plus. Instead, I fear that this approach may suffer from the garbage collector, however, in the case of this algorithm, it is common for constant memory allocation, and the performance of the java heap is better than C / C ++, and if you implement your own manager memory inside the language, even achieve good efficiency. Instead, this approach is not capable of embedding a method call (which causes a huge performance hit) and does not give you control over cache performance. Among the pros, there is a better and cleaner syntax than C ++.
My problems with scala are more or less similar to Java, as well as the fact that I can’t control how the language is optimized if I don’t have deep knowledge of the compiler and the standard library. But good: I get very clean syntax :)
How do you feel about this issue? Have you had to deal with this? Could you implement an algorithm with such properties and requirements in any of these languages, or would you suggest something else? How would you compare them?