▲ 80 ▼ Low effort meme (lemmy.ml) submitted 1 year ago by voodooattack@lemmy.world to c/programmerhumor@lemmy.ml 10 comments fedilink hide all child comments
[+] ugo@feddit.it 3 points 1 year ago (4 children) [deleted] permalink fedilink source parent hideshow 4 child comments replies: [–] thebestaquaman@lemmy.world 3 points 1 year ago (3 children) Thanks, that was a good read :) However, my impression is that he's largely using the existence of templates and polymorphism as arguments that "we don't really care about type". I disagree: A template is essentially a generic type description that says something about what types are acceptable. When working with something polymorphic, I'll prefer ParentClass&, to indicate what kind of interface I'm working with. Sure, it can be very useful to hide exact type information in order to generalise the code, but I think that's a weak argument for hiding all type information by default, which is what auto does. permalink fedilink source parent hideshow 3 child comments replies: [+] ugo@feddit.it 0 points 1 year ago (2 children) [deleted] permalink fedilink source parent hideshow 2 child comments replies: [–] thebestaquaman@lemmy.world 1 point 1 year ago* (1 child) Similarly, what would you gain by saying uint32_t const* x = my_var.get<uint32_t>(); To be frank: You gain the information that MyConcreteType::get<uint32_t> returns a uint32_t, which I otherwise couldn't infer from the docs. Of course, I could assume it, based on the template parameter, but I don't want to go around assuming a bunch of stuff in order to read docs. Take an example like auto x = my_var.to_reduced_form(), it's very clear that x is the "reduced form" of my_var, which could be meaningful in itself, but what type is it? I need to know that if I want to do anything with x. Can I do x += 1? If I do, will that modify my_var? Let's say I want to make a vector of whatever to_reduced_form returns... and so on. All these questions are very easily answered by MyConcreteType x = my_var.to_reduced_form(). Now I immediately know that everything I can do with my_var, I can also do with x. This makes me happy, because I need to do less digging, and the code becomes clearer to read. permalink fedilink source parent hideshow 1 child comment replies: [+] ugo@feddit.it 1 point 1 year ago [deleted] permalink fedilink source parent
[–] thebestaquaman@lemmy.world 3 points 1 year ago (3 children) Thanks, that was a good read :) However, my impression is that he's largely using the existence of templates and polymorphism as arguments that "we don't really care about type". I disagree: A template is essentially a generic type description that says something about what types are acceptable. When working with something polymorphic, I'll prefer ParentClass&, to indicate what kind of interface I'm working with. Sure, it can be very useful to hide exact type information in order to generalise the code, but I think that's a weak argument for hiding all type information by default, which is what auto does. permalink fedilink source parent hideshow 3 child comments replies: [+] ugo@feddit.it 0 points 1 year ago (2 children) [deleted] permalink fedilink source parent hideshow 2 child comments replies: [–] thebestaquaman@lemmy.world 1 point 1 year ago* (1 child) Similarly, what would you gain by saying uint32_t const* x = my_var.get<uint32_t>(); To be frank: You gain the information that MyConcreteType::get<uint32_t> returns a uint32_t, which I otherwise couldn't infer from the docs. Of course, I could assume it, based on the template parameter, but I don't want to go around assuming a bunch of stuff in order to read docs. Take an example like auto x = my_var.to_reduced_form(), it's very clear that x is the "reduced form" of my_var, which could be meaningful in itself, but what type is it? I need to know that if I want to do anything with x. Can I do x += 1? If I do, will that modify my_var? Let's say I want to make a vector of whatever to_reduced_form returns... and so on. All these questions are very easily answered by MyConcreteType x = my_var.to_reduced_form(). Now I immediately know that everything I can do with my_var, I can also do with x. This makes me happy, because I need to do less digging, and the code becomes clearer to read. permalink fedilink source parent hideshow 1 child comment replies: [+] ugo@feddit.it 1 point 1 year ago [deleted] permalink fedilink source parent
[+] ugo@feddit.it 0 points 1 year ago (2 children) [deleted] permalink fedilink source parent hideshow 2 child comments replies: [–] thebestaquaman@lemmy.world 1 point 1 year ago* (1 child) Similarly, what would you gain by saying uint32_t const* x = my_var.get<uint32_t>(); To be frank: You gain the information that MyConcreteType::get<uint32_t> returns a uint32_t, which I otherwise couldn't infer from the docs. Of course, I could assume it, based on the template parameter, but I don't want to go around assuming a bunch of stuff in order to read docs. Take an example like auto x = my_var.to_reduced_form(), it's very clear that x is the "reduced form" of my_var, which could be meaningful in itself, but what type is it? I need to know that if I want to do anything with x. Can I do x += 1? If I do, will that modify my_var? Let's say I want to make a vector of whatever to_reduced_form returns... and so on. All these questions are very easily answered by MyConcreteType x = my_var.to_reduced_form(). Now I immediately know that everything I can do with my_var, I can also do with x. This makes me happy, because I need to do less digging, and the code becomes clearer to read. permalink fedilink source parent hideshow 1 child comment replies: [+] ugo@feddit.it 1 point 1 year ago [deleted] permalink fedilink source parent
[–] thebestaquaman@lemmy.world 1 point 1 year ago* (1 child) Similarly, what would you gain by saying uint32_t const* x = my_var.get<uint32_t>(); To be frank: You gain the information that MyConcreteType::get<uint32_t> returns a uint32_t, which I otherwise couldn't infer from the docs. Of course, I could assume it, based on the template parameter, but I don't want to go around assuming a bunch of stuff in order to read docs. Take an example like auto x = my_var.to_reduced_form(), it's very clear that x is the "reduced form" of my_var, which could be meaningful in itself, but what type is it? I need to know that if I want to do anything with x. Can I do x += 1? If I do, will that modify my_var? Let's say I want to make a vector of whatever to_reduced_form returns... and so on. All these questions are very easily answered by MyConcreteType x = my_var.to_reduced_form(). Now I immediately know that everything I can do with my_var, I can also do with x. This makes me happy, because I need to do less digging, and the code becomes clearer to read. permalink fedilink source parent hideshow 1 child comment replies: [+] ugo@feddit.it 1 point 1 year ago [deleted] permalink fedilink source parent