Both are very capable CPUs so if you know you use something that uses over 16GB of ram get the 24GB M2.
That said I would say in the vast majority of use cases more than 16GB of memory isn't needed, so more CPU cores and higher memory bandwidth would speed things up a bit.
I went for the M2 Pro with 16GB of RAM!