14
Recently, I’ve been thinking about few common anti-patterns I tend to see in professional JavaScript projects. Today, I wanted to talk about one of them: no docs.
A lot of more seasoned developers have this obsessed with “self-documenting code.”
And its true that if you write functions that do just one thing and follow logical naming conventions, what a piece of code does can often be pretty apparent.
Looking at the addItemToCart() function below, I can pretty quickly determine that I pass in the ID of the item to add, and it updates the quantity of that item in the cart object.
In your example, without the comment, I’d have no way of knowing it was a customer ID I’m getting, unless the only objects with IDs are customers.
I mean, the example kinda implies that this is on a
Customer
type. Otherwise you’d have a methodgetCustomerId
instead.