Being the owner of a 27" 5K iMac myself I would normally say that you should go for the iMac. However, I assume you are staying in a dormitory of some sort so in that case I would recommend the Macbook Pro. If you are coding, you will need an external monitor for sure. Like another poster said, lugging the iMac around is a bit of a hassle and I would hate to leave something like that in the dorm room. The iPad is perfectly adequate for taking notes in class when paired with a keyboard or Apple Pencil but in your case, the laptop would serve your interests better in my opinion.