lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Mon, Aug 19, 2013 at 12:37 AM, Coda Highland <chighland@gmail.com> wrote:
On Sun, Aug 18, 2013 at 11:41 PM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Mon, Aug 19, 2013 at 1:02 AM, Tim Hill <drtimhill@gmail.com> wrote:
> implicit rather than explicit parameter indexing, which makes
> localization much harder (you can't change order in the format string
> to match language needs w/o changing the argument order to the call as
> well).
>
> Which is why C# uses "strings {1} like {0]" (these can contain extra modifiers).
>
> printf-like flags live on in string.format, but in Lua not such a
> problem, since the runtime errors tend to be clearer..  Making up
> other 'little languages' like "$(boo) is $(foo)" (or the above C#
> style) is an easy exercise of course.  The best we can do is check
> these strings early, and fail hard.  This is inconvenient, since we
> then cannot have them inline, unless some there's some preprocessor
> (and that seems overkill)
>
> Modern C compilers do check (and complain bitterly about) printf flags at least.
>
> C++'s << still seems an elegant solution, but you need to have a feel
> for how the overload set of << operates with your types, especially
> when adding an overload for a new type.
>

C++'s << is nice, but doesn't address reordering parameters for localization.


While I couldn't remember where I read it from, but stream operator overloading didn't turn
out to be a so-good solution because implicit type conversion could give you the "wrong"
result and it's easy to write something like this

ostream& foo(ostream &os, Obj* obj) {
   return os << obj;        // instead of os << *obj
}

without being given any warnings.

/s/ Adam