Exceptional coding style

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jan 15 08:00:45 PST 2013


On Tue, Jan 15, 2013 at 11:23:40AM +0100, FG wrote:
> On 2013-01-15 09:29, monarch_dodra wrote:
> >I still prefer "writeln" over "writefln". While writefln issafe, you
> >can still botch the amount of args, and or flag types, in which case
> >writefln will throw. Writeln never throws (due to a code error).
> 
> What about the argument that a format string makes translation easier?

Current format string syntax still has a ways to go before it can make
translation easier. Consider this example:

	writeln("%s is found in %s", file.name, dir.name);

Sounds ideal for translation, right? Except that it's not. First,
reading the format string alone says nothing about what meaning is
intended. What is found in a what? Also, it doesn't let you vary the
word order correctly. Nor does it let you perform inflection correctly.

For true ease of translation, you need:

1) Logical naming of format arguments, e.g.:

	"%{filename} is found in %{dirname}"

and of course, some way to associate logical names with actual
arguments.

2) Some way to indicate the function of each word so that inflection can
be cone correctly, e.g.:

	"%{filename.nominative} is found in %{dirname.locative}"

or something like that, in languages where words change form depending
on function. There will, of course, need to be requisite mechanisms for
interpreting these word function identifiers.

3) Some way to indicate multiplicity:

	"1 file was found" vs. "2 files were found"

would require the quantity of files to be passed to the formatting
function so that the appropriate translation can be selected. Keep in
mind the different languages have different rules as to how to map
quantity to word forms; just because English has only two forms
(singular, plural) doesn't mean that that's enough. Russian, for
example, requires 3 distinct forms: one for singular, one for numbers
2-4, a third for 5 onwards (with the second form recurring for selected
subranges of the latter).

Current format strings are far from making translation truly easier.


T

-- 
Philosophy: how to make a career out of daydreaming.


More information about the Digitalmars-d mailing list