StaticArrays and allocations

But, I think the point made was that sometimes you want neither, you want the whole object to be optimized away. Is that also convenient to achieve in C/C++?

I think that’s only possible for stack-allocated objects in C++, where a compiler might optimize it that way. But heap-allocated ones are (probably) always present explicitly in memory. Plus, in C++ I don’t think I ever explicitly want “the whole object to be optimized away”. It’s simply not a choice I can really influence, so I don’t have to worry about it.

I’m kinda not understanding how that’s a counter argument :thinking: You can’t have it, so that’s good?

I may have missed a part there. You think it could be available?

Well, you made the argument that you wanted a certain optimization, which you can achieve in Julia, yet it comes at a cost of having to understand the how to achieve that. In C++ that optimization isn’t possible so wanting to achieve it doesn’t really apply. Perhaps with some black template magic you might be able to optimize objects away, but for 99.9% of the users I suspect that’s not really of interest to them (and only to those writing the templates, not the ones using them). The core C++ language (i.e. leaving out all the exotic stuff such as concepts, move semantics, funky template meta-programming, etc) is in many ways simpler than Julia due to the less sophisticated type system. So the choices you make as a developer appear to be simpler (but that’s again based on my very limited Julia experience).

Sorry, what does this refer to?

It refers to this sentence:

I missed that at first, and thought you said this could not happen in c++.

I came from Fortran, and in Fortran (at least the one I knew) you don’t have any control over these things. Everything looks as if it was mutable, but the compilers will decide that without the user knowing about what is going on (and sometimes in a compiler-flag dependent way). Coming from Fortran, where every type is declared, one initially feels unsafe for not annotating types, then one makes mistakes and get type instabilities, and finally one gets the way around it and starts using Julia as one should. Not having to annotate every type becomes liberating at the end, not mentioning the fact that functions become generic, thus more useful. And we learn where to focus our attention to get performant code, and where all that obsessive control we had in the other language was counterproductive. At the end, not because of the possibilities of each language in general, but because the easiness of use, explore, test, benchmark, my codes are faster in Julia than what I achieved in Fortran.

10 Likes