Named Arguments – Cole’s Coding Tips

Named Arguments – Cole’s Coding Tips


Hey, it’s Cole here, back with another coding tip. What do the arguments to this function mean? Unless you have the function memorized, there’s no way to tell without using IntelliSense or reading the function declaration. This makes code harder to read, and programmers often spend more time reading code than writing code, so we need to make our code as readable as possible. One way to fix this is with named arguments. Here we use named arguments to make this function call more readable, even to programmers unfamiliar with the function. As an added benefit, our code still works as intended if the function’s parameters are re-ordered, and the compiler will prevent bugs by giving us compile errors if a parameter is renamed. If your programming language doesn’t support named arguments, don’t fret! We have other options. We can use comments, we can use variables, or we can use structs and classes.
Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *