Overloading relational operators separately; thoughts?

Russel Winder via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 29 04:29:55 PDT 2016


On Wed, 2016-09-28 at 20:30 +0000, pineapple via Digitalmars-d wrote:
> On Wednesday, 28 September 2016 at 20:16:08 UTC, Walter Bright 
> wrote:
> > 
> > Because there is no way to stop the former but still have 
> > operator overloading.
> > 
> > To reiterate, operator overloading exists in D to support the 
> > inclusion of arithmetic library types. Any other purpose is 
> > discouraged, and that includes expression templates and things 
> > like << for iostreams.
> 
> This is an obsolete way of thinking about operators. Operator 
> overloading exists to make the programmer's life easier, and 
> limiting the ways in which a valuable tool can be used drives 
> people to languages which allow them to be more expressive.

Definitely, yes. 

However, this has come up many times, and every time Walter says "no,
it's wrong". Whilst the C++ iostreams << may have problems, using this
as a single point argument as to why overloading fails in all other
cases except numeric arithmetic is bad philosophy. In my view this is
holding D back.

> For my job I write Python. We use a database layer called 
> sqlalchemy that allows us to express queries by writing, for 
> example, `session.query(some_table).filter(row1 == row2)` and I 
> cannot begin to express how useful this is when writing code, 
> when maintaining code, and when attempting to understand code 
> that someone else wrote.

Definitely. I spend a lot of my time trying to inculcate people into
DSL-based thinking as an extension of abstraction and leading towards
understanding and modelling the solution to problems in the domain.
Python has it's problems, C++ more, but this is a far superior way of
going than the Java approach of "operator overloading is too hard for
programmers to deal with so let's ban it". Hence Groovy, Scala, Kotlin,
Ceylon, etc. all of which bring back this feature Java eschewed from
C++ – possibly because the Oak developers had their problems. 

> The objective should never be to stop the programmer from doing 
> something because you personally dislike the practice.

I guess it depends on whether the language is wanting to gain traction
in the market or remain a pet project.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160929/d7cd3552/attachment-0001.sig>


More information about the Digitalmars-d mailing list