FAQ
Hi All,

A simplified version of some of my code goes something like:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package main

func main() {
     dir := ""
     entry := ""
     files := GetFiles(*dir + "/" + entry*)

     finalFilenamesWithPath := append(finalFilenamesWithPath, *dir+"/"+entry*
)

     _ = finalFilenamesWithPath
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

When i run a "go fmt" on the file, it insists on putting spaces around the
+ and "/" in the GetFiles func call, but in the append func call, it
insists on taking the spaces away.

That is, in GetFiles i end up getting:

*dir + "/" + entry*
and in append i end up getting:
*dir+"/"+entry*

Functionally they work fine, but i found it odd that "go fmt" was insisting
on sometimes putting spaces around string concatenation, and sometimes
insisting on taking it away.

Just wondering if there is a pattern i am missing... should string
concatenation have spaces around it or not? :) what are the rules that
govern such formatting?

cheers,

simran.

--
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

  • Dan Kortschak at May 18, 2016 at 4:59 am

    On Wed, 2016-05-18 at 14:35 +1000, simran wrote:
    Just wondering if there is a pattern i am missing... should string
    concatenation have spaces around it or not? :) what are the rules that
    govern such formatting?
    In the Get call, the string concatenation expression is the only
    parameter, in the append call it's one of two separated by a comma. The
    second case benefits from more tightly grouping the string concatenation
    expression to distinguish the expressions.

    --
    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.
  • Egon at May 18, 2016 at 8:42 am

    On Wednesday, 18 May 2016 07:36:35 UTC+3, simran g wrote:
    Hi All,

    A simplified version of some of my code goes something like:

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    package main

    func main() {
    dir := ""
    entry := ""
    files := GetFiles(*dir + "/" + entry*)

    finalFilenamesWithPath := append(finalFilenamesWithPath,
    *dir+"/"+entry*)

    _ = finalFilenamesWithPath
    }
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    When i run a "go fmt" on the file, it insists on putting spaces around the
    + and "/" in the GetFiles func call, but in the append func call, it
    insists on taking the spaces away.

    That is, in GetFiles i end up getting:

    *dir + "/" + entry*
    and in append i end up getting:
    *dir+"/"+entry*

    Functionally they work fine, but i found it odd that "go fmt" was
    insisting on sometimes putting spaces around string concatenation, and
    sometimes insisting on taking it away.

    Just wondering if there is a pattern i am missing...
    You should be using *filepath.Join*

    should string concatenation have spaces around it or not? :) what are the
    rules that govern such formatting?

    cheers,

    simran.


    --
    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.
  • Axel Wagner at May 18, 2016 at 4:47 pm
    I know that this sounds stupid, but: The whole point of gofmt is to not
    worry about such things. The tautologically correct way to do it is the way
    gofmt formats it, because that's how gofmt formats it.

    Or, as it has been put before: gofmt's style is no ones favorite, yet gofmt
    is everyone's favorite :) Disagreeing with gofmt is fine, but worrying
    about it is a waste of time.
    On Wed, May 18, 2016 at 6:35 AM, simran wrote:

    Hi All,

    A simplified version of some of my code goes something like:

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    package main

    func main() {
    dir := ""
    entry := ""
    files := GetFiles(*dir + "/" + entry*)

    finalFilenamesWithPath := append(finalFilenamesWithPath,
    *dir+"/"+entry*)

    _ = finalFilenamesWithPath
    }
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    When i run a "go fmt" on the file, it insists on putting spaces around the
    + and "/" in the GetFiles func call, but in the append func call, it
    insists on taking the spaces away.

    That is, in GetFiles i end up getting:

    *dir + "/" + entry*
    and in append i end up getting:
    *dir+"/"+entry*

    Functionally they work fine, but i found it odd that "go fmt" was
    insisting on sometimes putting spaces around string concatenation, and
    sometimes insisting on taking it away.

    Just wondering if there is a pattern i am missing... should string
    concatenation have spaces around it or not? :) what are the rules that
    govern such formatting?

    cheers,

    simran.



    --
    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.
    --
    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.
  • Simran at May 19, 2016 at 2:33 am
    Not disagreeing with it, not worrying about it... just trying to understand
    it :)

    Egon, thanks for the tip on filepath.Join :)
    On Thu, May 19, 2016 at 2:47 AM, Axel Wagner wrote:

    I know that this sounds stupid, but: The whole point of gofmt is to not
    worry about such things. The tautologically correct way to do it is the way
    gofmt formats it, because that's how gofmt formats it.

    Or, as it has been put before: gofmt's style is no ones favorite, yet
    gofmt is everyone's favorite :) Disagreeing with gofmt is fine, but
    worrying about it is a waste of time.
    On Wed, May 18, 2016 at 6:35 AM, simran wrote:

    Hi All,

    A simplified version of some of my code goes something like:

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    package main

    func main() {
    dir := ""
    entry := ""
    files := GetFiles(*dir + "/" + entry*)

    finalFilenamesWithPath := append(finalFilenamesWithPath,
    *dir+"/"+entry*)

    _ = finalFilenamesWithPath
    }
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    When i run a "go fmt" on the file, it insists on putting spaces around
    the + and "/" in the GetFiles func call, but in the append func call, it
    insists on taking the spaces away.

    That is, in GetFiles i end up getting:

    *dir + "/" + entry*
    and in append i end up getting:
    *dir+"/"+entry*

    Functionally they work fine, but i found it odd that "go fmt" was
    insisting on sometimes putting spaces around string concatenation, and
    sometimes insisting on taking it away.

    Just wondering if there is a pattern i am missing... should string
    concatenation have spaces around it or not? :) what are the rules that
    govern such formatting?

    cheers,

    simran.



    --
    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.
    --
    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
postedMay 18, '16 at 4:36a
activeMay 19, '16 at 2:33a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase