Everton, I think that is for the sake of simplicity.

Let's consider C++ for a moment. In C++ you have a different operator for 
each of these situations:
foo.Bar access to member Bar from object foo
foo->Bar access to member Bar thru object pointer foo
foo::Bar access to member Bar from the namespace foo

That is three operators to explain, three operators to write documentation 
about, three operators to choose from when programming.

In each of these situations, if by any chance the programmer uses the wrong 
operator, C++ compiler emits an error. Why? Because it allways knows what 
is needed in each situation. Try it. Try using an arrow where a dot is 
expected. The compiler will complain.

Go takes the opposite approach. If the compiler allways knows what is 
needed, why should it bother the programmer? Let's use only dot. End of 
story.


On Wednesday, July 5, 2017 at 11:43:43 AM UTC-3, Everton Marques wrote:
>
> If context is not given, I can't tell if foo.Bar() is a function of 
> package foo or a method of variable foo.
> That is, dot is used both for package namespace and method call.
>
> Example:
>
> type T struct {
> }
>
> func (t T) Println(s string) {
> fmt.Println("method: " + s)
> }
>
> func main() {
> fmt.Println("hello from package function")
> fmt := T{}
> fmt.Println("hello")
> }
>
> https://play.golang.org/p/HZibMmJ8W5
>
> I wonder if such an ambiguity came into Go...
> 1) on purpose, since the dot (.) is easy on the eye and simple key stroke 
> (shift not needed) ?
> 2) by accident, since keyboards lack convenient alternate symbols ?
> 3) for other reasons ?
>
> Everton
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to