D-etractions A real world programmers view on D
Peter Alexander
peter.alexander.au at gmail.com
Sat Aug 25 06:03:12 PDT 2012
On Saturday, 25 August 2012 at 00:22:58 UTC, bearophile wrote:
> Pragma Tix:
>
>> IMO a voice, D core developers should listen to.
>
> Even assuming all the things he has said are true, what do you
> suggest D core developers to do?
> Example: how can D language devevelopers help D programmers
> better refactor D code? Maybe having some built-in refactoring
> features?
The D language is designed in such a way that makes many
automated refactoring tasks incredibly difficult, if not
impossible.
An example from Walter's recent talk:
struct A {
int a;
mixin(bitfields!(
uint, "x", 2,
int, "y", 3,
uint, "z", 2,
bool, "flag", 1));
}
A obj;
obj.x = 2;
obj.z = obj.x;
A common (and simple) refactoring task included in most IDEs is
to rename a variable. Imagine what's involved in renaming the x,
y, and z from the bitfield in the above code. You would have to
expand the template (which involved CTFE) and then somehow infer
that the name of the variable came from that string in the
template args.
Okay, so bitfields are rarely used, but many templates involve
some use of CTFE, and templates are very common in D code. It's
good that D's parser is fairly simple to implement (compared to
C++ anyway), but to do automated refactoring you need simple
semantic analysis, and this is something that D does not have.
More information about the Digitalmars-d
mailing list