FAQ
gofmt/simplify.go contains the note:

// Note: We could also simplify slice expressions of the form s[0:b] to
s[:b]
// but we leave them as is since sometimes we want to be very explicit
// about the lower bound.

What is the rationale here? When is explicitly specifying a lower bound of
0 helpful?
The comment currently does not expound on this.

--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Robert Griesemer at Oct 1, 2013 at 4:50 pm
    I wrote this comment.

    Simplifying s[x : len(s)] to s[x :] seems like it's always a good idea
    because it reduces clutter and duplication; while simplifying s[0 : x] to
    s[: x] is not such a big deal. I felt more strongly about this in the past
    (if I remember correctly, at first only the 2nd index was made optional -
    we changed it later for symmetry). That said, sometimes it's still
    desirable (for pedagogic or readability reasons) to write the explicit 0.
    It's also fairly easy to make the rewrite with -r if so desired.

    - gri


    On Tue, Oct 1, 2013 at 7:10 AM, rh wrote:

    gofmt/simplify.go contains the note:

    // Note: We could also simplify slice expressions of the form s[0:b] to
    s[:b]
    // but we leave them as is since sometimes we want to be very
    explicit
    // about the lower bound.

    What is the rationale here? When is explicitly specifying a lower bound
    of 0 helpful?
    The comment currently does not expound on this.

    --

    ---
    You received this message because you are subscribed to the Google Groups
    "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+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-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rh at Oct 1, 2013 at 6:44 pm
    Dear gri,

    Thank you very much for expounding upon your thinking. I really appreciate
    it.

    1) May I gut your comment for its spirit, and place underneath the existing
    comment in simplify.go? I believe that the why is as important as the what
    to capture.

    2) Can you give me a small sample where including the explicit 0 helps code
    become more readable or pedagogic? This part is for my own feeble mind.

    Thank you so much,
    Yet another Robert contributing to Go
    On Tuesday, October 1, 2013 11:50:27 AM UTC-5, gri wrote:

    I wrote this comment.

    Simplifying s[x : len(s)] to s[x :] seems like it's always a good idea
    because it reduces clutter and duplication; while simplifying s[0 : x] to
    s[: x] is not such a big deal. I felt more strongly about this in the past
    (if I remember correctly, at first only the 2nd index was made optional -
    we changed it later for symmetry). That said, sometimes it's still
    desirable (for pedagogic or readability reasons) to write the explicit 0.
    It's also fairly easy to make the rewrite with -r if so desired.

    - gri



    On Tue, Oct 1, 2013 at 7:10 AM, rh <robert...@gmail.com <javascript:>>wrote:
    gofmt/simplify.go contains the note:

    // Note: We could also simplify slice expressions of the form s[0:b] to
    s[:b]
    // but we leave them as is since sometimes we want to be very
    explicit
    // about the lower bound.

    What is the rationale here? When is explicitly specifying a lower bound
    of 0 helpful?
    The comment currently does not expound on this.

    --

    ---
    You received this message because you are subscribed to the Google Groups
    "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Andrey mirtchovski at Oct 1, 2013 at 6:59 pm

    2) Can you give me a small sample where including the explicit 0 helps code
    become more readable or pedagogic?
    i'm not a robert, but i'll reply:

    http://blog.golang.org/slices

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rh at Oct 1, 2013 at 7:07 pm
    Andrey,

    Thank you for sharing your thoughts. My original thinking behind all this
    is that just like gofmt enforces one consistent style for all programs, it
    may be nice to just have one consistent format for slicing an array that
    starts at zero. One less thing to bikeshed. However, since gri feels
    there are cases where explicit zeroes are useful to readability, I defer to
    him.

    Thank you both.
    Rob (not Griesemer or Pike... I wish, ha :)
    On Tuesday, October 1, 2013 1:59:24 PM UTC-5, andrey mirtchovski wrote:

    2) Can you give me a small sample where including the explicit 0 helps code
    become more readable or pedagogic?
    i'm not a robert, but i'll reply:

    http://blog.golang.org/slices
    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Russ Cox at Oct 1, 2013 at 7:16 pm
    An example where the 0 helps:

    x, y, z := b[0:2], b[2:4], b[4:6]

    An example where it does not:

    x, y := b[:n], b[n:]

    Russ

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rh at Oct 1, 2013 at 7:20 pm
    Perfect. Thanks, Russ.
    On Tuesday, October 1, 2013 2:16:13 PM UTC-5, rsc wrote:

    An example where the 0 helps:

    x, y, z := b[0:2], b[2:4], b[4:6]

    An example where it does not:

    x, y := b[:n], b[n:]

    Russ
    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Robert Griesemer at Oct 1, 2013 at 7:50 pm
    Others have already answered but feel free to add a comment documenting the
    decision. Russ' example looks good to me.
    - gri

    On Tue, Oct 1, 2013 at 11:44 AM, rh wrote:

    Dear gri,

    Thank you very much for expounding upon your thinking. I really
    appreciate it.

    1) May I gut your comment for its spirit, and place underneath the
    existing comment in simplify.go? I believe that the why is as important as
    the what to capture.

    2) Can you give me a small sample where including the explicit 0 helps
    code become more readable or pedagogic? This part is for my own feeble
    mind.

    Thank you so much,
    Yet another Robert contributing to Go

    On Tuesday, October 1, 2013 11:50:27 AM UTC-5, gri wrote:

    I wrote this comment.

    Simplifying s[x : len(s)] to s[x :] seems like it's always a good idea
    because it reduces clutter and duplication; while simplifying s[0 : x] to
    s[: x] is not such a big deal. I felt more strongly about this in the past
    (if I remember correctly, at first only the 2nd index was made optional -
    we changed it later for symmetry). That said, sometimes it's still
    desirable (for pedagogic or readability reasons) to write the explicit 0.
    It's also fairly easy to make the rewrite with -r if so desired.

    - gri


    On Tue, Oct 1, 2013 at 7:10 AM, rh wrote:

    gofmt/simplify.go contains the note:

    // Note: We could also simplify slice expressions of the form s[0:b] to
    s[:b]
    // but we leave them as is since sometimes we want to be very
    explicit
    // about the lower bound.

    What is the rationale here? When is explicitly specifying a lower bound
    of 0 helpful?
    The comment currently does not expound on this.

    --

    ---
    You received this message because you are subscribed to the Google
    Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-dev+...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    ---
    You received this message because you are subscribed to the Google Groups
    "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+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-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 1, '13 at 4:27p
activeOct 1, '13 at 7:50p
posts8
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase