Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> For example, I wish Rust allow:

What kind of problems would this solve? Not trying to be snarky, just to understand the feature.



What this example show is that you can't manipulate the "things" that are expressed in syntax as data, so you can't have the same way to deal with both types and values:

    struct Person{name:String} +  struct User{pwd:String} = FAIL!
    ["Person", ("name", "String")] +  ["User", ("pwd", "String")] = possible!
Because types are not even third-class, you need to resort to "hacks" like macros, generics and other stuff like that.

Now, what it solve? almost everything.

(you can see how this could work in static lang with Zig comptime https://kristoff.it/blog/what-is-zig-comptime/)

In short, you get what inheritance promise without the OO, easy reflection, easy code generation, simpler macro implementation, easy way to do generics, easy way to copy to/from different types that are almost similar (ie: structurally)...

The amount of stuff you will simplify is massive.

Some of this feel is what make the "dynamic" languages their power. Now making it work on static lang is more tricky (you wanna keep everything as if you were coding it by hadn't and the types all resolved at compile time) so is likely required to be restricted and only a second-order citizen, but it will make some much easier!


Seems like you want a code generator. For some problems I admit I have missed a proper, integrated code generator. C macros is, like you say, hacky.

However, personally I strongly dislike dynamic languages for anything beyond simple programs, ie <100 LOC. Gets way to hard to reason about the code, since you never know what a function returns. In Python for example I invariably end up sprinkling dir(...) all over when modifying code.

So it would have to be used sparingly I think.


You could add type hints.

I poke around in the pybindgen code base semi-often and it’s fairly large. No problems that would call for sparing use.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: