Re: [Vala] Operator overloading





2009/3/25 William Swanson <swansontec gmail com>
A locked-down implementation that supports only the
basic math operators (+ -  * / %), forces those operators to be
"const" to eliminate side effects, and forces the assignment operators
(+= -= *= /= %=) to behave predictably


Obligatory notes here:
- Vala doesn't have const. I has/will have 'pure'??
C# (somewhat) solves this by obliging the operators to be public static functions (just like extension methods - only public access)

- +=, -=, *= etc. are usually overloadable for performance reasons. I agree this should stop being the case as many more bugs would come from incorrect implementation. (..but .. C# lets you use them, if the binary +, -, * etc. are implemented, or overload them if necessary)

In general, I agree with the opionions here of making operator overloading available.

However, beware how much you 'cut' them down, because in 10 years from now, there will be books on Vala saying "dont use + on strings, use StringBuilder.append (str1). append (str2) etc." just like Java ended.

Vlad


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