Is it just me, or does Rust feel much more bare-bones than other languages? I just started learning it recently and this is the one thing that stood out to me, much more so than the memory management business. A lot of things that would normally be part of the language has to be achieved through meta-programming in Rust.

Is this a deliberate design choice? What do we gain from this setup?


Edits:

  1. Somehow, this question is being interpreted as a complaint. It’s not a complaint. As a user, I don’t care how the language is designed as long as it has a good user experience, but the curious part of my mind always wants to know why things are the way they are. Maybe another way to phrase my question: Is this decision to rely more on meta-programming responsible for some of the good UX we get in Rust? And if so, how?
  2. I’m using meta-programming to mean code that generates code in the original language. So if I’m programming in Rust, that would be code that generate more Rust code. This excludes compilation where Rust gets converted into assembly or any other intermediate representation.
  • BartyDeCanter@lemmy.sdf.org
    link
    fedilink
    arrow-up
    10
    ·
    2 days ago

    I think that really depends on your perspective. I’ve spent most of my career in C or a minimal subset of C++ for embedded systems. For me, even no_std rust has a rather rich set of features.

    • cx40@programming.devOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 days ago

      I can see that. I’m coming in from the other extreme that is Python, where even the meta-programming is done in plain Python.

      • BlackRoseAmongThorns@slrpnk.net
        link
        fedilink
        arrow-up
        3
        ·
        1 day ago

        I also come from python, actual meta-programming concepts are usually implemented via meta-classes, which I would describe as more complex than rust macros, in the “it takes longer to fully understand” sense.

        You could also generate python code and execute it if you don’t mind the obvious security implications, but that’s only a possibility thanks to it being an interpreted language, while rust macros can provide validations and readable error messages out of the box.

        To your post’s point in general:

        • Python uses exceptions, rust uses errors as values, making rust more predictable.
        • Python uses Nullables (None | T) which require hand-written handling, instead of rust’s Option<T> which has convenience methods and syntax support (... = maybe?).
        • Python has GC by default, and making a function fast requires delegating it to another programming language, meaning you usually would write python for software that needs not be performant.

        I have more points if you’d like to understand my position, and am willing to explain if you need.

      • TehPers@beehaw.org
        link
        fedilink
        English
        arrow-up
        4
        ·
        2 days ago

        Part of why Python can do this is that it runs completely differently from Rust. Python is interpreted and can run completely arbitrary code at runtime. It’s possible to exec arbitrary Python.

        Rust is compiled ahead of time. Once compiled, aside from inspecting how the output looks and what symbol names it uses, there’s nothing that ties the output to Rust. At runtime, there is nothing to compile new arbitrary code, and compiling at runtime would be slow anyway. There is no interpreter built into the application or required to run it either.

        This is also why C, C++, and many other compiled languages can’t execute new arbitrary code at runtime.

      • 6nk06@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        2 days ago

        even the meta-programming is done in plain Python

        @decorator comes to mind, and only the keyword is part of the language.

        Common Lisp has meta programming built-in but no one uses Common Lisp for a good reason.

        • solrize@lemmy.ml
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          2 days ago

          Common Lisp has meta programming built-in but no one uses Common Lisp for a good reason.

          I use Common Lisp, but maybe you’re right and my reason for using it is bad.