코드의 "복사 및 붙여 넣기"가 위험한 이유는 무엇입니까? [닫은]
때로는 상사가 우리에게 불평 할 것입니다.
기능을 구현하는 데 오랜 시간이 필요한 이유는 무엇입니까?
실제로이 기능은 이전에 다른 응용 프로그램에서 구현되었으므로 코드를 복사하여 붙여 넣기 만하면됩니다. 비용이 낮아야합니다.
복사 및 붙여 넣기 코드는 제 관점에서 그렇게 간단한 것이 아니기 때문에 실제로 어려운 질문입니다.
비 기술적 인 상사에게 이것을 설명 할만한 충분한 이유가 있습니까?
복사-붙여 넣기 코드에서 버그를 발견 한 경우 모든 위치에서 문제를 해결하고 모든 사항을 기억할 수 있기를 바랍니다 (변경된 요구 사항에도 해당).
한 곳에서 논리를 유지하면 필요할 때 변경하는 것이 더 쉽습니다 (따라서 응용 프로그램을 업데이트해야한다고 결정한 경우 한 곳에서만 수행).
상사에게 DRY 원칙 에 대해 읽게하십시오 (반복하지 마십시오).
당신이 설명하는 것은 라이브러리를 완벽하게 사용하는 것처럼 들립니다. 라이브러리 에서 코드를 공유하고 한 곳에만 보관하십시오.
나중에 코드를 리팩터링 하려는 경우에만 코드를 복사하여 붙여 넣을 수 있습니다. 나중에 추출 된 공통 코드를 사용하여 최대한 많은 논리를 재사용 할 수 있는지 확인하십시오. 그리고 머지 않아 몇 분이지나 몇 일이 아니라 몇 주가 지났습니다.
복사 및 붙여 넣기를 사용하여 코드를 복사 하는 대신 라이브러리를 작성하여 코드를 공유 하는 것이 훨씬 좋습니다 .
여전히 재 작성보다 속도 이점을 얻을 수 있지만 (DRY 조회) 코드를 유지할 수있는 곳은 한 곳뿐입니다.
분명한 이유는 미래에 대한 '채무'를 취하기 때문입니다. 코드에서 변경해야 할 변경 사항 (버그 수정뿐만 아니라 변경 사항)도 두 곳을 업데이트해야하기 때문에 비용이 두 배나 비쌉니다. 결국에는 그중 하나를 잊어 버리기 때문에 더욱 위험합니다. 다시 말해, 지금 작업 속도를 높이면 향후 작업 속도가 더 느려질 수 있습니다. 이는 비즈니스에 적합하지만 일반적으로는 그렇지 않습니다.
그러나 더 중요한 이유는 "이것과 같다"라는 가정이 미묘하게 잘못되지 않는 것보다 더 자주 있기 때문입니다. 코드가 무언의 가정에 의존 할 때마다, 다른 가정으로 코드를 복사하면 이러한 가정이 새로운 위치에 있지 않으면 오류가 발생합니다. 따라서 붙여 넣은 코드는 종종 다음 변경 이후가 아니라 처음부터 잘못되었습니다.
디자인 방식으로 복사하여 붙여 넣은 코드는 확실히 재앙이며 앞으로 많은 문제가 발생할 수 있습니다. 그것은 당신에게 많은 일을 소요하지만 왜 당신이 요구하는지 지금 , 대답은 : 그것은 결코 바로 복사하지 않고 붙여 있기 때문에.
유연성과 클라이언트 사용을 염두에두고 상당히 독립적 인 라이브러리로 재사용하기 위해 원래 코드를 작성했다면 훌륭하지만 복사 붙여 넣기는 아니지만 코드 라이브러리를 사용합니다. 실제 코드 복사 붙여 넣기는 일반적으로 다음과 같습니다.
- "물론, 이미 정확히 그렇게하는 코드가 있습니다!"
- "잠깐,이 5 가지 버전의 코드 중 어느 것이 내 소스로 사용하고 싶은가?"
- "흠,이 모든 'util_func_023'기능은 무엇을합니까? 문서화하지 않았습니까? 지금 어떤 기능이 필요합니까?"
- "오, 예,이 코드는 코드베이스 Y를 사용 합니다. 하나를 선택 해야 합니다. 하나를 선택하십시오. 모든 코드베이스 Y를 새 프로젝트에 복사하거나 코드베이스 Y에서 원하는 기능을 익히고 하루를 보내십시오. 코드베이스 Y에서 원하는 기능 하나] "
- "저는 모든 것을 복사했습니다!"
- "왜 작동하지 않습니까?"
- 이것은 실제로 시작하려는 코드를 작성하는 대신 원하는 코드와 유사한 기존 코드를 디버깅하는 데 시간 / 일 / 주를 소비하는 지점입니다.
요약하자면, 직접 사용할 수없는 기존 코드는 기껏해야 유사한 코드를 작성하기위한 훌륭한 참조 자료가 될 수 있습니다. 확실히 전체를 들어 올릴 수 없으며 완전히 다른 시스템에서 작동 할 것으로 예상됩니다. 일반적으로 작성되고 완성 된 코드는 원본 자체가 아니라 사본 인 경우에도 가능한 한 많이 엉망으로 만들어야한다는 안전한 가정입니다.
당신이 복사 붙여 넣기에 프로젝트를 기반으로하고 싶은 경우에, 당신은 코드에있어 시작하기 쉬운 재사용을 가능하게하는 방식으로 하지 않고 원래의 코드를 복사하고 그것으로 장난. 그럴만 한 가치가 있으며, 그것이 상사가 기대하는 것이라면, 둘 다 그것이 처음부터 디자인하고 작업하는 방식인지 확인해야합니다.
복사 및 붙여 넣기는 재난이 발생하기를 기다리는 재난입니다. 상사는 최종 사용자에게 배송 된 코드가 깨지는 가격과 관련하여 배송 가격을 조기에 평가해야합니다.
이미 기능을 구현했으며 재사용하기 위해 복사하여 붙여 넣기를 해야하는 경우, 무언가 잘못한 것 같습니다. 이러한 기능을 라이브러리에 넣을 수 없으므로 복사 / 붙여 넣기없이 재사용 할 수 있습니까?
DRY 원칙 (반복하지 말 것) : Wikipedia에서 DRY .
"모든 지식은 시스템 내에서 하나의 명백하고 권위있는 표현을 가져야합니다."
다른 링크 .
그것은 당신의 비 기술적 인 상사가 가지고있는 최악의 오해처럼 들립니다. 당신의 직업이 주로 타이핑하고 있다는 것입니다. 그들은 타이핑을 제거함으로써 많은 시간을 절약 할 수 있다고 생각합니다.
이 사람에게 줄 수있는 최고의 교육은 입력하지 않은 모든 작업을 지적하는 것입니다. 대부분의 작업은 입력과 동시에 머리에서 보이지 않게 발생합니다.
물론 타이핑을 제거하면 시간이 절약됩니다. 그러나 훨씬 더 크고 타이핑이 아닌 작업의 일부는 더 커지고 시간을 절약하고 더 많이 먹습니다.
상사가 DRY 원리, 버그 및 기타 기술에 대해 듣고 싶습니까?
상사 나 회사가 프로젝트를 완료하는 데 필요한 시간을 과소 평가했을 때 일반적으로 들리는 이러한 의견. 그리고 잘못된 추정에 근거하여 계약서 등에 서명했습니다. 대부분의 경우 프로그래머는 추정에 관여하지 않았습니다.
왜 이런 일이 발생합니까? 때로는 프로젝트 스폰서의 예산이 너무 적습니다. 소프트웨어를 사용하여 자동화하는 비즈니스 프로세스가 팀의 노력에 가치가 없을 수도 있습니다. 이러한 경우 관리자는 일반적으로 나쁜 소식으로 인해 매우 폐쇄되는 경향이 있습니다. 프로젝트가 시작될 때 희망적인 생각이 있습니다. 그런 다음 관리자는 프로그래머를 비난합니다. 귀하의 경우에는 복사하여 붙여 넣기를 통해 간접적으로. 극단적 인 경우이를 사망 행진 이라고 합니다 .
코드 복사 및 붙여 넣기는 대개 우연의 일치 로 프로그래밍됩니다.
I think "another application" is key here, if the other application is already tested and in use, it should not be changed to use a common library, therefore you can’t share code with it.
Within the same application, “copy and paste” is bad, but between code bases that are developed by different teams or with different release cycles “copy and paste” can be the best option.
I worked for a similar company. Being a trainee, I didn't know better then, so when I started a new project, my boss also suggested to paste the code from somewhere else. Well, as you may think, the whole software was quite a mess, up to the point that when you tried to fix a bug, two new bugs appeared.
Even if the other application already has the feature you need, the code for that feature might simply not fit into your current application without a major rewrite. It's like taking the motor of a Ford and trying to fit it into a Toyota. Generally, there is a rule of thumb that if you have to modify more than 25% of the code you copy, it's better (cheaper) to rewrite it from scratch.
Extracting the code in question into a library sound compelling, but it might be more difficult than it sounds, depending on how that other system is built. E.g. the code for that feature might be hard to extract because it interfaces a lot of other code in unclean ways (e.g. by accessing lots of global variables etc.)
Tell your boss that the part of the each and every variable name includes the name of the old project and now you have to change them all, manually. If your boss doesn't know (or wants to know) why copy/paste is bad he/she might as well believe that :)
There are trade-offs between speed of development of the immediate functionality in front of you (especially when the application is small), and longer term maintenance costs as the application grows.
Copy and paste is quicker for the immediate functionality, but will costs you dearly as the application grows in size, in terms of fixing bugs and making system wide changes and maintaining workflows between different components of the application.
That is the argument that business owners need to hear. It is similar to the accepted costs of maintaining a fleet of vehicles, however, with software, the broken aspects of the software architecture are generally hidden to the business side, and can only be seen by developers.
He's right that if the team has implemented similar functionality before, repeating it will be much easier the 2nd time.
However, you should probably explain that each application is different. Just because you installed a door in one house doesn't mean you can install another door in another house in no time flat - you will be faster because of the experience (# doors installed), but it will still take time to get you equipment, mount the door, make sure it is plumb, and screw it into the frame.
Yeah, the biggest problem is that it isn't just copy and paste - its copy then paste then slightly modify.
Then later on when one of the pasted variants has a problem, it gets changed. Then later on, another variant gets changed.
Then, you find out that all the variants have to change cause the original copy had bugs. Now you are well and truly screwed because all the pasted areas are now not the same.
And wouldn't you know it, this kind of crappy coding is usually almost entirely void of comments.
To me, the difference is that when you have multiple copies of code doing the same thing, what you have is a bunch of code. When you only have one piece of code doing each particular thing, then you have a system.
Behaviors of a system can be changed with single point modifications quite easily - changing the behavior of a bunch of code requires a bunch of code.
I like systems, not a bunch of code.
in my company, we always work with classes and methods, and make technical documentation for them. I think its the best practice if u can use your own svn search aplications with good keys to find method class used before :)
참고URL : https://stackoverflow.com/questions/2490884/why-is-copy-and-paste-of-code-dangerous
'Programing' 카테고리의 다른 글
사용자가 브라우저 기록으로 돌아갈 수 있는지 확인하는 방법 (0) | 2020.07.02 |
---|---|
문자열에서 모든 공백을 제거하는 방법은 무엇입니까? (0) | 2020.07.02 |
왜이 C ++ 스 니펫 컴파일 (비 공백 함수가 값을 반환하지 않음) (0) | 2020.07.02 |
문자열에 배열의 문자열이 포함되어 있는지 테스트 (0) | 2020.07.02 |
@ManyToOne 속성에는 @Column이 허용되지 않습니다. (0) | 2020.07.02 |