FAQ
While watching Andrew and Brad's live coding session I noticed they used
"make" as a variable name. Here's a basic example

package main

import (
     "fmt"
)

func Make() string {
     return "Oops"
}

func main() {
     make := Make
     fmt.Println(make())
}

Playground (https://play.golang.org/p/p5wS1_INye)

This seems like a bad idea (I don't think they realized they did it), and I
actually thought the compiler would not allow it.

I was really surprised when everything worked. Is there anytime when
overriding make or its friends would be useful?

Kory

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

Search Discussions

  • David Symonds at Jan 11, 2015 at 11:49 pm
    Builtins are not keywords, so the compiler permits it.

    It's very useful in the sense of forward compatibility. Imagine that a
    future version of Go introduces some new builtin function, "zero".
    Everyone's code that currently does something like
       zero := 0
    will keep working in that future version just fine because of this.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Korylprince at Jan 12, 2015 at 4:30 pm
    Makes sense. Thanks!

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jesse McNelis at Jan 12, 2015 at 12:02 am

    On Mon, Jan 12, 2015 at 3:55 AM, wrote:
    I was really surprised when everything worked. Is there anytime when
    overriding make or its friends would be useful?
    To be clear, you're not 'overriding' the built-in make(), you're
    creating a new variable called 'make' within the scope of main().
    This makes the built-in make() inaccessible within main() but doesn't
    effect it outside of main().

    The variable called 'make' inside main() is said to 'shadow' the
    built-in make().
    This is one of the useful properties of block scoping.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Gao at Jan 13, 2015 at 3:30 pm

    On Monday, January 12, 2015 at 8:02:17 AM UTC+8, Jesse McNelis wrote:
    On Mon, Jan 12, 2015 at 3:55 AM, <koryl...@gmail.com <javascript:>>
    wrote:
    I was really surprised when everything worked. Is there anytime when
    overriding make or its friends would be useful?
    To be clear, you're not 'overriding' the built-in make(), you're
    creating a new variable called 'make' within the scope of main().
    This makes the built-in make() inaccessible within main() but doesn't
    effect it outside of main().
    The variable called 'make' inside main() is said to 'shadow' the
    built-in make().
    This is one of the useful properties of block scoping.
    I can not agree
    ```
    package main

    var make = 1

    func main() {

    }
    ```

    what bout this code? It's just the reason that make is not keyword.


    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Chris dollin at Jan 13, 2015 at 3:40 pm

    On 13 January 2015 at 15:30, Gao wrote:
    On Monday, January 12, 2015 at 8:02:17 AM UTC+8, Jesse McNelis wrote:

    The variable called 'make' inside main() is said to 'shadow' the
    built-in make().
    This is one of the useful properties of block scoping.
    I can not agree
    ```
    package main

    var make = 1

    func main() {

    }
    ```

    what bout this code?
    Well, what about it?
    It's just the reason that make is not keyword.
    make doesn't need to be a keyword. Which is good,
    because it reduces the opportunity to trip over its spelling.

    Chris

    --
    Chris "allusive" Dollin

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Gao at Jan 13, 2015 at 3:47 pm

    On Tuesday, January 13, 2015 at 11:40:50 PM UTC+8, ehedgehog wrote:
    On 13 January 2015 at 15:30, Gao <gaop...@gmail.com <javascript:>> wrote:
    On Monday, January 12, 2015 at 8:02:17 AM UTC+8, Jesse McNelis wrote:

    The variable called 'make' inside main() is said to 'shadow' the
    built-in make().
    This is one of the useful properties of block scoping.
    I can not agree
    ```
    package main

    var make = 1

    func main() {

    }
    ```

    what bout this code?
    Well, what about it?
    I want illustrate that if make is predefined in the out most scope,it will
    arose a redefine error,right?
    It's just the reason that make is not keyword.
    make doesn't need to be a keyword. Which is good,
    because it reduces the opportunity to trip over its spelling.

    Chris

    --
    Chris "allusive" Dollin
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Chris dollin at Jan 13, 2015 at 3:53 pm

    On 13 January 2015 at 15:47, Gao wrote:
    On Tuesday, January 13, 2015 at 11:40:50 PM UTC+8, ehedgehog wrote:

    ```
    package main

    var make = 1

    func main() {

    }
    ```

    what bout this code?
    Well, what about it?
    I want illustrate that if make is predefined in the out most scope,it will
    arose a redefine error,right?
    No.

    As per

         http://golang.org/ref/spec#Declarations_and_scope

    the predefined identifiers are in the universe block, which
    encloses the package block. Hence package-level declaration
    may shadow the builtins.

    Chris

    --
    Chris "allusive" Dollin

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 11, '15 at 11:47p
activeJan 13, '15 at 3:53p
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase