I had a similar idea some time ago, that all the code should be write only. That is, you should always write new functions (and give them new names) instead of trying to rewrite them (if the spec changes, this assumes they were correct in the first place). I think it's only really doable in purely functional language (like Haskell), though. It sort of means versioning of individual functions, and also types. It's ver…
Never edit a method, always rewrite it?
21–30 of 120 posts
Re: Never edit a method, always rewrite it?
#22I had a similar idea some time ago, that all the code should be write only. That is, you should always write new functions (and give them new names) instead of trying to rewrite them (if the spec changes, this assumes they were correct in the first place). I think it's only really doable in purely functional language (like Haskell), though. It sort of means versioning of individual functions, and also types. It's ver…
It creates technical debt and someone else will have to clean it up
Re: Never edit a method, always rewrite it?
#23If you make this a strict requirement for your code base people write wrappers all the time, which creates a huge mess:
def newMethod(x):
if x*2 == 42:
return 36
return oldMethod(x)
You cannot enforce the requirement anyway, because people will just copy-paste the code and edit it under a new name.You just cannot push this methodology unto developers.
Re: Never edit a method, always rewrite it?
#24I've been doing something similar. I name the new method Method, rename the old one as MethodOld and in Method, before the return value, I put an assert(MethodOld(args) == return value). It's one of the things that when I do, I appreciate the value of, but I'm not disciplined enough to do as much as I would like to lol.
This prevents cluttering your code with old methods and also allows you to figure out if a new environment breaks your code.
Re: Never edit a method, always rewrite it?
#25Re: Never edit a method, always rewrite it?
#26For our Christmas campaign, calculateCostOfGadget() needs to account for the compounding discount. Preferably yesterday, as we need to complete this month's billing to make payroll.
Re: Never edit a method, always rewrite it?
#27I had a similar idea some time ago, that all the code should be write only. That is, you should always write new functions (and give them new names) instead of trying to rewrite them (if the spec changes, this assumes they were correct in the first place). I think it's only really doable in purely functional language (like Haskell), though. It sort of means versioning of individual functions, and also types. It's ver…
Why? Your revision history is already in version control.
Re: Never edit a method, always rewrite it?
#28Re: Never edit a method, always rewrite it?
#29Devils advocate: If you make this a strict requirement for your code base people write wrappers all the time, which creates a huge mess: def newMethod(x): if x*2 == 42: return 36 return oldMethod(x) You cannot enforce the requirement anyway, because people will just copy-paste the code and edit it under a new name. You just cannot push this methodology unto developers.
Re: Never edit a method, always rewrite it?
#30When writing functions often I end up deciding fairly quickly if the function I am writing is intended to be reusable or not. If it is reusable I'll write it as a utility function, helper, lib, ... whatever the project's convention and language paradigm might be. Usually similar reusable functions already exist within the project. A significant portion of functions fall in another category; functions that actually ge…
It's debatable if it actually helps with that intention.