FAQ
I recently had some syntax erros in my code that were hard to track down
due (from a go perspective). I figured I would write the comments here so
they are potentially googleable.

The built-in types are not keywords, so you can define a variable called
"string" or "float64". This can be useful, but it can also lead to
confusing errors when you've forgotten commas in your function arguments.
For example, declaring the function:

func Foo(float64 float64) (float64){
var b float64 = 5.0
return b
}

returns the error " float64 is not a type ". This is because in the
declaration of the function, float64 is the name of a float64; to the
compiler it is like the function was declared as Foo(num float64).

Similarly, if you forget a comma in a function type, it may seem like
arguments are disappearing as in the first error of
http://play.golang.org/p/XOayR2L1ay , but it's just that the compiler drops
the identifiers in the function type when returning the error.


(to help googling)
int is not a type
string is not a type

--
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/groups/opt_out.

Search Discussions

  • Peter at Feb 14, 2013 at 10:13 am
    I can certainly see how that error is confusing!

    I wonder if there is any circumstance in which declaring a variable with
    the same name as its (or another) type is a good idea? Sure, it helps you
    avoid thinking up a name for it, but if the type is descriptive enough then
    it's pretty common in Go to just use the first letter - you're not adding
    any information by repeating the type. I like the idea that the
    pre-declared types are not "special", but if I submitted a CL with a
    variable called "int" it probably wouldn't get very far.
    On Thursday, 14 February 2013 02:36:28 UTC, Brendan Tracey wrote:

    I recently had some syntax erros in my code that were hard to track down
    due (from a go perspective). I figured I would write the comments here so
    they are potentially googleable.

    The built-in types are not keywords, so you can define a variable called
    "string" or "float64". This can be useful, but it can also lead to
    confusing errors when you've forgotten commas in your function arguments.
    For example, declaring the function:

    func Foo(float64 float64) (float64){
    var b float64 = 5.0
    return b
    }

    returns the error " float64 is not a type ". This is because in the
    declaration of the function, float64 is the name of a float64; to the
    compiler it is like the function was declared as Foo(num float64).

    Similarly, if you forget a comma in a function type, it may seem like
    arguments are disappearing as in the first error of
    http://play.golang.org/p/XOayR2L1ay , but it's just that the compiler
    drops the identifiers in the function type when returning the error.


    (to help googling)
    int is not a type
    string is not a type
    --
    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/groups/opt_out.
  • Kyle Lemons at Feb 14, 2013 at 4:50 pm
    Seems like something go vet could warn you about. In your case it actually
    causes a compiler error, so I'm not sure it would have helped, though.

    On Wed, Feb 13, 2013 at 6:36 PM, Brendan Tracey wrote:

    I recently had some syntax erros in my code that were hard to track down
    due (from a go perspective). I figured I would write the comments here so
    they are potentially googleable.

    The built-in types are not keywords, so you can define a variable called
    "string" or "float64". This can be useful, but it can also lead to
    confusing errors when you've forgotten commas in your function arguments.
    For example, declaring the function:

    func Foo(float64 float64) (float64){
    var b float64 = 5.0
    return b
    }

    returns the error " float64 is not a type ". This is because in the
    declaration of the function, float64 is the name of a float64; to the
    compiler it is like the function was declared as Foo(num float64).

    Similarly, if you forget a comma in a function type, it may seem like
    arguments are disappearing as in the first error of
    http://play.golang.org/p/XOayR2L1ay , but it's just that the compiler
    drops the identifiers in the function type when returning the error.


    (to help googling)
    int is not a type
    string is not a type

    --
    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/groups/opt_out.

    --
    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/groups/opt_out.
  • Oryband at May 28, 2015 at 2:58 pm
    Brendan, you just saved my day with this post. Found it via Google :)
    Thanks!
    On Thursday, February 14, 2013 at 4:36:28 AM UTC+2, Brendan Tracey wrote:

    I recently had some syntax erros in my code that were hard to track down
    due (from a go perspective). I figured I would write the comments here so
    they are potentially googleable.

    The built-in types are not keywords, so you can define a variable called
    "string" or "float64". This can be useful, but it can also lead to
    confusing errors when you've forgotten commas in your function arguments.
    For example, declaring the function:

    func Foo(float64 float64) (float64){
    var b float64 = 5.0
    return b
    }

    returns the error " float64 is not a type ". This is because in the
    declaration of the function, float64 is the name of a float64; to the
    compiler it is like the function was declared as Foo(num float64).

    Similarly, if you forget a comma in a function type, it may seem like
    arguments are disappearing as in the first error of
    http://play.golang.org/p/XOayR2L1ay , but it's just that the compiler
    drops the identifiers in the function type when returning the error.


    (to help googling)
    int is not a type
    string is not a type
    --
    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
postedFeb 14, '13 at 2:36a
activeMay 28, '15 at 2:58p
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase