CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Member-only story

Stop Using **kwargs as a Method Argument For Goodness’ Sake

--

I’ve been recently maintaining a code base that has extensive usage of **kwargs in method parameters which had a frustrating effect on me on not being able to understand what needs to be passed to the method unless I opened the method implementation.

To add insult to injury, there wasn’t any documentation at the top of the method to understand what needs to be passed. This meant I had to read the code line by line.

To add more humiliation to insult, the **kwargs were even being passed again a second level of depth to other methods that also accept **kwargs, which meant I had to dig even deeper to read more implementation details of these methods, again with no python documentation whatsoever for these methods.

To add shock to my humiliation, those methods were written by SDE III software engineers, unfortunately some even brag about using **kwargs in their code as a way to show-off how they achieve with less lines of code.

I’ve had it, enough is enough, I decided to write this article to outline why you never should use **kwargs (or even brag out it). Although **kwargs is a python specific feature, the same unpleasant technique could be used in Java by passing a `Map<String,String>` as a method argument or using map in golang passed as a parameter to a func to allow…

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Basil A.
Basil A.

Written by Basil A.

A Software Engineer with interests in System Design and Software Engineering done right.

No responses yet