开发者

Do you check in new code that doesn't happen to have any immediate application?

开发者 https://www.devze.com 2023-01-24 03:05 出处:网络
In the process of solving a larger problem I wrote a new class method to compute a property of objects of that class.I referred to standards, I found the appropriate internal library calls to do some

In the process of solving a larger problem I wrote a new class method to compute a property of objects of that class. I referred to standards, I found the appropriate internal library calls to do some of the work for me, I commented it fully and I applied it to a variety of sample objects to validate the results.

Later I realized I could solve the larger problem in an entirely different way. I would not need to call my new method at all. The function might be useful for solving some future problem, but if I check it in today it wil开发者_运维知识库l immediately be dead code. What do I do with it? Check it in? Check it in but #ifdef'd out? Check it in and immediately make another commit to remove it? Leave it in a git-stash? Just accept the loss and move on?


If this is your personal developer branch check it in and tag it. Make sure you don't merge it into whichever feature or version branch you are working on. I have a folder that I have an svn:ignore property set that prevents me accidentally adding this kind of stuff back into a main branch.


Don't check in dead code in the production tree. If you think you might have some use for that code some day in the future, check it in to your personal repository.

Anything that is in the product tree has an associated cost - code review, test coverage, design doc, public API description, thread modeling, maintenance, and so on. Paying that cost for code that is not used means you have less to spend on actual features for your users.


This in entirely up to you and (if it applies) the policy in your company.

first I would say it is not a loss and you should always keep it alternated solution somewhere because you'll one day think "hey this looks like that previous problem... dam how did I do it", so if you have a working code keep it.

then I wouldn't advise leaving it #ifdef or leaving it inside working code because when somebody else reads use your code, it will make it harder for them to follow the flow of your program. (at my work we have some projects which are compiled across desktop, DS, PSP etc. and when you have to read the code with multiple #define its hard: There is no need to make it harder :P.

the question of submitting as I mentioned in the beginning depends on your situation. If you are alone on the project why not. if there are other people, then ask yourself if this code could be useful to then or not.

hope it helps

Jason

0

精彩评论

暂无评论...
验证码 换一张
取 消