On Thu, Oct 19, 2023 at 9:56 PM Nurahmadie Nurahmadie <nurahma...@gmail.com>
wrote:

>
>> You have changed the question. You are no longer asking about defining
>> methods on a type derived from a primitive type. Non-aliased types are
>> deliberately distinct types that cannot be "auto downcast" or "auto
>> upcast". Arguably the biggest flaw of the C language was its automatic type
>> coercion. And I say that as someone who had been programming for several
>> years but didn't find a language I loved until I learned C sometime around
>> 1984. What you are proposing would lead to a huge number of bugs that
>> result from the C/C++ behavior you are advocating for. And that ignores the
>> technical difficulties of doing what you propose unless Go becomes more
>> like C++. Which most Go users, and I'm sure everyone on the Go development
>> team, would argue is a bad idea.
>>
>> Eh, I'm not really proposing anything. I'm interested in the why, I think
> I worded it badly in my last email, apologize about that, but the change in
> the question is because the statement that type in different package cannot
> be bounded/attached with new methods, so, ok, if we need to create new type
> to attach new methods to these foreign types, why is there no, type
> coercion, as you said, that allow the new type to be acknowledged as its
> underlying type? which will not be a question if otherwise Go has mechanism
> to allow methods to be attached to foreign types. I even deliberately not
> mentioned another modern language that allows this to a foreign type, not
> to compare Go with anything.
>
> But ok, I should take the answer as: it will make Go more C/C++ like, and
> it's bad. Sure.
>

Personally, I find "why" questions suspicious. They are usually thinly
disguised requests to change the existing behavior.  And that appears to be
the case for this discussion. Implicit type coercion is almost always a bad
idea. That is, more likely to introduce bugs than useful behavior. Here I
am not talking about generics which does not introduce type coercion. If
you believe the current behavior is wrong you should say so and propose why
an alternative behavior is better.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD8ZAFEAooGrN6TYj2MrsQQud%2BhEWexJG9QJuhNq_Rg1EA%40mail.gmail.com.

Reply via email to