• danwardvs@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    This was me in courses that used C. Keep adding and removing * and & until the IDE was happy and it usually worked.

  • skomposzczet@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    I think that’s the only thing I dislike about rust. Not having to use * to dereference but later having to use is tad confusing. I know it’s still clever solution but in this case I prefer c++'s straightforward consistency.

    Using ampersand never was problematic for me.

    • Pfosten@feddit.de
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      C++ does have the problem that references are not objects, which introduces many subtle issues. For example, you cannot use a type like std::vector<int&>, so that templated code will often have to invoke std::remove_reference<T> and so on. Rust opts for a more consistent data model, but then introduces auto-deref (and the Deref trait) to get about the same usability C++ has with references and operator->. Note that C++ will implicitly chain operator-> calls until a plain pointer is reached, whereas Rust will stop dereferencing once a type with a matching method/field is found. Having deep knowledge of both languages, I’m not convinced that C++ features “straightforward consistency” here…

  • nothacking@discuss.tchncs.de
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Same for C, & yields a pointer to a value, and * allows you to access the data. (For rust people, a pointer is like a reference with looser type checking)

      • nautilus@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        honestly with Go in general I’m in a perpetual cycle of being annoyed with it and then immediately being amazed when I find some little trick for efficiency - with stringer interfaces and the like