I think N+1 problem in real applications are more than just a coding experience problem. N+1 problems frequently arise because of separation of concerns where the code doing the looping, and the code making the sub-queries are significantly separated from each other. In that case preventing the N+1 is not obvious, and fixing it can be very complex, and result in messy code.
In languages with strong meta-programming, like Ruby, it is possible to deal with N+1s more automatically, which allows you to prevent them systematically, and most importantly have an elegant solution to N+1s that span independent blocks of code.
A couple of articles about these techniques: https://www.aha.io/engineering/articles/90-percent-of-rails-... https://www.aha.io/engineering/articles/automatically-avoidi...