Possible duplicate:
Concrete functions against many arguments and context dependent
So, I’ve been developing for 3-4 years, I know a wide range of languages, I know some impressive ones (for those who have little understanding: P).
But I always wondered; when I make a function, if it will be for a specific purpose, or should it be molded for reuse, even if I do not need to do this?
eg:
//JS, but could be any language really //specific function HAL(){ alert("I'm afraid I can't let you do that, " + document.getElementById("Name").value + "."); } //generic function HAL(nme){ alert("I'm afraid I can't let you do that, " + nme + "."); } //more generic function HAL(msg, nme){ alert(msg + " " + nme + "."); }
Yes, a very simple example, but conveys the point I want to make. If we take this example, would I use it outside the first? Probably not, so I would have a desire to do it this way, but then common sense (now) will convince me to do it second, but I don’t see any benefit from this path if I know it will not be used in any other way , i.e. it will always use the input value (yes, I would put this in a global variable as usual).
Is this just a case of what, in my opinion, was of the greatest importance at that time, or should I follow the 2nd pattern as best as possible?
source share