As said above, yes the E36 M42 is a newer design, it could be discussed if its better or not...
I think is just design with another purpose than the E30, period. That´s just my thinking.
About the swap, well not so straight... The M40 and M42 engine (both E30 and E36) share the exact same block, so yes the gearbox bolts right up to it.
But to fit an E36 engine into an E30 you WILL need to mount the E30 complete intake system, E30 oil pan (upper and lower, and dipstick, the M40 shares the same oil pan and dipstick as the M42), and complete E30 engine wiring harness. Depending on what year the engine is, if it comes with serpentine belt system, put the E30 pulleys, belts and all related to it, if you don´t want to mess up with the dipstick position.
You could also convert your M40 block to M42,as the crank is the same as well, but a lot of work involved...
Do a search on this forum about the things that need to be swapped from E36 to E30, it´s been discussed a few times.
Good luck!