Páginas

Monday, March 20, 2017

Indentation styles

pro-tip for indentation style

Style 1: bad

        docker_or_rpm_images.update(self.qualified_docker_images(self.image_from_base_name(image_base_name),
                                                                 "v" + openshift_image_tag))
Suppose during a refactor we rename docker_or_rpm_images -> images, result:
        images.update(self.qualified_docker_images(self.image_from_base_name(image_base_name),
                                                                 "v" + openshift_image_tag))
Bad indentation... this style is painful to maintain.

Style 2: better

        docker_or_rpm_images.update(
            self.qualified_docker_images(self.image_from_base_name(image_base_name), "v" + openshift_image_tag))
Suppose during a refactor we rename docker_or_rpm_images -> images, result:
        images.update(
            self.qualified_docker_images(self.image_from_base_name(image_base_name), "v" + openshift_image_tag))
We still have a long and apparently complicated line, but this time the indentation stays consistent, no need to update adjacent lines to the one that was automatically changed with the rename.
For more details:

(post content extracted from a PR I was reviewing recently)

No comments: