Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)C
Posts
2
Comments
10
Joined
2 yr. ago

  • The term “meta-programming” had me lost since I’m only familiar with that in reference to C++ templates (and Rust’s generics are more like templates).

    Yes, like C++ template and macros. The kind of code that generates new code before being run.

    So to answer your question as to why there are macros, it’s because you need to generate code based on the input. A function call can’t do that.

    You can design a language where you don't need to generate code to accomplish this. My question isn't why this is necessary in Rust. My question is why Rust was designed such that this was necessary.

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

  • 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.

  • C++ was my first programming language. I remember the nightmare of dealing with dependencies and avoiding boost because it felt wrong to need a third part library for basic features. The toolchain for Rust is very nice (not just compared to C++, but all other languages I've worked with) and has so far been a huge joy to work with. The language itself too. I'm just curious about why the language likes to expose more of its features through meta-programming rather than directly in the language itself. Things like println! and format! being macros instead of functions, or needing a bunch of #[derive(Debug,Default,Eq,PartialEq)] everywhere for things that other language provide through regular code.

  • I'm not talking about what features are in the standard libraries vs third party libraries. I mean meta-programming as in the stuff that generates Rust code. Take console printing for example, we use a macro println! in Rust. Other languages provide an actual function (e.g. printf in C, System.out.println in Java, print in Python, etc). The code for my first project is also full of things like #[derive(Debug,Default,Eq,PartialEq)] to get features that I normally achieve through regular code in other languages. These things are still in the Rust standard library as I understand it.

  • Rust @programming.dev

    Why is Rust so bare-bones?

  • That's also to make programming easier. Different programmers have different needs.

  • But the main benefits of static typing is in making the programming part easier. What do you gain from translating dynamically typed languages into a statically typed language?

  • A trick I've employed is to pretend to believe in something completely different. If it says "no, you're wrong" and goes on to tell me what I actually believe, then it's a good indicator that I might be on the right path.

    • Specific heat capacity of water: 4.184J/(gC)
    • Average shower temperature: 37C
    • Cold tap water temperature: T
    • Shower head output: 2gallon/min = 7.57L/60s = 126ml/s = 126g/s

    1s * (126g/s) * (4.184J/(gC)) * (37C - T) = 524J/C * (37C - T)

    120Wh = 432000J

    T = -787C

    So I guess the math checks out if your city's water supply temperature is way below absolute zero.


    Scratch that, let's assume the water actually flows, so T=0C. What water throughout do we need to achieve this level of power consumption?

    1s * (X g/s) * (4.184J/(gC)) * (37C) = 432000J

    X = 2791g/s = 44gpm

    You would have to be showering with 17 showerheads simultaneously using showerheads that are rated at the highest legal flow rates in the US (2.5gpm).

  • Programmer Humor @programming.dev

    MAKE IMPORTING GREAT AGAIN!

    github.com /hxu296/tariff
  • Early 30s now. I've been on this path since I was 18, so I guess I'd be happy to hear that I stuck with it. I'd probably also be disappointed to hear that I'm actually kind of bad at it.