FAQ
A useful operator used in Dart language is the cascade operator:

"The .. operator in the preceding code is a cascade operator, which allows
you to perform multiple operations on the members of a single object."
https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-main

which if were added to Go would help to simplify code, i.e. when you have
to set the fields of a same object:

***
FieldName.a = 0
FieldName.b = 1
FieldName.c = "as"

vs

FieldName
..a = 0
..b = 1
..c = "as"
***

Or to pass several tags to the same field:

***
struct {
     microsec uint64 `field:"1", quest:"er"`
     serverIP6 uint64 `field:"2", quest:"zx"`
     process string `field:"3", quest:"as"`
}

vs

struct {
     microsec uint64 ..field:"1" ..quest:"er"
     serverIP6 uint64 ..field:"2" ..quest:"zx"
     process string ..field:"3" ..quest:"as"
}
***

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

  • Jan Mercl at Aug 8, 2014 at 11:05 am

    On Fri, Aug 8, 2014 at 12:57 PM, Archos wrote:
    A useful operator used in Dart language is the cascade operator:

    "The .. operator in the preceding code is a cascade operator, which allows
    you to perform multiple operations on the members of a single object."
    https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-main

    which if were added to Go would help to simplify code, i.e. when you have to
    set the fields of a same object:

    ***
    FieldName.a = 0
    FieldName.b = 1
    FieldName.c = "as"

    vs

    FieldName
    ..a = 0
    ..b = 1
    ..c = "as"
    ***
    Like VB with, but worse (no new scope).

    -j

    --
    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.
  • Minota at Aug 8, 2014 at 11:23 am
    IMHO there's no real gain for golang.
    This gonna cause a bad legibility of code.

    att,

    Lucas Sant' Anna
    +353 0834546382


    2014-08-08 12:04 GMT+01:00 Jan Mercl <0xjnml@gmail.com>:
    On Fri, Aug 8, 2014 at 12:57 PM, Archos wrote:
    A useful operator used in Dart language is the cascade operator:

    "The .. operator in the preceding code is a cascade operator, which allows
    you to perform multiple operations on the members of a single object."
    https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-main
    which if were added to Go would help to simplify code, i.e. when you have to
    set the fields of a same object:

    ***
    FieldName.a = 0
    FieldName.b = 1
    FieldName.c = "as"

    vs

    FieldName
    ..a = 0
    ..b = 1
    ..c = "as"
    ***
    Like VB with, but worse (no new scope).

    -j

    --
    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.
  • Meta keule at Aug 8, 2014 at 11:24 am
    I don't like to use an operator to set field tags (meta data, non code).
    That is confusing and gives a false impression on what field tags are and
    how they can be used.
    (also an operator inside a struct type definition does not make much sense
    to me).

    Cheers,
    Benny

    Am Freitag, 8. August 2014 12:57:19 UTC+2 schrieb Archos:
    A useful operator used in Dart language is the cascade operator:

    "The .. operator in the preceding code is a cascade operator, which
    allows you to perform multiple operations on the members of a single
    object."

    https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-main

    which if were added to Go would help to simplify code, i.e. when you have
    to set the fields of a same object:

    ***
    FieldName.a = 0
    FieldName.b = 1
    FieldName.c = "as"

    vs

    FieldName
    ..a = 0
    ..b = 1
    ..c = "as"
    ***

    Or to pass several tags to the same field:

    ***
    struct {
    microsec uint64 `field:"1", quest:"er"`
    serverIP6 uint64 `field:"2", quest:"zx"`
    process string `field:"3", quest:"as"`
    }

    vs

    struct {
    microsec uint64 ..field:"1" ..quest:"er"
    serverIP6 uint64 ..field:"2" ..quest:"zx"
    process string ..field:"3" ..quest:"as"
    }
    ***
    --
    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 Aug 8, 2014 at 12:22 pm

    On Fri, Aug 8, 2014 at 8:57 PM, Archos wrote:
    A useful operator used in Dart language is the cascade operator:

    "The .. operator in the preceding code is a cascade operator, which allows
    you to perform multiple operations on the members of a single object."
    https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-main

    which if were added to Go would help to simplify code, i.e. when you have to
    set the fields of a same object:
    Looks a lot like the "with" statement in Javascript that is no longer
    used because it was too confusing to use.

    --
    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 Aug 8, 2014 at 12:53 pm

    On Friday, 8 August 2014 13:57:19 UTC+3, Archos wrote:
    A useful operator used in Dart language is the cascade operator:

    "The .. operator in the preceding code is a cascade operator, which
    allows you to perform multiple operations on the members of a single
    object."

    https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-main

    which if were added to Go would help to simplify code, i.e. when you have
    to set the fields of a same object:

    ***
    FieldName.a = 0
    FieldName.b = 1
    FieldName.c = "as"
    vs.

    field := Field{a: 0, b:1, c:"as"}

    and little benefit from such large change.

    + egon

    vs
    FieldName
    ..a = 0
    ..b = 1
    ..c = "as"
    ***

    Or to pass several tags to the same field:

    ***
    struct {
    microsec uint64 `field:"1", quest:"er"`
    serverIP6 uint64 `field:"2", quest:"zx"`
    process string `field:"3", quest:"as"`
    }

    vs

    struct {
    microsec uint64 ..field:"1" ..quest:"er"
    serverIP6 uint64 ..field:"2" ..quest:"zx"
    process string ..field:"3" ..quest:"as"
    }
    ***
    --
    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.
  • San at Aug 8, 2014 at 4:51 pm

    field := Field{a: 0, b:1, c:"as"}

    and little benefit from such large change.

    + egon
    That make sense.
    Do you also have a solution when field doesn't has only a, b, and c
    properties?

    --
    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 Aug 8, 2014 at 5:28 pm

    On Friday, 8 August 2014 19:51:21 UTC+3, San wrote:
    field := Field{a: 0, b:1, c:"as"}
    and little benefit from such large change.

    + egon
    That make sense.
    Do you also have a solution when field doesn't has only a, b, and c
    properties?
    I would say that then the
    f.a = "a"
    f.b = "b"
    f.c = "c"
    isn't that verbose. If you have more fields, then it feels like a design
    smell. There definitely are cases where you have more, but I would think
    they don't come up that often.

    Give a real-world example where this occurs, otherwise the solutions would
    be for an imaginary problem that may never occur in real-life.

    + egon

    --
    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.
  • Archos at Aug 9, 2014 at 6:34 am
    I've only used Github's trending repositories to find projects that use
    structs with many fields:

         https://github.com/trending?l=go

    And guess!. It's very common the usage of multiple fields:

    https://github.com/shirou/gopsutil/blob/master/cpu.go#L8
    https://github.com/mapmeld/mapplz-go/blob/master/mapplz.go#L37
    https://github.com/docker/docker/blob/master/engine/engine.go#L47
    https://github.com/syncthing/syncthing/blob/master/discover/discover.go#L22


    El viernes, 8 de agosto de 2014 18:28:23 UTC+1, egon escribió:

    On Friday, 8 August 2014 19:51:21 UTC+3, San wrote:

    field := Field{a: 0, b:1, c:"as"}
    and little benefit from such large change.

    + egon
    That make sense.
    Do you also have a solution when field doesn't has only a, b, and c
    properties?
    I would say that then the
    f.a = "a"
    f.b = "b"
    f.c = "c"
    isn't that verbose. If you have more fields, then it feels like a design
    smell. There definitely are cases where you have more, but I would think
    they don't come up that often.

    Give a real-world example where this occurs, otherwise the solutions would
    be for an imaginary problem that may never occur in real-life.

    + egon
    --
    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 Aug 9, 2014 at 9:46 am

    On Saturday, 9 August 2014 09:34:54 UTC+3, Archos wrote:
    I've only used Github's trending repositories to find projects that use
    structs with many fields:

    https://github.com/trending?l=go

    And guess!. It's very common the usage of multiple fields:

    https://github.com/shirou/gopsutil/blob/master/cpu.go#L8
    https://github.com/mapmeld/mapplz-go/blob/master/mapplz.go#L37
    https://github.com/docker/docker/blob/master/engine/engine.go#L47
    https://github.com/syncthing/syncthing/blob/master/discover/discover.go#L22
    Sorry about not being explicit enough.

    To properly analyse a feature you need
    1. multiple real-world problems,
    2. discussion why that code can't be improved in any other way, and then
    3. show how the feature gives huge improvement.

    This is the bare minimum for having an interesting discussion about a
    feature.

    Just having many fields is not a problem, it just means that you have many
    fields. I failed to find the code that would have huge benefits from such
    cascade operator (of course I didn't do a thorough search).

    + egon

    El viernes, 8 de agosto de 2014 18:28:23 UTC+1, egon escribió:

    On Friday, 8 August 2014 19:51:21 UTC+3, San wrote:

    field := Field{a: 0, b:1, c:"as"}
    and little benefit from such large change.

    + egon
    That make sense.
    Do you also have a solution when field doesn't has only a, b, and c
    properties?
    I would say that then the
    f.a = "a"
    f.b = "b"
    f.c = "c"
    isn't that verbose. If you have more fields, then it feels like a design
    smell. There definitely are cases where you have more, but I would think
    they don't come up that often.

    Give a real-world example where this occurs, otherwise the solutions
    would be for an imaginary problem that may never occur in real-life.

    + egon
    --
    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.
  • David Thomas at Aug 9, 2014 at 1:01 pm
    Just thought I'd add, Dart took the cascade idea from Smalltalk, and it's typically used to chains method calls on the same object. Chaining method calls is popular in JavaScript, too, but you have to use "." and design the API for it by having methods return "this". Thus it's really useful in Dart.

    If this were added to Go (which I doubt, since chaining doesn't seem that popular anyway), I'd expect it to be used for method call chaining rather than setting fields, and certainly not for tags.

    It's also worth mentioning that this would likely interact badly with Go's semicolon inference.

    --
    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.
  • David Thomas at Aug 9, 2014 at 1:10 pm
    Oh one more thing: the cascade operator has none of the problems of Javascript's "with". Comparing it to "with" is fair, but don't assume that that means it has all of the same problems. "with" pollutes the scope. ".." requires that the single identifier following it is a field or method of the current receiver.

    --
    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
postedAug 8, '14 at 10:57a
activeAug 9, '14 at 1:10p
posts12
users8
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase