Keep the Build Clean

Keep the Build Clean

Johannes Brodwall

HAVE YOU EVER LOOKED AT a list of compiler warnings the length of an essay on bad coding and thought to yourself, “You know, I really should do something about that…but I don’t have time just now”? On the other hand, have you ever looked at a lone warning that appeared in a compilation and just fixed it?

When I start a new project from scratch, there are no warnings, no clutter, no problems. But as the codebase grows, if I don’t pay attention, the clutter, the cruft, the warnings, and the problems can start piling up. When there’s a lot of noise, it’s much harder to find the warning that I really want to read among the hundreds of warnings I don’t care about.

To make warnings useful again, I try to use a zero-tolerance policy for warn- ings from the build. Even if the warning isn’t important, I deal with it. If it’s not critical but still relevant, I fix it. If the compiler warns about a potential null-pointer exception, I fix the cause—even if I “know” the problem will never show up in production. If the embedded documentation (Javadoc or similar) refers to parameters that have been removed or renamed, I clean up the documentation.

If it’s something I really don’t care about and that really doesn’t matter, I ask the team if we can change our warning policy. For example, I find that documenting

??84 97 Things Every Programmer Should Know

?

???????????????the parameters and return value of a method in many cases doesn’t add any value, so it shouldn’t be a warning if they are missing. Or, upgrading to a new version of the programming language may make code that was previously OK now emit warnings. For example, when Java 5 introduced generics, all the old code that didn’t specify the generic type parameter would give a warning. This is a sort of warning I don’t want to be nagged about (at least, not yet). Having a set of warnings that are out of step with reality does not serve anyone.

By making sure that the build is always clean, I will not have to decide that a warning is irrelevant every time I encounter it. Ignoring things is mental work, and I need to get rid of all the unnecessary mental work I can. Having a clean build also makes it easier for someone else to take over my work. If I leave the warnings, someone else will have to wade through what is relevant and what is not. Or more likely, that person will just ignore all the warnings, including the significant ones.

Warnings from your build are useful. You just need to get rid of the noise to start noticing them. Don’t wait for a big cleanup. When something appears that you don’t want to see, deal with it right away. You should fix the source of the warning, suppress the warning, or fix the warning policies of your tool. Keep- ing the build clean is not just about keeping it free of compilation errors or test failures: warnings are also an important and critical part of code hygiene.

时间: 2024-11-10 01:31:51

Keep the Build Clean的相关文章

[Grunt] Cleaning your build folder with grunt-contrib-clean

Grunt will clean up your build with the grunt-contrib-clean to make sure that no artifacts from previous builds are hanging around. Install: npm install grunt-contrib-clean --save-dev Example: clean: { build: 'build' //clean the build directory } Use

ANT编译build.xml

一,体验ant就像每个语言都有HelloWorld一样,一个最简单的应用能让人感受一下Ant1,首先你要知道你要干什么,我现在想做的事情是:编写一些程序编译它们把它打包成jar包把他们放在应该放置的地方运行它们这里为了简单起见只写一个程序,就是HelloWorld.java程序代码如下:package test.ant;public class HelloWorld{public static void main(String[] args){   System.out.println("Hel

Tomcat默认ROOT.build.xml之ant学习

Tomcat的编译打包采用了传统的ant编译,相对于c里面的makefile文件,ant采用build.xml文件来制定编译规则. 先来尝试看看简单的ROOT工程里的编译规则. <?xml version="1.0" encoding="UTF-8"?> <!--   Licensed to the Apache Software Foundation (ASF) under one or more   contributor license ag

公司拷贝回家的工程用sts导入clean package报错java.lang.NoClassDefFoundError

从公司拷贝工程回家加班,用相同版本的sts和jdk但是run as    maven build   clean package 总是报错java.lang.NoClassDefFoundError:com/fasterxml/jackson/databind/ObjectMapper 等等很多NoClassDefFoundError等等错误,但是我在公司相同的代码相同的工程一点问题没有 后来猜测可能家里电脑maven下载相关的包是很久之前下载的,公司是最近半个月下载的,于是删除了C:\User

windows上使用mkdocs搭建静态博客

windows上使用mkdocs搭建静态博客 之前尝试过用HEXO搭建静态博客,最近发现有个叫mkdocs的开源项目也是搭建静态博客的好选择,而且它支持markdown格式,下面简要介绍一下mkdocs的环境搭建过程 项目地址:https://github.com/mkdocs/mkdocs 介绍:英文版----http://www.mkdocs.org/ 中文版----http://markdown-docs-zh.readthedocs.io/zh_CN/latest/ 使用环境:win8.

Gulp新手入门教程

Gulp 是一个自动化工具,前端开发者可以使用它来处理常见任务: 搭建web服务器 文件保存时自动重载浏览器 使用预处理器如Sass.LESS 优化资源,比如压缩CSS.JavaScript.压缩图片 当然Gulp能做的远不止这些.如果你够疯狂,你甚至可以使用它搭建一个静态页面生成器.Gulp真的足够强大,但你必须学会驾驭它. 这是这篇文章的主要目的.帮助你了解Gulp的基础用法,助你早日完成一统天下的大业. 在我们深入了解之前,我们先来说说为什么是Gulp. 为什么是Gulp? 类似Gulp的

maven的配置和使用

Maven 简介 1.1 Maven 是什么 翻译为"专家","内行" Maven是跨平台的项目管理工具.主要服务于基于Java平台的项目构建,依赖管理和项目信息管理. 1.2 为什么使用Maven IDE?Eclipse? 手工操作较多,编译.测试.部署等工作都是独立的,很难一步完成 每个人的IDE配置都不同,很容易出现本地代码换个地方编译就出错 Ant? 没有一个约定的目录结构 必须明确让ant做什么,什么时候做,然后编译,打包 没有生命周期,必须定义目标及其实

Eclipse搭建Maven项目并上传SVN备份

近段时间在学着Java,想着用Java做BS的项目.但是项目一遇到问题又要重做,故想起了用SVN做备份. 我的电脑是windows的64位系统: 一.建项目的总体思路是: 前期: a.安装JDK,配置JAVA环境变量(Eclipse基于JAVA环境,所以必须安装JDK) 从Oracle官网下载适合系统的JDK:http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk 安装并配置J

ADT

1.什么是antant是构建工具2.什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3.ant的好处跨平台   --因为ant是使用java实现的,所以它跨平台使用简单--与ant的兄弟make比起来语法清晰--同样是和make相比功能强大--ant能做的事情很多,可能你用了很久,你仍然不知道它能有多少功能.当你自己开发一些ant插件的时候,你会发现它更多的功能.4.ant的兄弟makeant做的很多事情,大部分是曾