|
|
|
|
|
by hartcw
4053 days ago
|
|
Although I don't use go (yet), I can see the benefit of this mechanism as I use a similar one for my own c/c++ code. There I use specially tagged comments to embed python in the c/c++ sources, and then run all the code through a python interpret stage to expand/execute the python code before compiling it. Actually it supports C macro style for the embedded code, which is a bit more sensible than misusing code comments. For example for generating a c/c++ enum: enum example_t
{
#py \
for line in open('values.txt'): \
print('EXAMPLE_' + line.strip() + ',')
EXAMPLE_Max,
EXAMPLE_Unknown
};
Or alternatively to stuff it in a comment: enum example_t
{
/* py
for line in open('values.txt'):
print('EXAMPLE_' + line.strip() + ',')
*/
EXAMPLE_Max,
EXAMPLE_Unknown
};
If anyones interested, heres the python script I use to preprocess the c/c++ files https://github.com/hartcw/cppy |
|
They should have copied Java's annotation model which makes a lot more sense.