Hacker News new | ask | show | jobs
by joeldo 1455 days ago
- If it were an item id the argument would be item_id. It is an object.

You've never worked with vaguely named variables? What you are suggesting is guessing the data type based off the name.

- What type of object? The type that can be added to a cart.

Okay sure, but what precisely is that?

- Nobody just throws random objects at a function.

I couldn't agree more - so the follow up question is what is the fastest way to get familiar with what type of input or output this function returns?

- They are familiar with the code in general and they know what to do.

For very small projects with very small teams after some onboarding time perhaps, but outside of this I would disagree.

Code changes over time, parts that you use to know intimately get changed subtley and erode knowledge away. Having types in place highlights these changes if your assumptions are incorrect.

1 comments

If you're working with badly named variables you have more problems than a type system can help with.

It doesn't matter "what precisely" is the the thing that you are adding to the chart, and a static type system won't tell you that either. There could be be any of 1000 things that implement IItem. And probably half those things just throw exceptions for methods they aren't actually able to implement.