3 ms·
> I suppose you can look at Rust macros as a different, infrastructure language on top of Rust. That's a strange take, not one I've heard anywhere else. Rust m
by nindalf 4y ago
> I suppose you can look at Rust macros as a different, infrastructure language on top of Rust.
That's a strange take, not one I've heard anywhere else. Rust macros are code generators - they're run once at build time and generate regular Rust code that's strongly typed. Maybe it's because the author has a different interpretation of "infrastructure" than the commonly accepted one.
- danpalmer 4y agoI can understand this take, Rust macros run at a different time, with different constraints, and are used to solve different problems. In many ways that may feel like a different language. However, a more technically correct interpretation would likely divide based on hygienic vs unhygienic macros. The C Preprocessor is most definitely a different language to C – it has the same differences as Rust/Rust Macros do, but additionally is implemented by a different binary, is de-coupled from the C language to some extent, and most importantly, has different syntax and semantics making it actually a different _language_ in the strict definition of the word.
- TechBro8615 4y agoI think the author really means "library code" (i.e. code where the "user" is another developer). He also alludes to such code using metaprogramming which makes internal type hints hard to implement. In this context, macros can be seen analogously to meta programming, or "infrastructure code" to use the terminology of OP.
- pg_1234 4y agoAs with Rust and macros ... it would be more accurate to say Python is one language that can be used in two ways/modes ... as fits your needs. If anything this is just a sign of a more versatile language.
- ptsneves 4y agoJust checked PEP3107 and PEP484 and type hints are not taken into account at runtime[1]. > While these annotations are available at runtime through the usual __annotations__ attribute, no type checking happens at runtime. At first I thought it was disproving the commenter's "strange take" assertion but it actually proves him right. While it is true that python's type hints are a build time feature like in Rust, they do not generate code for the interpreter in the way Rust does. Actually they do not generate anything besides metadata that can be interpreted (at build time) in any way undefined way. The undefined is explicit. I personally liked the article and agree that eventually the undefined specification of the PEP will be removed and a new language a-la Typescript will emerge. [1] https://peps.python.org/pep-0484/ https://peps.python.org/pep-0484/