On Wednesday, 16 January 2013 at 19:06:47 UTC, Mehrdad wrote:
On Wednesday, 16 January 2013 at 18:57:06 UTC, mist wrote:

This is a single template operator in D so it kind of solves the problem. First is tricky, but is exactly the reason sometimes types from external libs are used only via alias/typedef. I'd prefer something like :%s/boost::unord/std::unord/g though :) But well, if you are working with C++, then templates and mixins will hardly solve most problems of course, because C++ templates sucks and mixins do not even exist there.



Yeah I'm working in C++, not D.


But even if I was using D, there's no way in heck that I would use a _MIXIN_ for that:

mixin("I'm not sure how this is supposed too be readable").unordered_map!(int) a;

makes no sense to me at all, when I could just as well have said 'boost'.



Also, the search/replace thing won't work so well for any real-world example (the second one is a lot closer to what I had in mind... you can't just replace "T" with "T, U" and expect it to work).


So my point is: no, it's not a simple matter of abstracting things away. Lined-up text really DOES make certain tasks easier than they would be otherwise.

Mixins and templates are tools to avoid copy-paste, there is no point to using them just for the sake of that. I have already mentioned that first example is not related to copy-paste and thus not fixable with that, it is more related to alias. Second is fixed perfectly in D using string mixins and single template unary operator with much more readable code.

My point is - when you have a lot repetitive text pieces in your code, it is much better in longer scope to use advanced language tools instead of advanced editing tools. And this is one place where D is so superior do C++. I must admit I'd prefer to have template mixins allowed for statements to minimize string mixin usage but it is still much much better than copy-paste in my opinion.

Reply via email to