4 ms·
> Most of the time, when I see a new function, I have no idea what’s the type of its parameters... For that reason I usually use types for defining utility fun
by Alex3917 8y ago
> Most of the time, when I see a new function, I have no idea what’s the type of its parameters...
For that reason I usually use types for defining utility functions that get re-used in multiple places throughout the app. For everything else I just name the variables according to what the thing is, e.g.:
user_model, user_model_list, user_id_set, user_id_to_user_model_dict, etc. If you have a good style guide, there really should only be one allowable name for any given variable, and it should be immediately clear what type each variable is from the suffix on the name.
- cstejerean 8y agoAh yes, the old Hungarian notation (or variation on that idea). Makes sense in some contexts.
- kaoD 8y agoIsn't that just ad-hoc typing? What's the point of naming based on types, instead of just declaring types so they can be programmatically analyzed by your tools?
- Alex3917 8y ago> What's the point of naming based on types More readable. When declaring a type you only see the type when the variable is declared or when it's passed into a function, whereas when putting the type in the name it's obvious in each line where it's used so you don't need to waste working memory on remembering what things are.