5 ms·
Is this an example from some well-known compiled language? I work mostly in C++, and this is a feature I've wished for for a long time.
by CoastalCoder 2y ago
Is this an example from some well-known compiled language?
I work mostly in C++, and this is a feature I've wished for for a long time.
- ijlx 2y agoSwift and C# appear to have this feature, though they use the syntax fetch(accountId, history: true, details: false);
- yen223 2y agoKotlin does this https://kotlinlang.org/docs/functions.html#named-arguments https://kotlinlang.org/docs/functions.html#named-arguments
- kazinator 2y agoNope! > "When you use named arguments in a function call, you can freely change the order that they are listed in." That violates a key requirement in my specification, which means that I regard it as broken. Positional parameters should take arguments only in their designated argument position. Only non-positional parameters (keyword parameters) should be allowed to be specified in any order.
- JamesonNetworks 2y agoIs there an example you have in mind as to why the params, if passed via keyword, would need to stay in their position? It sounds like external calls made to the internal api without the headers being present? Trying to understand why the position/order would matter to you once arguments are named?
- einburger 2y agoIf the code base supports designated initializers I'll use them as a way of getting named parameters like so: struct SomeArgs { bool normalize{false}; int stride{2}; char ch{'x'}; ... some other stuff }; void someFn(SomeArgs args); someFn({ .stride = 1, .ch = 'y' }); someFn({ .normalize = true }); not as simple as python but it's close-ish and more readable than: someFn(false, 2, 'c');
- gherkinnn 2y agoC# is well known I guess https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments#named-arguments https://learn.microsoft.com/en-us/dotnet/csharp/programming-...
- js2 2y agoObjective-C. Swift.
- adamrezich 2y agoJai has this.