3 ms·
What is an item in the first declaration? Is it an id? Is it an object (if so, what type of object? Id and qty or some other data)? I guess you now need to rea
by joeldo 4y ago
What is an item in the first declaration? Is it an id? Is it an object (if so, what type of object? Id and qty or some other data)?
I guess you now need to read through the implementation or docs.
The first is much easier to read incorrectly.
- bjourne 4y agoWhat is an item in the second declaration? That it has type "Item" doesn't help you unless you have contextual information. And if you have contextual information you can probably figure out what an item is in the first declaration too.
- joeldo 4y agoI would argue that it isn't a zero-sum game. Extra context (that is enforced) is better than none at all.
- kdtsh 4y agoAn item is an IItem, as it says in the definition. You can always ‘figure out what an item is’ in a dynamic typing system, that’s not the problem. There’s an incredible amount of mental overhead in any non-trivial project which employs dynamic typing. Engineers who can work around this have my respect, but I find static typing to be the easiest solution to this problem by far.
- bjourne 4y agoThat fact is useless without any context. An "item" could have been an "Ifdkjsj" and you'd be none the wiser. "incredible amount of mental overhead" needs a citation and, as shown in TFA, no citation exists.
- kdtsh 4y agoMaybe I’m not understanding where you’re coming from because as far as I can tell a ‘lfdkjsj’ and a ‘skfjwb’ which are both an IItem, or both a IWhcjwp, is easier to work with than the dynamic alternative. Regardless of how poorly named a variable is, in a static ruling system what you see is what you get, where as in a dynamic typing system what you see could be anything at runtime. The only citation I have is the tenuous grip I have on my own sanity - I could have more correctly talked about the incredible amount of mental overhead this has _for me_, but read the rest of the thread and you’ll see that this isn’t an uncommon experience. As I said, if you can work around this then you have my respect.
- bjourne 4y ago> in a static ruling system what you see is what you get, where as in a dynamic typing system what you see could be anything at runtime. What you see in a statically typed language: IBlaha blah. What could blah be? An IBlaha. What could IBlaha be? Anything! The type has not gained you anything. > The only citation I have is the tenuous grip I have on my own sanity That's an argument from authority where you are the authority. It doesn't work on HN since we are all skilled developers. I've also been a software developer for decades and I can count on one hand the times static types has provided a tangible benefits.
- kdtsh 4y agoNow we are just talking about using a sane naming convention for your types. Depending on the paradigm you are working in your instance of IBlaha has a consistent definition - in a trait or a class or whatever else you like. It also likely makes simple work for your IDE during refactoring as others have observed. You don’t get this from dynamic typing. Of course you could say the same thing about sane naming dynamic naming conventions for your declarations in a dynamically typed language - and you wouldn’t be wrong, but a compiler won’t help you in the case of human error. All I’m interested in is offloading as much complexity onto the tools at my disposal, so I can focus on what’s important. On my citation … that was tongue in cheek and I thought it was obvious. I don’t have a citation, this is all my own experience. For the third time, if you can work your way around this you have my respect.
- bjourne 4y agoSure, the type IBlaha is defined somewhere just as the object(s) passed to add_item_to_cart are also defined somewhere. Again: "That it has type "Item" doesn't help you unless you have contextual information." It has nothing to do with naming conventions. Whatever simplistic tools does is irrelevant since this sub thread was about the meaning of two declarations in HN comment. Dynamically typed languages are very popular so it seems that many developers can work their way around dynamic typing.
- 4y ago
- jacobsenscott 4y agoIf it were an item id the argument would be item_id. It is an object. What type of object? The type that can be added to a cart. You don't just drop a programmer into the code and have them call a function in a vacuum. Nobody just throws random objects at a function. They are familiar with the code in general and they know what to do.
- joeldo 4y 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.
- jacobsenscott 4y agoIf 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.