Named arguments in Swift

Software

Today I learned! Via kornel on lobste.rs:

Yeah, I think Swift nailed it. Its overloading/default args aren’t even a special calling convention or kwargs object. They are merely part of function’s name cleverly split into pieces. init(withFoo:f andBar:b) is something like init_withFoo_andBar_(f, b) under the hood.

It’s been a while since I was a full-time developer, but I loved the Objective-C/Smalltalk messaging style over the C/C++ style for parameters, even just for the sake of readability:

Human age: 18 height : 180
Human(18,180)

I might need to mess with Smalltalk again one day. Is there a modern implementation in regular use that isn’t wed to C? Objective Rust, make it happen!

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

You can leave me a comment by contacting me, and I might publish your thoughts. Please read the FAQs first though.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!