Region in Android Studio to organize your code

Hello best team,
hope everyone is doing well here.

I want to open a discussion about Regions Android Studio.
As far as I know all examples in Raywenderlich in iOS projects, to organize the code you are using Pragma Mark.
In Android projects, I can see that the Regions are not used.

I just want to hear your opinion about this part, because in Android projects currently, I’m using the Regions to organize the code.

Example:

Android:

 //region Lifecycle
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)
        Injector.get().inject(this)
        setupAppLoader(parentView, false)
    }
//endregion

iOS:

 //MARK:- Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        loadOfflineData()
        initAppLoader()
    }

Thank you in advance,
Gent

Hey gentberani!

Thanks very much for starting this discussion!

In my experience, using regions in Android code has been more of a headache than it’s worth, especially when working on multi-developer teams. If you can get everyone on your team to follow the same region approach and stick to it, then they can be valuable.

My personal preference has been to try to stick with the approach advocated in Clean Code by Robert C. Martin with respect to keeping files relatively small in terms of lines of code, and also sticking to a particular order of methods in a class. Similar challenges exist with Clean Code in terms of multi-person teams, but I’ve found the principles to be easier to stick with for the teams I’ve been on.

Having said all that, regions might very well make good sense for our Android project code, so we’ll take a shot at using them in some tutorials and courses and see how they’re received.

And like you I’d love to hear more opinions about regions and experiences people have had with them. :]

Thanks again!

This topic was automatically closed after 166 days. New replies are no longer allowed.