[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: ++ and +=
- From: Craig Barnes <craigbarnes85@...>
- Date: Wed, 19 Feb 2014 17:27:15 +0000
On 19 February 2014 16:56, Steven Mak <firstname.lastname@example.org> wrote:
> Hi all,
> Can I know why there is no such operators as ++ or += (or similarly others
> like string concatenation) in Lua? What are the better alternatives instead
> of writing it in full "x = x + 1" or "this_string = this_string .. "Another
> string ""?
One of the reasons is that each new operator would require a new
overload metamethod. In Python for example, you need
separate overloads for x = x + y and x += y (__add__ and __iadd__).
Python has 13 of these extra, largely redundant overload methods.
Each new operator also needs a new opcode and makes the
Using a string buffer or rope is often more appropriate if you find
yourself doing a lot of string concatenation.