-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiletime reflection #43
Comments
I'm not sure yet. Reflection is slow and can result in runtime errors. I think I'll implement it with codegen, just like json decoding. |
if it would be something like c#'s it would be awesome,
|
I could see value in static reflection or a compiler API at some point. @medvednikov As you point out, this could generalize your json support (which some people won't want to use anyway, as more efficient serialization methods exist). But I agree that runtime reflection is at odds with V as I understand it today. |
The syntax I have in mind:
What do you think? |
@HedariKun about your suggestion. vweb framework will have the following syntax:
|
const fields = T.fields
for field in fields {
const id = field.name
if field.type == 'string' {
result.$id = get_string(data, field.name)
} else if field.type == 'int' {
result.$id = get_int(data, field.name)
}
} I renamed else if is_uppercase(field.type[0]) {
const type = field.type
result.$id = decode<$type>(data)
} For arrays we can check |
We could call |
|
V can be smarter with struct fields:
Compile-time coding is tough, I want to make it as simple and light as possible. |
Maybe to make this more consistent and simpler:
|
Even better:
|
the later syntax seems better, also it is nice that the vweb will have that type of syntax but wouldn't it be good if we can make our own, like having ['something'] can also be used when creating other stuff, maybe discord bot and you specify the command name between [] or some other custom thing. |
|
oh neat~ |
I think requiring $for field in T.fields {
$if field is SomeType { Let's define what's happening. Here I'd call field a symbol alias as it's not a value. $field means use the field name as an identifier token in code. For
See also #205 for some more compile time code generation. |
Of course this could be The reason I prefer |
I agree, compile time |
What I would like from meta functionality in compile time:
This would allow me to implement e.g. this:
|
Update: |
Here I propose some new compile-time features for reflection and update the docs: #5962 |
I thumbs-downed this feature request, unless someone can explain why repeating Go’s design error will not be a problem for Vlang? Runtime reflection in Go ostensibly was a design error that continues to have egregious implications they apparently did not contemplate when it was designed into the language:
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
will it have reflection ? if yes is it the same as go?
The text was updated successfully, but these errors were encountered: