Is it more optimal to use a collider to prevent players from leaving screen ?

Is it more optimal to use a collider to prevent players from leaving screen ?
I have seen some tuts coding the numbered location that the player cannot exit screen and doing this all in code…

so is it better to use colliders to stop them from leaving screen or coding it?
and please explain whats the difference pros and cons of each

Thanks

It is difficult to determine which one is the best. Both are acceptable. The only things that may affect your choice is your purposes and preferences. For example, I have a game that have a circular gameplay. Camera rotates around specific point only. The player is on the screen. I could use colliders (I actually did this at the beginning, but there was a bag), but for me it is much easier to use code to keep the player where I want. Also, somebody likes that everything might be changed in code, but others like to use editor staff (so, using colliders). Of course, you should avoid some complex colliders due to performance. However, using a few standard colliders to keep the player within the screen is completely fine.