• Sunrosa@lemmy.world
    link
    fedilink
    arrow-up
    11
    arrow-down
    2
    ·
    1 month ago

    One of the reasons i find it so hard to use non-Rust languages is how ugly they typically are by comparison. “fn” instead of “function” is such a great example of saving key presses where they’re most needed. And you get very used to seeing compact abbreviations. Idk if that’s what you’re talking about though.

    • Lucy :3@feddit.org
      link
      fedilink
      arrow-up
      9
      arrow-down
      3
      ·
      1 month ago

      Rust:

      fn getofmylawn(lawn: Lawn) -> bool {
          lawn.remove()
      }
      

      C:

      bool getofmylawn(Lawn lawn) {
          return lawn.remove();
      }
      

      With Rust you safe 1 char, and gain needing to skip a whole line to see what type something is.

      • chunes@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        1 month ago

        So that’s why people like C-style return types. That actually makes a lot of sense. I do too now.

      • fruitcantfly@programming.dev
        link
        fedilink
        arrow-up
        4
        ·
        1 month ago

        With Rust you safe 1 char, and gain needing to skip a whole line to see what type something is.

        Honestly, the Rust way of doing things feels much more natural to me.

        You can read it as

        1. Define a function,
        2. with the name getoffmylawn,
        3. that takes a Lawn argument named lawn,
        4. and returns a bool

        Whereas the C function is read as

        1. Do something with a bool? Could be a variable, could be a function, could be a forward declaration of a function,
        2. whatever it is, it has the name getoffmylawn,
        3. there’s a (, so all options are still on the table,
        4. ok, that’ a function, since it takes a Lawn argument named lawn, that returns a bool
      • Sunrosa@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 month ago

        “fn” was just one example. There’s also other abbreviations like “pub”, “impl”, “extern”, “mut”, “ref”, “bool”, “u64” And it’s true that some of these keywords are only relevant in Rust, however other langues have their own specific keywords, and they tend to be longer. In languages like Java (which is the worst example I can think of), you see things like “private static boolean” as function definition. In c++, you have to type “unsigned long” or even “unsigned long long” to represent “u64” (depending on data model).

        • [object Object]@lemmy.world
          link
          fedilink
          arrow-up
          1
          arrow-down
          2
          ·
          1 month ago

          Ooh yeah, overall coding culture is definitely not affected by the preferred nomenclature for identifiers. The person who’s habituated to fn over function will absolutely never name their functions in the vein of chkdsk. The two are completely disconnected in the brain of the programmer who read too much K&R in their childhood and was irretrievably traumatized by it for life.

          • calcopiritus@lemmy.world
            link
            fedilink
            arrow-up
            1
            arrow-down
            1
            ·
            1 month ago

            I’d say it’s much more influential the names of the identifiers of the standard library.

            A language with function keyword that names it’s stdlib functions strstr and strtok will inspire way worse naming than on that has fn keyword with stdlib functions str::contains and str::split.

            We could search for a random crate on crates.io and see what identifiers people actually use, or we could spread misinformation on Lemmy.