Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Jabor
Jul 16, 2010

#1 Loser at SpaceChem

eschaton posted:

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

it's no harder than string concatenation

the only reasonable localization apis end up being of the form getLocalizedString("there are %d butts", nButts)

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
the "problem" is mostly just that string formatting is usually more readable than string concatenation, so when those are your only options, even people that don't give the slightest gently caress about localization are usually happy with converting everything to use string formatting, but when you ask them to give up string interpolation there'll be a bunch of grumbling and unhappiness

Soricidus
Oct 21, 2010
freedom-hating statist shill
just require your users to learn english imho, they'll thank you for it later

Notorious b.s.d.
Jan 25, 2003

by Reene

eschaton posted:

Lisp gets this even more right than Haskell by just always using prefix notation

(except in loving loop of course)

the loop macro is a perfect example of why macros are dangerous

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Soricidus posted:

just require your users to learn english imho, they'll thank you for it later

shaggar alt spotted

Soricidus
Oct 21, 2010
freedom-hating statist shill
i've literally shipped non-localized software to a customer where half the people didn't speak english, on the basis that the guy who knew english could tell the others what to click when

they were happy with this as an alternative to paying for localization

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
operators should only describe basic mathematic operations

everything else should be String.concat(a, b) or a.concat(b) or w/e

because gently caress, if + means concat, what else does it mean? where's that defined?

and the answer is invariably line 13433 of a utils lib that's in every project and takes hours to hunt down

programmers like to think they're clever but 90% of them are dumbshit fuckwads who don't understand that the cleverest thing is to say what you mean and mean what you say. verbosity should be encouraged because the opposite is expensive when onboarding or maintaining code

VikingofRock
Aug 24, 2008




Other examples of appropriate operator overloading include smart pointers overloading operator-> and operator*, and container classes overloading operator[] (although the latter does have the occasional slightly-dumb design decision, like of C++'s std::map's operator []).

Shaggar
Apr 26, 2006

Soricidus posted:

just require your users to learn english imho, they'll thank you for it later


hackbunny posted:

shaggar alt spotted

Bloody
Mar 3, 2013

Soricidus posted:

just require your users to learn english imho, they'll thank you for it later

suffix
Jul 27, 2013

Wheeee!
some people don't get that '+' means something the way 'Add' means something, so you get dumb poo poo like 'shift standard output left by "hello world" bits', and 'divide pathA by pathB'

so for each library you get to learn dumb mnemonics like "* looks kind of like a hub", or "@<@ points to the indexing we want to preserve" because the author sees the operators as a smorgasbord you just randomly assign based on loose visual associations without caring about semantics

without custom operators you get "we overloaded +,-,*,/,%,&,| as shorthand for the methods on this car class"
and in haskell you get "we named the operator *-~ to not conflict with *-, **, *~ or *-* from other libraries"

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
what language is this and what does it do?
3==D ~o

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
hmm, looks like APL. Probably conway's game of life

Soricidus
Oct 21, 2010
freedom-hating statist shill
i only use languages that permit the use of U+42069 ERECT PENIS as an infix operator

MononcQc
May 29, 2007

Soricidus posted:

i only use languages that permit the use of U+42069 ERECT PENIS as an infix operator

ꑕ YI SYLLABLE NYOT

Yi, also known as Lolo, is the Sino-Tibetan language used by aboriginal people of south-west China.

Notorious b.s.d.
Jan 25, 2003

by Reene

suffix posted:

some people don't get that '+' means something the way 'Add' means something, so you get dumb poo poo like 'shift standard output left by "hello world" bits', and 'divide pathA by pathB'

so for each library you get to learn dumb mnemonics like "* looks kind of like a hub", or "@<@ points to the indexing we want to preserve" because the author sees the operators as a smorgasbord you just randomly assign based on loose visual associations without caring about semantics

without custom operators you get "we overloaded +,-,*,/,%,&,| as shorthand for the methods on this car class"
and in haskell you get "we named the operator *-~ to not conflict with *-, **, *~ or *-* from other libraries"

MononcQc
May 29, 2007

I kind of always liked how lisps could never have operator overloading debates because they are the same poo poo as functions and there's no precedence rules to get all angry about.

Notorious b.s.d.
Jan 25, 2003

by Reene

MononcQc posted:

I kind of always liked how lisps could never have operator overloading debates because they are the same poo poo as functions and there's no precedence rules to get all angry about.

nobody is tempted to do anything stupid with lisp naming. you would never see anyone seriously suggest @**@ as a lisp function name.

there's something special about infix notation that makes people go bonkers

VikingofRock
Aug 24, 2008




suffix posted:

some people don't get that '+' means something the way 'Add' means something, so you get dumb poo poo like 'shift standard output left by "hello world" bits', and 'divide pathA by pathB'

I actually think that both of those are pretty decent uses of operator overloading. Both significantly reduce line noise when used multiple times in a single line (which is a common thing to do for both), and there is little chance for confusion with the original operator because (as you pointed out), bit shifts and division are semantically meaningless when applied to streams and paths. The cost you pay for this is that you have to learn what the operator does. In the case of using '/' as a path separator, this is immediately obvious, and literally every C++ tutorial covers using ">>" and "<<" for cout and cin so people aren't likely to be too confused by their use for other streams. It seems like maybe your objection is that the same symbol is being used to mean drastically different things within the same language (and sorry for arguing with a straw man if that was not your objection), but I don't really buy that argument because that is incredibly common in programming (unary vs. binary -, *, and &), in math (the center dot means can mean scalar multiplication, the dot product, the group operation, the convolution of functions, and probably way more), and in everyday life (# can mean "number". "pound", or "hashtag"). This is no undue burden in those other cases, so why should it stop us from cleaning up line noise in our programs?

JewKiller 3000
Nov 28, 2006

by Lowtax
the main problem with operator overloading is that people who use it tend to be the type who like to write clever-looking programs, and these are the worst kind of people

suffix
Jul 27, 2013

Wheeee!

VikingofRock posted:

It seems like maybe your objection is that the same symbol is being used to mean drastically different things within the same language

that is exactly my objection
you wouldn't call a method to write to a stream "shiftRight", and you wouldn't call a method that shifts bits in an integer "write", so why do people think it's okay that they share a name just because the name looks like line noise?

im not against operator overloading in principle, but you should have only a few operators, with a consistent definition, so every time a programmer encounters it it has the same semantic meaning
e.g. if you want a short syntax to join paths, don't use the division operator, use your concatenation operator that also concatenates strings, lists and arrays

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
if anything c++ should drop the bit-shifting versions of << and >> because it's really not an operation that benefits significantly from having an operator and the precedence is stupid for bit shifting but good for streaming (1 + x << 2 being (1 + x) << 2 is stupid; cout << x + 1 being cout << (x + 1) makes perfect sense)

using * for both multiplication and dereferencing is a far more egregious example of symbol reuse. not only does it confuse humans, it means that you can't even lex c without a symbol table.

VikingofRock
Aug 24, 2008




suffix posted:

that is exactly my objection
you wouldn't call a method to write to a stream "shiftRight", and you wouldn't call a method that shifts bits in an integer "write", so why do people think it's okay that they share a name just because the name looks like line noise?

Well, those aren't the names of the operators--their names are just symbols. Think of them like homophones. It's not really any weirder than having dog.walk() and directory.walk()

Soricidus
Oct 21, 2010
freedom-hating statist shill

Plorkyeran posted:

if anything c++ should drop the bit-shifting versions of << and >> because it's really not an operation that benefits significantly from having an operator

nor is stream io though?

iostream operators are really really bad and the only way anyone could think otherwise is stockholm syndrome

oh no blimp issue
Feb 23, 2011

ive never understood why c++ uses << for sending something to a stream

oh no blimp issue
Feb 23, 2011

i bet someone felt /very/ clever about it though

Soricidus
Oct 21, 2010
freedom-hating statist shill

Awia posted:

ive never understood why c++ uses << for sending something to a stream

because it was there

Notorious b.s.d.
Jan 25, 2003

by Reene

VikingofRock posted:

I actually think that both of those are pretty decent uses of operator overloading.

you're part of the problem.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
all of the bitwise operators should be reclaimed for non bitwise purposes

Notorious b.s.d.
Jan 25, 2003

by Reene

MALE SHOEGAZE posted:

all of the bitwise operators should be reclaimed for non bitwise purposes

great idea, but you're like 30+ years too late for that

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Blinkz0rz posted:

operators should only describe basic mathematic operations

everything else should be String.concat(a, b) or a.concat(b) or w/e

because gently caress, if + means concat, what else does it mean? where's that defined?

category theory

duh

VikingofRock
Aug 24, 2008




I mean don't get me wrong, I think their are plenty of poor design decisions around C++ iostreams. I just don't think that their choice of using operator<< and operator>> is necessarily one of them.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Notorious b.s.d. posted:

nobody is tempted to do anything stupid with lisp naming. you would never see anyone seriously suggest @**@ as a lisp function name.

but *@@* as a defvar name…

quote:

there's something special about infix notation that makes people go bonkers

it's really non-prefix notation, not just infix, Forth implementations typically wind up with an insanity of weird operators too

Soricidus
Oct 21, 2010
freedom-hating statist shill

VikingofRock posted:

I mean don't get me wrong, I think their are plenty of poor design decisions around C++ iostreams. I just don't think that their choice of using operator<< and operator>> is necessarily one of them.

the use of operators at all is one of the poor design decisions, since it leads directly to horrors like the use of mutable state to control output formatting

VikingofRock
Aug 24, 2008




Soricidus posted:

the use of operators at all is one of the poor design decisions, since it leads directly to horrors like the use of mutable state to control output formatting

So I agree that controlling output formatting through global mutable state is a really bad design decision on iostreams. What I was trying to argue was that, mutable state aside,

code:
std::cout << "The hex representation of " << std::dec << x << " is " << std::hex << x << "." << std::endl;
is a lot more pleasant to read than

code:
std::cout.put("The hex representation of ").put(std::dec).put(x).put(" is ").put(std::hex).put(x).put(".").put(std::endl);
(although I understand arguments to the contrary). I've never really heard the argument that the latter would somehow have kept C++ from using global mutable state for output formatting. Could you elaborate on that? Or am I misunderstanding what you were saying?

VikingofRock fucked around with this message at 01:59 on Mar 7, 2016

Notorious b.s.d.
Jan 25, 2003

by Reene

VikingofRock posted:

So I agree that controlling output formatting through global mutable state is a really bad design decision on iostreams. What I was trying to argue was that

code:
std::cout << "The hex representation of " << std::dec << x << " is " << std::hex << x << "." << std::endl;
is a lot more pleasant to read than

code:
std::cout.put("The hex representation of ").put(std::dec).put(x).put(" is ").put(std::hex).put(x).put(".").put(std::endl);
(although I understand arguments to the contrary). I've never really heard the argument that the latter would somehow have kept C++ from using global mutable state for output formatting. Could you elaborate on that? Or am I misunderstanding what you were saying?

both are bad but the latter example, using a builder pattern, is the better of the two

akadajet
Sep 14, 2003

VikingofRock posted:

So I agree that controlling output formatting through global mutable state is a really bad design decision on iostreams. What I was trying to argue was that, mutable state aside,

code:
std::cout << "The hex representation of " << std::dec << x << " is " << std::hex << x << "." << std::endl;
is a lot more pleasant to read than

code:
std::cout.put("The hex representation of ").put(std::dec).put(x).put(" is ").put(std::hex).put(x).put(".").put(std::endl);
(although I understand arguments to the contrary). I've never really heard the argument that the latter would somehow have kept C++ from using global mutable state for output formatting. Could you elaborate on that? Or am I misunderstanding what you were saying?

:barf:

VikingofRock
Aug 24, 2008




Notorious b.s.d. posted:

both are bad but the latter example, using a builder pattern, is the better of the two

I mean they are the exact same code, just with the name of a function changed. So you can't really argue that one is using a builder pattern and the other isn't. But I think in this case, the focus should be on pretty much everything except the '<<'s or the '.put()'s, because those functions are the least important part of the code. I think that using '.put()' instead of '<<' defeats that slightly, which makes the code with '.put()' a little harder to read.

Again, I probably would have been fine with C++ using '.put()' instead of '<<', although I do prefer the latter. It would have been even better had C++ done something besides having global mutable state for outputting stuff (because yeah, that code is disgusting either way). But I think that if you are going to design iostreams the way C++ did, then this is a very defensible use of operator overloading.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

VikingofRock posted:

So I agree that controlling output formatting through global mutable state is a really bad design decision on iostreams. What I was trying to argue was that, mutable state aside,

code:
std::cout << "The hex representation of " << std::dec << x << " is " << std::hex << x << "." << std::endl;
is a lot more pleasant to read than

code:
std::cout.put("The hex representation of ").put(std::dec).put(x).put(" is ").put(std::hex).put(x).put(".").put(std::endl);
(although I understand arguments to the contrary). I've never really heard the argument that the latter would somehow have kept C++ from using global mutable state for output formatting. Could you elaborate on that? Or am I misunderstanding what you were saying?

yeah but in reality no one would use the latter

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




MALE SHOEGAZE posted:

yeah but in reality no one would use the latter

So the argument against operator overloading here is that "it made this bad thing more ergonomic and readable, so this bad thing got implemented"? I guess I understand that argument but it seems pretty weak to me.

  • Locked thread