3 ms·
One of my favourites features in Python are named parameters. I even wish Java could be more verbose in that manner.
by KptMarchewa 5y ago
One of my favourites features in Python are named parameters. I even wish Java could be more verbose in that manner.
- vbsteven 5y agoIf the project permits it, Kotlin fills that gap in Java well. Named parameters + defaults + nullability is a nice combination to have when it comes to evolving functions or types with backwards compatibility in mind.
- cletus 5y agoI go back and forth on Python in this regard, specifically the named vs positional arguments in that an argument can be one or the other. Part of me prefers just using an anonymous object in Javascript. Typescript is also cleaner than that. Day to day I use Hack (FB's PHP fork), which has a type system and shapes, which are essentially anonymous objects in the JS/TS sense but a little more awkward syntactically: function foo(shape( 'a' => int, 'b' => int, ?'c' => int, )): void; foo(shape('a' => 1, 'b' => 2)); But with Python you sort of have this awkward mix of args and kwargs.
- klibertp 5y agoYou can mark args as keyword only or positional only in the recent versions of Python (starting 3.7, maybe?)
- skocznymroczny 5y agoYou'd be surprised how many people are against this feature. I thought it'd be a no-brainer when it was proposed in the D community, but there was a lot of pushback against the feature (it's not implemented yet but it was accepted for the language). The main argument was that named arguments will cause your code to break when the arguments are renamed.
- makapuf 5y agoSeems acceptable since names are now part if your interface, and you could object that now you can relax ordering. Whats more interesting is that python has position only and name only arguments, meaning that there are uses for both.
- habibur 5y ago> The main argument was that named arguments will cause your code to break when the arguments are renamed. Here's the counter point : ordered argument list will break if the order is re arranged in the defined function. While for named arguments it doesn't.
- Sebb767 5y ago> Here's the counter point : ordered argument list will break if the order is re arranged in the defined function. While for named arguments it doesn't. Counter-counterpoint: Once you add support for named arguments, your cannot do either, as you don't know which convention the caller uses.
- ledauphin 5y agoin Python you can (and should) define your keyword arguments as keyword-only, for that very reason.