Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Operator Overloading

Name: Faggot 2010-06-23 17:00

So, I like operator overloading, but I know people who DETEST it. I realized that the reason that I like operator overloading is that I like to write basic types. So I was thinking: What intrinsic types would a language have to provide such that users of that language would never want to create their own? My ideas thus far:

INTEGER - big integer, of course, that does not overflow.
FIXED - a scaled big integer in a wrapper, for when a float is overkill
FLOAT (REAL) - an arbitrary precision floating point number (base 10, of course)
COMPLEX - a pair of REALS, or some complex system (pun not intended) like C99

STRING - a managed array of UTF-32 codepoints, NUL terminated; a normal string class with the exception of the encoding
BUFFER - a managed array of machine types, defaults to unsigned bytes. The only way to have standard (C program) types is if they are boxed in a buffer.

BOOLEAN - it'll still see use

So, what do you think, /prog/, with these seven types (and arrays of them and classes to aggregate them, of course), would you want to overload operators? For those of you who like operator overloading, of course. What sorts of types am I missing?

Name: Anonymous 2010-06-23 17:06

Operator overloading in SEPPLES is problematic because it obscures functionality under another more familiar syntax, and it's also a pain to debug for similar reasons.

If everything is inspectable and the syntax is uniform and simple, I don't see the problem with it.

Name: Anonymous 2010-06-23 17:18

VECTORS

Name: Anonymous 2010-06-23 17:24

Oh I know what you missed, you missed file streams that you shift by data you want to pass to them. This was such a clever idea Bjarne. Every language needs this.

Name: Anonymous 2010-06-23 17:25

>>1
People dislike operator overloading because some geniuses like doing stuff like overloading * for strings to mean caesar encoding or whatever.
I guess the main reason people do that is that they want to write terser expressions, but the language doesn't provide a way of creating new operators (like Haskell does).
As for your original question, there are vectors (which I suppose could go under COMPLEX), and other mathematical types like quaternions or matrices.

Name: Anonymous 2010-06-23 21:17

>>5
vectors (which I suppose could go under COMPLEX)
You know vectors can have an arbitrary number of dimensions, right?

Name: Anonymous 2010-06-23 21:25

>>6
Not to mention that vector math and complex number math are completely different on account of the whole i2 = -1 deal.

Name: Anonymous 2010-06-23 21:32

>>6
No shit, sherlock. >>1 said something about a complex system, which I assumed could be extended to more than 2 items.
>>7
It's fine as long as you don't try to multiply vectors and instead implement functions for calculating the dot/cross products.

Name: Anonymous 2010-06-23 22:04

>>8
>>1 said something about a complex system, which I assumed could be extended to more than 2 items.
Since we were talking about complex numbers and the ``complex system'' was referring to the way complex numbers are implemented in C99, that's a brain-damaged assumption.

It's fine as long as you don't try to multiply vectors and instead implement functions for calculating the dot/cross products.
So basically, it's not.

Name: Anonymous 2010-06-23 22:21

Why the fuck do you think you need to store a termination character in a string? Are you fucking retarded.

You know a string no longer has any more bytes when you are at the end of the memory you allocated for bytes of the string's value.

Adding an extra 0 byte (or 4 0 bytes) to the end of your byte sequence is fucking retarded.

Name: Anonymous 2010-06-23 22:33

>>9
Hey bro, don't be so negative. We're all friends here.

Name: Anonymous 2010-06-24 3:39

I heard Java doesn't let you overload operators at all.

Name: Java 2010-06-24 3:42

>>12
hey say that to my face fucker not online and see what happens

Name: Anonymous 2010-06-24 4:25

>>13
Sure. Where can I speak to this ``face fucker'' of yours?

Name: Anonymous 2010-06-24 5:09

>>1
There are many more purely mathematical types that would make good use of operators. As others have mentioned, there are vectors, matrices, quaternions; there are arbitrary precision numbers (e.g. BigInteger); and any permutation of those (such as a 4x4 matrix of complex bigfloats).

However in my opinion, the best use of operator overloading is to overload operator[] for new container types. There are all sorts of different segmented arrays, trees, hashmaps, etc., and operator[] is absolutely the logical way of accessing them.

>>5
It doesn't bother me when people make bad operator choices. I generally just don't use such code.

Personally I detest operator overloading because operators can only fail via exception. Exceptions in my opinion are terrible for high-performance computing, which is exactly where you would benefit the most from overloaded operators. Higher level languages don't need operator overloading because they generally already provide you with a string concatenation operator and general-purpose containers; if you want to do math you're using the wrong language.

I occasionally wish C, or a similar language, supported operator overloading without exceptions; in other words you can only add an operator if you can guarantee it won't fail. This would make it easy to implement our own types. There are lots of types that would be commonly used such as fixed, complex, half-float, etc. that we could implement on our own in a way that they don't signal failure (such as implementing a NAN state). A large part of the reason Fortran is so popular in science still today is because it supported complex way back in 1958, when C didn't get it until 1999. We are really at the mercy of the standards committee here, so C is still not great for math.

These days you could of course use C++ instead, but then you get all the horrible baggage that comes with it.

Name: Anonymous 2010-06-24 6:10

>>14
inb4 overloading the " operator to embed a DSL inside C++

Name: Anonymous 2010-06-25 2:10

OVERLOAD MY ANUS

Name: Anonymous 2010-12-17 1:37

This post brought to you by the Gay Nigger Association of America

Name: Anonymous 2010-12-22 2:43

Name: Anonymous 2011-02-03 4:05

Name: Anonymous 2011-02-04 12:35


Don't change these.
Name: Email:
Entire Thread Thread List