Bazel’s build style guide explains most of what needs to be said about how targets should be named. However, I do have an opinion that I feel strongly about.

Don’t repeat yourself (DRY)

It’s kinda funny that we keep trying to apply the DRY principle to every corner of software engineering, but I digress. Anyway, my take is that we should treat package names as namespaces, which means avoiding repeating the package name in target names. Bazel already gives us this namespace through its label syntax: //package:target. The package path provides context, so there’s usually no reason to repeat that context in the target name. Very often, I notice people and AI agents repeating the package name in the target name. For example:

WRONG: //ios/app:app_library
Correct: //ios/app:library

A well-organized app package, in my opinion, looks something like this:

//ios/app # ios_application
//ios/app:library # swift_library / objc_library
//ios/app:resources # apple_resource_bundle
//ios/app:xcarchive # xcarchive
...

The nice thing about this convention is that //ios/app:app can be shortened to //ios/app, since Bazel allows you to omit the target name when it matches the last component of the package path. Of course, more descriptive names or prefixes are sometimes necessary, especially when a package contains multiple targets of the same kind. But to me, if you reach the point where you need to prefix every target with additional context just to distinguish them, it’s probably a sign that the package should be split into smaller ones. The goal isn’t to make every target name as short as possible. It’s to avoid redundant information.

Conclusion

In today’s AI-driven world, one might think that naming conventions don’t matter as much anymore. However, I believe they still do. Consistent, predictable target names make it easier to build tools that automate the maintenance of BUILD files and write Bazel queries by hand.