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

Pages: 1-4041-

Operator Overloading

Name: Anonymous 2007-08-19 22:01 ID:cGHmVo4b

What are your opinions? Use or don't use?

Name: Anonymous 2007-08-19 22:07 ID:KXz8ON7O

hate it

Name: Anonymous 2007-08-19 22:09 ID:lCZI2Fvf

Yeah. Code better do what it says it does, and not some special meaning of "->". This is why Java eats C#'s beans, for instance.

Name: Anonymous 2007-08-19 22:15 ID:FIY38YPQ

>>2
>>3
Newbs

as with everything else use when appropriate

for example it makes perfect sense to overload for example + on a vector class/structure so that you can do
a + b
instead of some shit like addvectors(a, b)

Name: Anonymous 2007-08-19 22:36 ID:Heaven

>>4
Or in Java style, a.addVectors(b).

OH GOD I JUST WROTE SOMETHING THAT RESEMBLES JAVA CODE *kills self*

Name: Anonymous 2007-08-20 5:41 ID:caKSnTZI

>>1
Why not. Operators are just syntactic sugar for functions. As long as your language is powerful enough to let you use them like functions and overload them, and it's not shitty enough to perform automagic shitty type conversion that will always make everything fail, you should be alright.

There are cases where operators are the right thing to use. For example, type comparison. You always use the equality symbol, which is usually == in your programming language, to test for object equality, so == is a better name than equals or some other Java-like bullshit. It's always far more intuitive and easier to understand, not to mention shorter, to do a == b than a.equals(b) (UGH! THE JAVA SHIT!), and the infix syntax for == better reflects the fact == is a function of two operands and its operands are expected to be of equal/similar/compatible types.

Of course, don't make it Perl. The & operator shouldn't really hire a new employee or mop the floor, or eat the protagonist as in roguelike games. Just like you should name your functions properly, you should choose your operators properly, and if none fit, use a function.

Also, all of this is meaningless if you use Lisp.

>>2-3
Java fags

Name: Anonymous 2007-08-20 5:51 ID:ZqwQ7CSs

Java designers are apparently all idiots. "Oh noes, programmers could choose to use the '+' operator in places where it's semantically impropriate, so let's force everyone to write myint1.add(myint2) instead. Yay, the improved readability of code by preserving semantics by removing them. Yay, making all user defined classes second class citizens. Yay! After work, let's all go post comments on Youtube."

Name: Anonymous 2007-08-20 5:54 ID:ZqwQ7CSs

>>7
impropriate
That word, I do not think it means what I think it means.

Name: Anonymous 2007-08-20 9:15 ID:k/xjY8U4

Good, provided you don't do something stupid like overload + without knowing what a ring is.

Name: Anonymous 2007-08-20 9:20 ID:bqrd43DR

>>9
lol, knows what a ring is

Name: Anonymous 2007-08-20 10:35 ID:1Py8TuDr

>>9

STRING RINGS

Name: Anonymous 2007-08-20 11:51 ID:vL3VEjyD

>>4
Yeah, this is the first example people ever mention. I've never heard of any others.

Even with vectors, you're left with the question as to what kind of product operator*() on them produces. Cross or dot product? Whut? Can't overload on return type you know, have to pick one and have a named method for the other... oh noes, java-style code! The horror.

Perhaps I'm just jaded. But I quite prefer to read code that means what it says, rather than having to deduce types yourself, types that may have been declared two screenfuls up, and then go to the appropriate spot in the appropriate doxygen (or what have you) autogenerated piece of shit manual. With C, or Java? You have a tags file for the source at hand. You move your cursor on top of the function call you're interested in and press the magic key(s) your editor wants. Abracadabra!

And don't get me started on Boost.

Name: Anonymous 2007-08-20 11:57 ID:CejhsYus

>>9
Wow finally all my overloading rants have sunk in!

Except maybe a field would be safer (j/k)

Name: Anonymous 2007-08-20 13:12 ID:KS1jlx4H

i leik it
(+) :: Num a => a -> a -> a
a + b = a - b

Name: Anonymous 2007-08-20 14:38 ID:Heaven

>>14
+ = -

Name: Anonymous 2007-08-20 14:40 ID:Heaven

>>15
(+) = (-)

Name: Anonymous 2007-08-20 19:36 ID:4HOyBu5n

FUNCTIONS SUCK, GOTO, EXCEPTIONS OR GTFO.

Name: Anonymous 2007-08-21 3:54 ID:C+VUWDWz

>>9
Lord of the Rings?

Name: Anonymous 2007-08-21 16:20 ID:yjW80hpW

>>15,16
WAR IS PEACE
FREEDOM IS SLAVERY
ADDITION IS SUBSTRACTION

Name: Anonymous 2007-08-21 16:33 ID:p2mbYOw/

>>17
OKAY YOU FUQIN ANGERED AN EXPERT PROGRAMMER
GODFUCKIGNDAMN
FIRST OF ALL, YOU DON'T FUQIN KNOW WHAT A MAN PAGE IS
SECONDLY, THIS IS /prog/ DO NOT DEMAND USEFUL ANSWERS THE WAY YOU WANT THEM TO BE
THIRDLY PROGRAMMING IS ALL ABOUT PHILOSOPHY AND ``ABSTRACT BULLSHITE'' THAT YOU WILL NEVER COMPREHEND
AND FUQIN LASTLY, FUCK OFF WITH YOUR BULLSHYT
EVERYTHING HAS ALREADY BEEN ANSWERED IN
>>3,4,10

Name: Anonymous 2007-08-21 16:33 ID:Heaven

>>19
I think I love you

Name: Anonymous 2007-08-21 16:43 ID:smvwF6nT

>>20
(((ok bitch)
  (you asked for it)
  (here goes))
 (im taking out the fucking
     (bold paranthesis on you))
 (you fuqing angered an expert programmer)
 (ive been here for (expt 3 88888000) years longer than you)
 (ive read sicp twice)
 (i know every programming language in the world
    including apl)
 (if u wanna batl (lets do it))
 (ill crush you like a bean))

Name: Anonymous 2007-08-21 21:52 ID:uxigH/pi

balls

Name: Steve 2007-08-21 22:14 ID:m/TGRrB1

I have to go with Balls on this one

Name: Anonymous 2007-08-22 1:10 ID:zEulPfCH

ass += penis

Name: Anonymous 2007-08-22 9:07 ID:JH+D5PTH

>>25

for all n > 0 ?

Name: Anonymous 2007-08-22 10:45 ID:mYG40BWW

uxigH divided by pi = ?

Name: Anonymous 2007-08-22 11:15 ID:Heaven

Name: Anonymous 2009-03-06 8:36


fucking turing machine does?

Name: Anonymous 2009-03-06 9:09


- Quick hacks Perl.

Name: Anonymous 2009-11-13 8:12

overload my anus

Name: Anonymous 2009-11-13 9:19

>>6
infix
better
:(

Name: Anonymous 2009-11-13 9:58

>>32
cool 2-year reply, bro

Name: Anonymous 2009-11-13 12:54

GOTO Topic

Topic:
I'm ambivalent about operator overloading.  I have always thought there should be serious consideration involved before one creates a local disambiguation of, most commonly, simple arithmetic operators.  The extended "==" tends to be good, but that just goes into the second point: overloading an operator is essentially the same as writing a function/method, so why not just write a function/method?  Neither design promotes readability of code as you still have to scroll through it to find the overloading or the method implementation at least once.  And, in compiled code, it doesn't matter (I don't think so anyway; feel free to correct me on this).

On the other hand, operator overloading does promote heuristic readability.  Programs that use vector math, or any kind of math, can look much more logical if the code looks closer to what you were taught in school.  I can't count the number of times I exchanged 'pow' for '^', for example.  If this is the case, however, then does my argument become "operator overloading is a nonessential feature preserved for the benefit of the programmer?"

I'd rather not the reason be that trivial if I can afford it.

Name: HASKELL MEME FAN 2009-11-13 12:59

I do not distinguish operators from functions because I am not a faggot.

Name: Anonymous 2009-11-13 13:05

>>34
operator overloading is a nonessential feature preserved for the benefit of the programmer
As is everything, really. You can choose to program in machine code, I'll invent some new operators in Haskell.

(~>) :: a -> (a -> b) -> b
infixl ~>
(~>) = flip ($)

data Person = Person {
              address :: Address
            , age :: Integer
            } deriving (Show)

data Address = Address {
               street :: String
             , house :: Integer
             } deriving (Show)


And now given p :: Person you can do
p~>address~>street
OOP IN HASKELL

Name: LISP MEME FAN 2009-11-13 13:05

I, too, do not distinguish operators from functions because I am not a faggot.

Name: Anonymous 2009-11-13 13:21

>>9
Point being? Even floating point addition is not commutative.

>>12
As with everything, you have to be mindful of the domain you're working in. Even in mathematics a product can mean any number of different operations as long as they follow a set of rules. C++ has roots in academics so it's not surprising the language allows for something akin to a Hilbert space definition.

Name: Anonymous 2009-11-13 13:35

>>38
I'm >>12 and what is this

Name: Anonymous 2009-11-13 13:50

>>36
Being able to access a record field through an operator does not OOP make.

Also, that isn't operator overloading, it's operator creation, and that distinction is relevant because one of the things people bitch about operator overloading is that unrelated meanings can be associated with existing operators (which   , as a sidenote, Haskell's type class system makes extra hard to accomplish).

Name: Anonymous 2009-11-13 16:18

Guide to Function Naming in Haskell

  1. Think about what the function does.
  2. Ignore it.
  3. Select a random 2–3 character sequence that looks pretty to you.
  4. Check if anyone anywhere has used this sequence.
  5. If so, return to step 3.
  6. Congratulations!  Enjoy you're new function.

Name: Anonymous 2009-11-13 16:20

>>41
For additional fun, you may append the str prefix, and you have the C string functions!

Name: Anonymous 2009-11-13 16:21

>>41
I hate this so much.

Name: Anonymous 2009-11-13 16:28

>>41
I actually do that, except I use a single letter for variables and three for functions.

Name: Anonymous 2009-11-13 16:35

Use nonsensical hexadecimal strings for all variable names, function names, objects, and methods, even file names.  Watch grown men break down and cry.

Name: Anonymous 2009-11-13 16:41

People still use variables? What is this, the 80s?

Name: Anonymous 2009-11-13 18:07

>>45
No no, at least use sensical hexadecimal strings.

Name: Anonymous 2009-11-13 18:43

i use ciphertext for functions names, generated from a sensible plaintext name.

Name: Anonymous 2009-11-13 19:41

I use UNICODE. For instance, ☺ is my standard name for the recursive factorial. ⌤ is recursive fibs.

Name: Barack Obama 2009-11-13 20:00

>>49
I'm Barack Obama and I approve of this.

Name: Anonymous 2009-11-13 20:16

>>50
*Nigger

Name: Barack Obama 2009-11-13 20:18

>>51
*Republican

Name: Anonymous 2009-11-13 20:20

>>41
[citation needed]

Name: Anonymous 2009-11-13 20:52

>>53
<$>

Name: Anonymous 2009-11-14 10:40

>>53
A few operators out of thousands of functions don't constitute a pattern of behavior.

Name: Anonymous 2009-11-14 10:40

s/3/4/

Name: Anonymous 2009-11-14 10:45

CITE MY ANUS

Name: Anonymous 2010-12-17 1:18

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

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