Detecting inadvertent use of integer division

bearophile bearophileHUGS at lycos.com
Mon Dec 14 18:19:40 PST 2009


Bob Jones:
> The fact that adding a specific intdiv operator would not only avoid more 
> casting, but remove the the need for casting in a lot of existing cases 
> should count pretty well against the "no more operator/keywords" argument.

In D you can't use // used in Python, because it's used to denote comments and this will not change.

You probably can't use "div" beause that adds another keyword, and people don't like that. And it goes against the C usage of using symbols for operators (so for example D devs don't like 'or' and 'and' as boolean operators, even if they can avoid some of the bugs caused by writing & instead of && or the other way).

You can't use \ (it's also not different enough to tell them apart well).

I don't know if you can use \\.

Even if you find a fitting operator, how can you restrict \ to just floating point division and keep some compatibility with C code?

Bye,
bearophile



More information about the Digitalmars-d mailing list