清理一个大型的遗留Java项目 [英] Cleaning up a large, legacy Java project

查看:246
本文介绍了清理一个大型的遗留Java项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经被派去在一个庞大的Java项目上做一些工作,而开发人员的几次迭代的影响是显而易见的。没有标准的编码风格,格式,命名约定或类结构。这是一个很好的一天,当我遇到一个与Javadoc类,单元测试是一个快乐的白日梦。

到目前为止,我们这个项目的人已经融入 ,适应现有的我们正在工作的任何阶级的约定,但现在是时候来强加一些秩序和一致性。

这是一个艰巨的挑战,寻找任何建议人们可能有这样的任务。是否有任何特别有效的策略,或者是需要注意的陷阱?这是一个好主意吗?



编辑补充:我不想给人留下这个项目不好的印象 - 它实际上设计得很好,写得很好。这只是感觉它的年龄和维护的必然性...

解决方案

我发现Eclipse是一个非常强大的工具,因为这一点。

很多人都为命令行工具和基于模式的文本编辑器发誓要进行编程,但是使用完整的IDE进行重大重构有很多优势: 自动实时编译显示错误发生的时间和地点。仅仅因为你做出了改变,班上没有任何东西或者立即打包,并不意味着你没有在其他地方制造问题。红旗将在eclipse中的包树上直接导向你。

  • 基于图形的重命名和移动。重命名代码的元素可能会比你所知道的要大得多。 Eclipse将向您显示有关元素的每个实例的详细信息,以及如何通过重命名来更改它。

  • 自动导入管理允许您执行该操作在处理确保你所有的进口都是有序的。 Eclipse将在使用时自动添加导入,并将未使用的导入到动作灯泡中,以便一键删除。 使用代码样式确保所有源文件使用相同的格式的一切。空格,缩进,新行,括号都可以为你格式化。这可以在您创建新代码以及更新现有文件时使用。



  • 除了Eclipse的工具集,您还可以利用其他工具现代的Java工具,以确保您的代码始终正常运行。


    • 测试套件使您可以不断确保您所做的任何更改都不会产生负面影响影响项目的功能。如果你要重构一个特性,写两个或三个测试用例来说明它的工作方式。确保它们在更改之前和之后运行。这是在问题发生之前发现问题的最简单方法。

    • 使用诸如Maven之类的工具来辅助依赖性,测试,编译和部署。不要再浪费时间去做任何上述任务了。专注于编写能够完成工作的代码。


    • 我个人更喜欢Eclipse,因为我是重构的人,而不是一些自动化的工具,几乎不知道我的代码。

      I've been assigned to do some work on a huge Java project, and the influence of several iterations of developers is obvious. There is no standard coding style, formatting, naming conventions or class structure. It's a good day when I come across a class with Javadoc, and unit testing is a happy daydream.

      So far those of us on the project have been "blending in", adapting to the existing convention of whatever class we're working on, but the time is coming to impose some order and consistency.

      It's a daunting challenge, and I'm looking for any advice people might have on such a task. Are there any strategies that have been particularly effective, or pitfalls to look out for? Is it even a good idea to try?

      Edit to add: I don't want to give the impression that the project is bad - it is in fact solidly designed and largely well-written. It's just feeling its age and the inevitability of maintenance...

      解决方案

      I find Eclipse to be an incredibly powerful tool for operations such as this.

      A lot of people swear by command-line tools and modal-based text editors for programming but there are strong advantages of using a full IDE for major refactoring:

      • Automatic, real-time compilation shows you errors as they happen and everywhere they happen. Just because you make a change and nothing in the class or immediate package breaks does not mean that you haven't created issues elsewhere. Red flags will go up the package tree in eclipse leading you directly to them.
      • Graphical based renaming and moving. Renaming elements of your code can have an impact much larger than what you know. Eclipse will show you details of every instance of the element in question and how it will be changed by the rename.
      • Automatic import management allows you to take the work out of dealing with ensuring all your imports are in order. Eclipse will automatically add imports as they are used and mark unused ones with action lightbulbs for one-click removal.
      • Use code styles to ensure all of the source files use the same format for everything. Spaces, indents, new lines, parenthesis can all be formatted for you. This works as you create new code as well as for updating existing files.

      In addition to Eclipse's toolset you might look in to utilizing other modern Java tools for ensuring your code is always functioning.

      • Test suites allow you to constantly ensure any changes you make don't have a negative effect on the function of the project. If you are going to be refactoring a feature, write two or three test cases that demonstrate the ways it works. Make sure they run before and after any changes. This is the easiest way to spot problems before they become an issue.
      • Use a tool such as Maven to assist with dependencies, testing, compiling, and deployments. Don't waste time doing any of the aforementioned tasks again. Focus on writing the code that does the work.

      edit:

      I also personally prefer Eclipse because I am the one doing the refactoring, not some automated tool that knows next to nothing about my code.

      这篇关于清理一个大型的遗留Java项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆