Re: Safe copy-paste using mixin

2015-09-01 Thread drug via Digitalmars-d-learn
On 31.08.2015 16:30, cym13 wrote: No, in my case there is no problem, I'm curious. I guess that string mixins sometimes may look like a hack. IMHO they are a hack. That's why they should be used with caution (and why using them feels so good ^_^ ). But I don't see how mixing arbitrary code

Safe copy-paste using mixin

2015-08-31 Thread drug via Digitalmars-d-learn
I have code that is being duplicated in several places and I'd like to use mixins to simplify code maintenance but I failed to do it. For example https://github.com/drug007/hdf5-d-examples/blob/tmp/examples/aux.d Lines 80-82, 91-93 and 99-101 are identical, how can I use mixin here? I failed

Re: Safe copy-paste using mixin

2015-08-31 Thread drug via Digitalmars-d-learn
On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c) { return `string a = "` ~ a ~ `";` ~ `string b = "` ~ b ~ `";` `string c = "` ~ c ~ `";`; }

Re: Safe copy-paste using mixin

2015-08-31 Thread drug via Digitalmars-d-learn
On 31.08.2015 14:36, cym13 wrote: On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c) {

Re: Safe copy-paste using mixin

2015-08-31 Thread drug via Digitalmars-d-learn
On 31.08.2015 13:35, drug wrote: I have code that is being duplicated in several places and I'd like to use mixins to simplify code maintenance but I failed to do it. For example https://github.com/drug007/hdf5-d-examples/blob/tmp/examples/aux.d Lines 80-82, 91-93 and 99-101 are identical, how

Re: Safe copy-paste using mixin

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c) { return `string a = "` ~ a ~ `";` ~

Re: Safe copy-paste using mixin

2015-08-31 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 31 August 2015 at 10:38:41 UTC, drug wrote: On 31.08.2015 13:35, drug wrote: I have code that is being duplicated in several places and I'd like to use mixins to simplify code maintenance but I failed to do it. For example

Re: Safe copy-paste using mixin

2015-08-31 Thread drug via Digitalmars-d-learn
On 31.08.2015 15:28, Andrea Fontana wrote: On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c)

Re: Safe copy-paste using mixin

2015-08-31 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c) { return `string a = "` ~ a ~ `";` ~

Re: Safe copy-paste using mixin

2015-08-31 Thread cym13 via Digitalmars-d-learn
On Monday, 31 August 2015 at 12:43:25 UTC, drug wrote: On 31.08.2015 15:28, Andrea Fontana wrote: On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: