posted 11 years ago
fred has offered you a hard-coded solution, which one could say was a variation of a data-driven solution. It's very easy to understand and to modify. Yours is a procedural solution. If, for some reason, you wanted to adapt your characters at run-time, that might be a better approach ("better" being one of those words that get harder to be sure of the more you try to define them). I'd offer an intermediate scheme, where you could still use data to drive your output, and retain the easy-to-modify aspect, but have the data be read by something that uses it when you need it:
When run, this is the output:
There are a lot of things in this code I wouldn't do in a production setting, but this ought to give some idea how you can use a data-driven approach without hard coding.
Now, if you really want to make your head spin, think about what you'd have to do with the above to get the output to look like this:
"Il y a peu de choses qui me soient impossibles..."