• 10 Posts
  • 1.26K Comments
Joined 3 years ago
cake
Cake day: July 24th, 2023

help-circle





  • antonto196mistakes rule
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 day ago

    That sounds better than starting with the tree and no chest, meaning you have to do stuff like collect rainwater in a cauldron you made by killing a lot of zombies.








  • antonto196rule
    link
    fedilink
    English
    arrow-up
    9
    ·
    3 days ago

    If a man speaks his mind but has no youtube channel, is he really misogynistic?
    Tune in next week to bad philosophy, where we will conduct a survey among railway workers about pulling levers and a special guest will shows us how to stop bullets with math.


  • antontoRust@programming.devWhy is Rust so bare-bones?
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    3 days ago

    You can design a language where you don’t need to generate code to accomplish this.

    Other people have python scripts generate C, so having on in the same codebase and language is certainly an improvement.

    My question isn’t why this is necessary in Rust. My question is why Rust was designed such that this was necessary.

    Because otherwise the compiler team either also needs to maintain a huge amount libraries or cut corners and move things to runtime that really should happen at compile time.

    Someone mentioned elsewhere that this allows for compile-time type safety. I’m still trying to wrap my head around how that works.

    printf is a great example. According to the C type system, it takes a string and a variable amount of untyped arguments dependent on the content of the string, but that doesn’t actually describe the allowed arguments.
    Misusing printf like this printf("%s", 42); will get you a warning, but only because there is a special case for printf in the compiler. If you have your own function that does the same as printf, and you misuse the same way, you will find out by dissecting the core dump.

    In rust the format string gets parsed at compile time by a macro, which decides the type of each arguments that can than be checked by the compiler. Imagine printf(“%s %d”,…) created a function with the signature specialized_printf(char* agr0, int arg1), it would be impossible to pass the wrong types of arguments.

    Now that these tools exist people have gone further and made a library that checks SQL queries against the shema of a running database and causes a compile error if it doesn’t fit.