Named Parameters in Dart, Swift and Python

In software development we optimize for readability since code is read more than its written. Named parameters are one way to improve code readability. Lets say we have a function that calculates the distance between two points. I takes two point Point class instances representing the start and end positions. When calling the functions, using positional arguments its not very clear what is being referred to.

In Python:

In Dart:

In Swift:

On the other hand, using named parameters makes function calls more expressive, its clear to the reader what the arguments represent. This becomes helpful particularly as the number of arguments grow. Lets add one more argument. In the examples below when calling the functions its not very clear what the third argument is when its being read.

Using named parameters is really helpful in such a situation. In the three languages its possible to specify that the parameters should be passed as named parameters. In Python, we can add a *, before the parameters, in dart we can add curly braces around the parameters and in swift we can remove the underscore before the parameter names.