4 ms·
That's a fair point on the lack of support for strings by sum, but note this is only because the function is hard-coded explicitly to reject them and only becau
by clusmore 10y ago
That's a fair point on the lack of support for strings by sum, but note this is only because the function is hard-coded explicitly to reject them and only because it's not the best way to build strings. By usage, strings should just work.
On the point of documentation, this is potentially a fair point if you consider that you probably wrote this function for a particular usage and you know at design time that you're really only ever going to give it a list of ints (if you strip the types away, the parameter is still called nums which suggests that's what was really intended). In reality, the function is actually much more powerful than that, and if included in a library, many people could use it for many more things than just that.
- dllthomas 10y ago> In reality, the function is actually much more powerful than that, and if included in a library, many people could use it for many more things than just that. I think all this says is that design and documentation considerations for functions in distributed libraries may be different than those for functions used locally. Something I certainly agree with, but not really a criticism of the parent point.
- clusmore 10y agoFair point. I realise I sound quite critical in my comments so perhaps I should add that I like the tool itself. The problems that I see are more in the usage as shown in the examples. I am not necessarily suggesting that in all circumstances, the most general types are the best. But I am yet to see this tool used in such a way as to permit the most general types, as would be appropriate for library functions.
- dllthomas 10y ago> if you strip the types away, the parameter is still called nums which suggests that's what was really intended Correct and concise documentation is incredibly valuable. For documentation to stay correct, it must be checked and updated as situations change. Types and assertions can both play this role. Tests can play this role. Names also play this role - they are not mechanically checked, but "is my use here consistent with the name" is a check any programmer is applying as they work. This actually argues a bit against renaming refactor tools - if I am changing a name, I should be making sure that it squares with existing uses. From this perspective, checking of function parameter namess is weaker than checking of function names, since the names of the parameters typically do not appear at the use site - very different than the assignment of other variables.