|
Notorious b.s.d. posted:no one is ever tempted to do the latter in about a decade of using languages with operator overloading i don't think i've ever actually encountered a stupid operator overload that actively mislead me while reading code (at most, i've encountered stupid operator overloads that made it very clear that i didn't know what the code did without digging in further), but i've encountered a whole fuckload of normal functions with misleading names that did something completely unlike what the name suggests. sometimes the obvious non-operator name isn't wrong, but is ambigous. does list.append() mutate the list, or return a new list with the object added? depends on what language you're using, because i've encountered both. list + x obviously returns a new list, and list += x obviously mutates the list.
|
# ? Mar 5, 2016 18:22 |
|
|
# ? May 25, 2024 22:06 |
|
fleshweasel posted:another thing with operator overloading is: it's totally undiscoverable with IDE autocomplete, so people are probably just going to use the method version of it anyway. i think this actually leads to a good rule of thumb for when to define operator overloads. if the overload actually makes sense, then you don't need discoverability since it's what the programmer will try first before looking for a method. if no normal user would just naturally start with writing a + b or a[b] and then get annoyed when that doesn't compile, then the operator is probably not a good name for that function.
|
# ? Mar 5, 2016 18:26 |
|
operator overloading is dumb because of precedence rules that constrain how you can create your dsl or whatever. haskell is the only one to get this right by letting you actually define arbitrary operators with your chosen fixity and binding rules. scala is actually the worst because it lets you define arbitrary operators but it picks precedence based on the first character.
|
# ? Mar 5, 2016 18:39 |
|
Barnyard Protein posted:does someone have an article or rundown of the reasons operator overloading is bad? i have an intuitive feel of why its a bad thing, but i'd like to be well-versed in the reasons. a coworker was excitedly talking about operator overloading being a thing in java9 considering there is not a single jep related to operator overloading your coworker has no idea what he's talking about hth
|
# ? Mar 5, 2016 18:47 |
|
fleshweasel posted:another thing with operator overloading is: it's totally undiscoverable with IDE autocomplete, so people are probably just going to use the method version of it anyway. i dont feel up to firing up an ide but wont it have full type info available, unless youre in something like python
|
# ? Mar 5, 2016 18:48 |
|
it will type check your usage of the operator, but the typical way of finding functions that use a particular value is by hitting . and scrolling through the menu that pops up
|
# ? Mar 5, 2016 18:51 |
|
FamDav posted:scala is actually the worst because it lets you define arbitrary operators but it picks precedence based on the first character. wait what?
|
# ? Mar 5, 2016 18:51 |
|
Also typically method names will be easier to disambiguate when you're casually browsing some code, as opposed to the canonical Scalaz examples from a few years back, and some HTTP library name whose name I forgot, where you need to know the difference between operators =, ~=, ~, ~~, ~~# and whatever else.
|
# ? Mar 5, 2016 18:54 |
|
jony neuemonic posted:wait what? http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#infix-operations
|
# ? Mar 5, 2016 18:56 |
|
operator overloading is fine and people complain about it too much. most of the complaints i see are either entirely hypothetical or people being scared of how a language they haven't used looks at first glance.
|
# ? Mar 5, 2016 19:02 |
|
the project that is going to keep scala relevant for a solid decade (apache spark) has a style guide that eschews most of the scala feature set. its the equivalent of the google c++ style guide. they've also done a lot of work to refactor things to make even less use of features like implicits, and that kind of mentality is pushing into things like breeze because real people don't want to deal with that junk.
|
# ? Mar 5, 2016 19:05 |
|
f# set overloads + for union and - for difference which is way more readable especially in the case of difference when I'm always wondering which set is getting subtracted from
|
# ? Mar 5, 2016 19:08 |
|
like ten years ago some dude i looked up to at the time showed me a C++ DSL he made with operator overloading that concisely constructed gtk windows with various widgets in them. It was pretty rad, dude's rad.
|
# ? Mar 5, 2016 19:13 |
|
a.add(b) sending an email makes perfect sense b/c it sends b a notification that a added them to their contact list. duh.
|
# ? Mar 5, 2016 19:14 |
|
Barnyard Protein posted:does someone have an article or rundown of the reasons operator overloading is bad? i have an intuitive feel of why its a bad thing, but i'd like to be well-versed in the reasons. a coworker was excitedly talking about operator overloading being a thing in java9 Shaggar posted:operators have well understood meanings in some contexts (ex: adding ints, concatenating strings) but outside of that they could mean anything (ex: Person a + Person b =???) qntm posted:sometimes I overload subtraction to undo concatenation CPColin posted:Is that properly anticommutative? That is, does "DEF" - "ABCDEF" return "-ABC"?
|
# ? Mar 5, 2016 19:17 |
|
FamDav posted:http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#infix-operations scala is amazing
|
# ? Mar 5, 2016 19:22 |
|
AWWNAW posted:f# set overloads + for union and - for difference which is way more readable especially in the case of difference when I'm always wondering which set is getting subtracted from a.Except(b) is a good way to spell it
|
# ? Mar 5, 2016 19:24 |
|
lol, not only is precedence defined by the first character of the operator, but associativity is defined by the last character. imagine if someone asked you to come up with an operator precedence/associativity system. would you have ever thought of this?
|
# ? Mar 5, 2016 19:26 |
|
its probably entirely coincidental behavior
|
# ? Mar 5, 2016 19:27 |
|
Sagacity posted:Also typically method names will be easier to disambiguate when you're casually browsing some code, as opposed to the canonical Scalaz examples from a few years back, and some HTTP library name whose name I forgot, where you need to know the difference between operators =, ~=, ~, ~~, ~~# and whatever else. spray. fuckin spray also sbt basically scala is an extended lesson in why operator overloading is bad
|
# ? Mar 5, 2016 19:28 |
|
fart simpson posted:imagine if someone asked you to come up with an operator precedence/associativity system. would you have ever thought of this? i would bury this person in an unmarked grave and we would never discuss it again it was a hard design decision but it had to be done
|
# ? Mar 5, 2016 19:29 |
|
personally i'd be okay with operator overloading if it was only used to overload pure functions but then i'd have to trust other programmers to only overload pure functions and no one would ever use my operator overloads because they would be suspicious of them so it's not worth it
|
# ? Mar 5, 2016 19:41 |
|
i am working on a query library and i have a thing off to the side that lets you write π, σ, etc for project, select and so on but i'm never going to include it
|
# ? Mar 5, 2016 19:44 |
|
qntm posted:sometimes I overload subtraction to undo concatenation "ABCDEF" - "DEF" = "ABC", and so then "ABCDEF" - "E" = "ABCDEFinv(E)"
|
# ? Mar 5, 2016 19:53 |
|
MALE SHOEGAZE posted:personally i'd be okay with operator overloading if it was only used to overload pure functions but then i'd have to trust other programmers to only overload pure functions and no one would ever use my operator overloads because they would be suspicious of them so it's not worth it looks like haskell wins again
|
# ? Mar 5, 2016 20:02 |
Just because some people misuse operator overloading doesn't mean that operator overloading itself is bad. People will misuse literally every feature you give them, and just because someone has used operator overloading on their email class doesn't mean that using operator overloading on your quaternion class is bad. Personally I think Haskell does operator overloading right. For example, in order to overload the + operator, you need to define the ways in which your type is a numeric type. So you can easily overload the + operator for quaternions, but not for emails. (You can also define a whole new + operator, but then you have to specify which one you are using every time so no one does that.)
|
|
# ? Mar 5, 2016 20:16 |
|
VikingofRock posted:Just because some people misuse operator overloading doesn't mean that operator overloading itself is bad. People will misuse literally every feature you give them, and just because someone has used operator overloading on their email class doesn't mean that using operator overloading on your quaternion class is bad. yeah, typeclasses handle this really well. if you want to overload + you have to overload *, abs, signum (sign), fromInteger, and negate. prevents the worst abuses of oo because overloading + can only sensibly be done on something resembling numbers.
|
# ? Mar 5, 2016 20:27 |
|
HappyHippo posted:yeah, typeclasses handle this really well. if you want to overload + you have to overload *, abs, signum (sign), fromInteger, and negate. prevents the worst abuses of oo because overloading + can only sensibly be done on something resembling numbers. code:
1.0 in fairness this is mostly a joke, i've never seen it actually used other than in irc's lambdabot
|
# ? Mar 5, 2016 21:48 |
|
KARMA! posted:php has this as well or the prettiest option: print "call me ".$foo." man";
|
# ? Mar 5, 2016 22:03 |
|
VikingofRock posted:Just because some people misuse operator overloading doesn't mean that operator overloading itself is bad. People will misuse literally every feature you give them, and just because someone has used operator overloading on their email class doesn't mean that using operator overloading on your quaternion class is bad. yes, all syntactic features are a tradeoff between use and abuse. operator overloading offers minimal benefits, but creates a lot of temptation to abuse the language. it's just not worth it. i would be perfectly happy to write "2.plus(2)" the rest of my days if it means i never have to look at a fuckup like "cout << dongs << butts" ever again
|
# ? Mar 5, 2016 22:09 |
|
Sagacity posted:Also typically method names will be easier to disambiguate when you're casually browsing some code, as opposed to the canonical Scalaz examples from a few years back, and some HTTP library name whose name I forgot, where you need to know the difference between operators =, ~=, ~, ~~, ~~# and whatever else. loving dispatch
|
# ? Mar 5, 2016 22:15 |
|
Notorious b.s.d. posted:yes, all syntactic features are a tradeoff between use and abuse. operator overloading offers minimal benefits, but creates a lot of temptation to abuse the language. it's just not worth it. 1) oo offers great benefits when you actually need it because poo poo like adding vectors is downright painful when it isn't available 2) the temptation to abuse it is actually quite low - the syntax is often more complex and you often need to overload a bunch of operators. most people dont go through the trouble unless they really want it. 3) writing "2.plus(2)" is moronic. anyone who would want that just to prevent the c++ stream overloads (which aren't that bad) is insane. do you have ocd or something? i seriously dont get why people get so drat upset over operator overloading of all things. its not that big a deal, even when it's misused.
|
# ? Mar 5, 2016 23:50 |
|
go look at a page of scala code
|
# ? Mar 5, 2016 23:58 |
|
Bloody posted:go look at a page of scala code ok so scala does it wrong (idk i dont use scala)? being poorly implemented in one language doesnt mean much
|
# ? Mar 6, 2016 00:04 |
|
java hosed up generics doesn't mean generics are bad. in fact they're good
|
# ? Mar 6, 2016 00:06 |
|
Pythong
|
# ? Mar 6, 2016 00:10 |
|
uncurable mlady posted:r# taught me you can do string formatting like this - the downside of string interpolation is that it's harder to localize you need to be able to have "call me {foo} man" (or equivalent) act as the key, and then have the replacement happen in the localized string, and have that be as transparent as possible to the developer
|
# ? Mar 6, 2016 00:54 |
|
Notorious b.s.d. posted:operator overloading creates the temptation to do really stupid poo poo and there's always some idiot who gives in c4_View c4_View::operator,(const c4_Property &) const
|
# ? Mar 6, 2016 00:58 |
|
FamDav posted:operator overloading is dumb because of precedence rules that constrain how you can create your dsl or whatever. haskell is the only one to get this right by letting you actually define arbitrary operators with your chosen fixity and binding rules. scala is actually the worst because it lets you define arbitrary operators but it picks precedence based on the first character. Lisp gets this even more right than Haskell by just always using prefix notation (except in loving loop of course)
|
# ? Mar 6, 2016 00:59 |
|
|
# ? May 25, 2024 22:06 |
|
VikingofRock posted:Just because some people misuse operator overloading doesn't mean that operator overloading itself is bad. People will misuse literally every feature you give them, and just because someone has used operator overloading on their email class doesn't mean that using operator overloading on your quaternion class is bad. you will believe this right up until you actually have to use their email class in a project
|
# ? Mar 6, 2016 01:02 |