有几种方法可以避免意大利面条代码? [英] Is there a way to avoid spaghetti code over the years?

查看:216
本文介绍了有几种方法可以避免意大利面条代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个编程工作。每个人有20-50个开发人员,项目进行3 - 5年。

I've had several programming jobs. Each one with 20-50 developers, project going on for 3-5 years.

每次都一样。有些程序员是明亮的,有些是平均水平的。每个人都有自己的CS学位,每个人都读设计模式。意图是好的,人们正在努力编写良好的代码,但仍然在几年后的代码变成意大利面条。模块A中的更改突然中断了模块B.除了写它的人之外,总是有这些部分的代码没有人能够理解。改变基础架构是不可能的,向后兼容性问题阻止了良好的功能进入。一半的时间,你只是想从头开始重写所有。

Every time it's the same. Some programmers are bright, some are average. Everyone has their CS degree, everyone read design patterns. Intentions are good, people are trying hard to write good code but still after a couple of years the code turns into spaghetti. Changes in module A suddenly break module B. There are always these parts of code that no one can understand except for the person who wrote it. Changing infrastructure is impossible and backwards compatibility issues prevent good features to get in. Half of the time you just want to rewrite everything from scratch.

这是正常的。是吗?它必须是?我可以做什么来避免这种情况,还是应该接受它作为一个生活的事实?

And people more experienced than me treat this as normal. Is it? Does it have to be? What can I do to avoid this or should I accept it as a fact of life?

编辑:伙计,我印象深刻的答复的数量和质量在这里。这个网站及其社区摇滚!

Guys, I am impressed with the amount and quality of responses here. This site and its community rock!

推荐答案

无情的勤奋与常量单元测试是防止意大利面条代码的唯一方法。即使那样,它只是一个救援解决方案。

Ruthless diligence combined with constant unit testing is the only way to prevent spaghetti code. Even then it's only a band-aid solution. As soon as you stop paying attention out comes the pasta.

很多时候,我发现意大利面条代码是因为有人只是平淡无奇的那一天。他们知道有一个更好的方法来做,只是没有时间。

Very often I find that spaghetti code is introduced because someone is just plain being lazy that day. They know there is a better way to do it and just don't have the time. When you see that happen there is only one thing to do.

调用它并要求他们更改

我发现在代码审查期间指出更好的方法通常足以让人们去。如果他们检查它,我感觉强烈,我会重构它自己。

I find that pointing out the better way during a code review is usually enough to get people going. If they check it in and I feel strongly, I'll refactor it myself.

我偶尔会有点离奇?我肯定我做。坦率地说,虽然我不介意。我不是一个混蛋,并以最好的社会方式接近。但是让错误的代码检查在很大程度上保证,我将不得不在未来的某个时间调试它。我现在宁愿采取一点小剥离,并得到正确的代码。

Do I occasionally come off as a little bit eccentric? I'm sure I do. Frankly though I don't mind. I'm not a jerk about it and approach this in the best possible social manner. However letting bad code get checked in pretty much assures that I am going to have to debug it at some point in the future. I'd rather take a little flak now and get the right code in.

我也觉得单元测试的文化也有助于防止意大利面条代码。单元测试意大利面条代码要好得多。随着时间的推移,这迫使人们保持他们的代码有些因素。

I also feel that a culture of unit testing also helps prevent spaghetti code. It's much harder to unit test spaghetti code that well factored code. Over time this forces people to keep their code somewhat factored.

这篇关于有几种方法可以避免意大利面条代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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