3 ms·
Yeah. Pretty horrible design flaw. Being able to add parameters in a backwards compatible way is essential for software development. I guess the only way to do
by globular-toast 6y ago
Yeah. Pretty horrible design flaw. Being able to add parameters in a backwards compatible way is essential for software development. I guess the only way to do it is via passing an object, which is like passing keyword parameters in other languages.
- tetha 6y agoOr you end up with java-like names once you forgot the option object. toReabableNumber, toReadableNumberWithBase, toReadableNumberWithBaseAndPrecision, .... or I guess toReabableNumberWithOptions.
- simongray 6y agoIsn't that more Objective-C style?
- wruza 6y agoAaand in objc, it would traditionally be: [array mapSelector:@selector(toReadableNumber:withOptions:) fromObject:[NSFormattingManager localizedFormattingManager] withArguments:@[@{kCFNumberFormattingBaseKey:@(10)}]]; Thank god they invented @-syntax for core type literals.
- hawk_ 6y agouhm java has method overloading..
- vorticalbox 6y agoSo does javascript.
- Toutouxc 6y agoI believe that JS doesn't have function overloading. Function overloading, the way I understand it, is the ability to declare multiple functions with the same name but a different signature (different tuple of arguments) and let the runtime/compiler decide upon the implementation used.
- vorticalbox 6y agoJavaScript supports this here is a snippet from out sdk https://pastebin.com/xCnY8ZzV https://pastebin.com/xCnY8ZzV
- emteycz 6y agoThat's TypeScript and it works only with type signatures, you still have only one actual implementation.
- dsego 6y agoI don't understand this argument. Let's say you remove a typed param and replace it with a new one of the same type, how will your typed language protect you then? Is that a case that should be handled in a backwards compatible way? Changing a function signature is a breaking change. In some cases like function arity or different types your compiler could catch it and throw errors (and break your program, hence breaking change). A better language might have a special syntax or specific types for mapping functions but that's not the argument you were making.
- reeeeee 6y agoIf you remove a typed param and replace it with a new one of the same type, typing will indeed not save you. But there should be other checks to warn you: - Version should be bumped - Dependencies should be informed via the changelog - Existing tests of dependencies should fail
- valenterry 6y ago> Changing a function signature is a breaking change Not if your language has default parameters and does not allow callers to pass "extra" parameters. Then you can easily add a new parameter with a default value and older callers will work as expected.
- globular-toast 6y agoI forgot to say I meant adding an optional new parameter to a function. Obviously adding a new parameter to a function is a breaking change for any API regardless of language.