Yes, this is a common pattern with my projects as well. ABR: Always Be Refactoring. When I feel a new pattern emerge, I try to update older code to match it as well. As a project grows, your experience working in the problem domain influences your style and it's a good idea to be updating older code to match it as well.
As a corollary, if your first project commit is still in your project unchanged a few months later, something is going wrong. I view development as an exploratory practice, and a big part of that is updating old code and ironing out your style. No one knows their final design/API before they start coding. Find any large open source project and walk up its commit history; it happens everywhere.
If you've been working on a drawing or a painting for a while, your style develops sophistication the longer you do it. Also, your first layer or first few sketches are rarely the inked lines that appear in the final result.
A big takeaway lesson from this experience: you're getting better. Or, at least, you're changing. Certainly, from today's perspective, the code you're writing today looks better to you. If the code you wrote back then looks bad today - make it look better. Your responsibility today is not just the code you write today; it is the entire code base. So make it right - and be glad you're getting better.
Yes, this happens. I would even say that it's expected and typical as you delve further into your solution.
Only update your code when you go back and touch it. Don't forget to write unit tests before adjusting it.
It's very tempting to rewrite bad code for no reason, particularly when you don't have a deadline looming. You can easily get stuck in a loop that way.
Is this a common situation, even in large commercial-style projects?
I must confess here that my belief is that if you design first and code later you can avoid many issues. So I would say here it depends. If one starts with a good design has some company standards in place to ensure the code based on the design follows the same important rules no matter who wrote it then at least you have a chance to avoid such situations. However I am not sure if this is always the case :-).
Should I consider investing (a lot of) time in re-factoring and maybe even rewriting the affected code?
Making things better can never hurt :-).
Is it normal that as a project grows and changes, large parts of code have to be re-factored or rewritten from ground up? Is this bad?
I would say yes and re-factoring should be normally considered to be a good thing when the resulting code is better than the old one. The world never stays the same and even if something was appropriate at some point in time it just may be that it doesn't stand up to the needs of today. So I would say it would be bad if the company you work for would say to you: "you cannot re-factor this code. It's holy". Change (if it is for the better) is always good.
Fred Brooks wrote, "Build one to throw away, you will anyway." While it's not as true as it used to be, it is far from uncommon to not really understand the problem until you start working on it.
发布评论
评论(6)
即使在大型商业项目中,这种情况也很常见吗?
是的。
我是否应该考虑投入(大量)时间进行重构,甚至重写受影响的代码?
您明天也会再次这样做吗?
不。除非您实际上正在处理要重构的代码。
随着项目的发展和变化,大部分代码必须从头开始重构或重写,这正常吗?
是的。
这很糟糕吗?
如果我们都完美的话,事情肯定会容易得多,是的。
Is this a common situation, even in large commercial-style projects?
Yes.
Should I consider investing (a lot of) time in refactoring and maybe even rewriting the affected code?
You going to do that again tomorrow too?
No. Not unless you're actually working on the code you want to refactor.
Is it normal that as a project grows and changes, large parts of code have to be refactored or rewritten from ground up?
Yes.
Is this bad?
It would certainly be a lot easier if we where all perfect, yes.
是的,这也是我的项目的常见模式。 ABR:始终进行重构。当我感觉到新模式出现时,我会尝试更新旧代码以匹配它。随着项目的发展,您在问题领域的工作经验会影响您的风格,并且更新旧代码以匹配它也是一个好主意。
作为推论,如果几个月后您的第一个项目提交在项目中仍然保持不变,则说明出现了问题。我将开发视为一种探索性实践,其中很大一部分是更新旧代码并完善你的风格。在开始编码之前,没有人知道他们的最终设计/API。查找任何大型开源项目并查看其提交历史记录;这种事到处都有发生。
如果你已经画了一段时间的图画或绘画,你画的时间越长,你的风格就会变得越复杂。此外,您的第一层或前几张草图很少是最终结果中出现的墨线。
Yes, this is a common pattern with my projects as well. ABR: Always Be Refactoring. When I feel a new pattern emerge, I try to update older code to match it as well. As a project grows, your experience working in the problem domain influences your style and it's a good idea to be updating older code to match it as well.
As a corollary, if your first project commit is still in your project unchanged a few months later, something is going wrong. I view development as an exploratory practice, and a big part of that is updating old code and ironing out your style. No one knows their final design/API before they start coding. Find any large open source project and walk up its commit history; it happens everywhere.
If you've been working on a drawing or a painting for a while, your style develops sophistication the longer you do it. Also, your first layer or first few sketches are rarely the inked lines that appear in the final result.
从这次经历中得到的一个重要教训是:你正在变得更好。或者,至少,你正在改变。当然,从今天的角度来看,您今天编写的代码看起来更好。如果你当时写的代码今天看起来很糟糕 - 让它看起来更好。你今天的责任不仅仅是你今天编写的代码;它是整个代码库。所以改正吧——并为自己的进步而感到高兴。
A big takeaway lesson from this experience: you're getting better. Or, at least, you're changing. Certainly, from today's perspective, the code you're writing today looks better to you. If the code you wrote back then looks bad today - make it look better. Your responsibility today is not just the code you write today; it is the entire code base. So make it right - and be glad you're getting better.
是的,这种情况发生了。我什至会说,当您进一步深入研究解决方案时,这是预期的和典型的。
仅当您返回并触摸它时才更新您的代码。在调整之前不要忘记编写单元测试。
无缘无故地重写糟糕的代码是非常诱人的,特别是当你没有迫在眉睫的最后期限时。这样你很容易陷入循环。
请记住,运输是一项功能。
Yes, this happens. I would even say that it's expected and typical as you delve further into your solution.
Only update your code when you go back and touch it. Don't forget to write unit tests before adjusting it.
It's very tempting to rewrite bad code for no reason, particularly when you don't have a deadline looming. You can easily get stuck in a loop that way.
Remember, shipping is a feature.
即使在大型商业项目中,这种情况是否很常见?
我必须在这里承认,我的信念是,如果你先设计,然后编码,你可以避免很多问题。所以我想说这要看情况。如果一个人从一个好的设计开始,并制定了一些公司标准,以确保基于该设计的代码遵循相同的重要规则,无论是谁编写的,那么至少您有机会避免这种情况。但我不确定情况是否总是如此:-)。
我是否应该考虑投入(大量)时间进行重构,甚至重写受影响的代码?
让事情变得更好永远不会有坏处:-)。
随着项目的发展和变化,大部分代码必须从头开始重构或重写,这是否正常?这很糟糕吗?
我想说是的,当生成的代码比旧代码更好时,重构通常应该被认为是一件好事。世界永远不会保持不变,即使某些东西在某个时间点是合适的,也可能无法满足今天的需求。所以我想说,如果你工作的公司对你说:“你不能重构这段代码。它是神圣的”,那就糟糕了。改变(如果是为了更好的话)总是好的。
Is this a common situation, even in large commercial-style projects?
I must confess here that my belief is that if you design first and code later you can avoid many issues. So I would say here it depends. If one starts with a good design has some company standards in place to ensure the code based on the design follows the same important rules no matter who wrote it then at least you have a chance to avoid such situations. However I am not sure if this is always the case :-).
Should I consider investing (a lot of) time in re-factoring and maybe even rewriting the affected code?
Making things better can never hurt :-).
Is it normal that as a project grows and changes, large parts of code have to be re-factored or rewritten from ground up? Is this bad?
I would say yes and re-factoring should be normally considered to be a good thing when the resulting code is better than the old one. The world never stays the same and even if something was appropriate at some point in time it just may be that it doesn't stand up to the needs of today. So I would say it would be bad if the company you work for would say to you: "you cannot re-factor this code. It's holy". Change (if it is for the better) is always good.
弗雷德·布鲁克斯 (Fred Brooks) 写道:“造一个然后扔掉,无论如何你都会这么做。”虽然情况不像以前那么真实,但在开始解决问题之前不真正理解问题的情况并不罕见。
Fred Brooks wrote, "Build one to throw away, you will anyway." While it's not as true as it used to be, it is far from uncommon to not really understand the problem until you start working on it.