I did something similar for creating tables of subclasses for my muds wiki. I got fed up of writing them all out by hand, so I got the mud to generate a big block of text that I could just copy and paste.
Hey, that's why calculators were invented. You can do the math yourself, but it's easier and less time consuming with a computer/calculator/program, especially with large numbers like you have there. Nothing to be ashamed of, in fact it's rather an ingenious method of doing it IMHO.
Code writing code isn't a very novel concept. Well, maybe in C. I would suggest learning a simple scripting language to generate your C code if you actually do that very often. :p
I think a more interesting question would have been how do you generate the C function given an approximate table. :evil:
29 Oct, 2009, David Haley wrote in the 5th comment:
Votes: 0
I've often written code to generate code, but as Runter said usually the generator was in a scripting language. There's nothing wrong with it, although depending on what you're doing you might be generating a table when you could leave it as a formula in your code or something like that.
You can also think of it as compiling: given a simple and abbreviated representation of something, you need to generate a more explicit representation of something that you can feed to another system. I did this quite a bit when generating game rules that needed to be expressed in a logical language; the game generation was parametrized but the resulting structure had clear patterns that were far easier to just generate automatically.
Lol yeah I could have done it in Javascript or such a bit faster heh. I just happened to be in that window and went, hm, //blah, and I had them all nicely formatted and all heh.
There's nothing wrong with it, although depending on what you're doing you might be generating a table when you could leave it as a formula in your code or something like that.
I probably would have left it as a calculated function in the code.
What scripting language would be good for things like this? I've tried to automate the more repetitive parts of my code before, but I always find it takes too long to write the program.
10 Nov, 2009, David Haley wrote in the 11th comment:
Votes: 0
When I mentioned this:
I said:
I did this quite a bit when generating game rules that needed to be expressed in a logical language; the game generation was parametrized but the resulting structure had clear patterns that were far easier to just generate automatically.
I did it in Lua or Ruby depending on my mood at the time, and/or who else I was working with.
It requires a certain degree of comfort, though; if you're not proficient enough with the scripting language you might as well write the code by hand and use editor-fu (copy/paste, replacing, regular expressions, etc.) instead of scripting-fu.
So I added it to my fishing code as an argument (it'll be the first 'craft' type skill).
Which, with a little help, yielded:
(101, levels of it, level 1 is 0)
Anyone else do this kind of stuff to write your code if it involves computation and arrays like that? I felt kind of… dirty ;p.