Exceptional coding style
mist
none at none.none
Wed Jan 16 10:57:05 PST 2013
On Wednesday, 16 January 2013 at 18:42:38 UTC, Mehrdad wrote:
> On Wednesday, 16 January 2013 at 18:38:21 UTC, Mehrdad wrote:
>> On Wednesday, 16 January 2013 at 11:00:48 UTC, mist wrote:
>>>> When you have a ton of similar lines of code which need to
>>>> be edited in parallel, lining them up lets you edit all of
>>>> them in one keystroke. Saves me quite a lot of annoying
>>>> editing in the long run, actually.
>>>
>>> When you have a ton of similar lines of code, you'd better
>>> start thinking about templates or mixins :P
>>
>>
>> Easy to say in theory, but makes absolutely no sense in many
>> cases. =P
>>
>> Example:
>> boost::unordered_set<int> foo;
>> boost::unordered_map<int> bar;
>>
>>
>> and now I want to change 'boost' to 'std' because C++11 came
>> out.
>>
>> Templates? Mixins? wtf lol
>
> Another example:
>
> template<class T> struct foo
> {
> int x;
> int operator+(int) const { }
> int operator-(int) const { }
> int operator*(int) const { }
> };
>
> template<class T> int foo<T>::operator+(int x) const { return
> this->x + x; }
> template<class T> int foo<T>::operator-(int x) const { return
> this->x - x; }
> template<class T> int foo<T>::operator*(int x) const { return
> this->x * x; }
>
>
>
> let's say now I want to add a new template parameter, class U,
> to all the functions.
>
>
>
> If you can teach me how "templates" or "mixins" would solve my
> problem here I'd love to know.
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.
More information about the Digitalmars-d
mailing list