Why can't GO just have arrays. Why do I have to learn new things like slices :(

  • 1
    Go has arrays.
    Slices are like arrays as well, they are just dynamically sized. Slices are just extended arrays
  • 0
    @byte are go slices similar to C++ vectors?
  • 2
    @Zennoe do you mean if internally it is just a pointer, a current size and a capacity (c++ vector)? I guess slices don't have the capacity. Usually they are readonly in respect to pushing more items.
  • 1
    @Zennoe kind of same from wht I've read ( I don't have much experience there )

    @anicka-burova slices have a capacity as well as length.
    Slices are like references to arrays
  • 0
    learning go wait till interface skull fucks your brain ...
    this implement that implement those so you could....

    anyway when you wrap your head round its the best language ever
  • 1
    @byte array slices is a subset extract from an array. Slices intention is a view in to the array. Capacity has no meaning here.
  • 0
    @anicka-burova slices can be an independent entity
    They are Go's way of implementing dynamic arrays
    sl := make( [ ] int, 0, 5)
    Makes a slice of length 0 and capacity 5
    s := make( [ ] int, 5)
    Makes a slice of length 5 and capacity 5
  • 3
    @byte I admit I never done Go. Slice is a technical term in programming, which looks like might be used wrong in Go.

    In c++ vector is an implementation for dynamic sized array. Calling it vector might be a bad idea as well.

    In pseudo programming, if somebody would use SLICE word, I would understand it as a view in to a subset of an array. There you wouldn't need a capacity obviously.

    Sorry for misunderstanding.
  • 1
    @anicka-burova Go slice is a little different than the traditional SLICE

    Yeah, I can see why they'd be misunderstood

    It takes time to get your head around these things in Go, but once you do its a great language
  • 2
    @byte my hobby is trying new languages, one day...
Add Comment