Bobinas P4G
  • Login
  • Public

    • Public
    • Groups
    • Popular
    • People

Conversation

Notices

  1. muesli (fribbledom@mastodon.social)'s status on Wednesday, 22-May-2019 01:07:36 UTC muesli muesli

    #golang pop quiz: what does this code print out?

    s := strings.Split("", "@") fmt.Println(len(s))

    [ ] 0
    [ ] 1
    [ ] Undefined output

    In conversation Wednesday, 22-May-2019 01:07:36 UTC from mastodon.social permalink
    • muesli (fribbledom@mastodon.social)'s status on Thursday, 23-May-2019 04:35:02 UTC muesli muesli
      in reply to

      Sounds like most of you are aware of strings.Split's behavior, and it is well documented, too:

      "If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s."

      So if s was an empty string, that would be the only element in the returned list.

      However, it still seems a bit unintuitive to me. I keep noticing how often people expect it to return an empty slice, which leads to issues that can be tricky to debug at times.

      In conversation Thursday, 23-May-2019 04:35:02 UTC permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • Privacy
  • Source
  • Version
  • Contact

Bobinas P4G is a social network. It runs on GNU social, version 2.0.1-beta0, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All Bobinas P4G content and data are available under the Creative Commons Attribution 3.0 license.