You can also adjust features (roll up windows with remote, etc). Run diagnostics in real time while driving, test every switch/sensor on the car. Also, it is needed if you do a brake job on the rear brakes to open/close the parking brake so you can put the pads in.
I don't believe you need to recode the battery if you replace with the exact same battery but you need to change it if you don't put in the OEM one [1]
Yeah we don't have the source code. But with long coding adaptations in the system you can do a large portion of what you need to do (engine/trans swaps). If going deeper is needed there are companies who reflash/recode ECUs but that is about as deep as you can go without doing independent module hacking.