Re: A better way to write this function? (style question)

2013-12-31 Thread Jacob Carlborg
On 2013-12-30 23:51, John Colvin wrote: Anyway, the big problem I've hit is that AFAICT std.algorithm makes a complete mess of unicode and i can't find a byCodeUnit range anywhere in order to make it correct. There's a "byGrapheme" and a "byCodePoint" function in std.uni. It was recently adde

Re: A better way to write this function? (style question)

2013-12-30 Thread Thomas Gann
Thanks for all your replies, guys! I have done some further research in the meantime and I have found out that I am, in fact, an idiot. There is actually a standard library function that does exactly what I am trying to do! As it turns out, std.string.split(): 1) It automatically discards emp

Re: A better way to write this function? (style question)

2013-12-30 Thread bearophile
Thomas Gann: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by splitting the string up by whitespace. Take a lo

Re: A better way to write this function? (style question)

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 22:38:43 UTC, Brad Anderson wrote: On Monday, 30 December 2013 at 22:30:02 UTC, John Colvin wrote: On Monday, 30 December 2013 at 22:17:21 UTC, John Colvin wrote: On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I

Re: A better way to write this function? (style question)

2013-12-30 Thread Brad Anderson
On Monday, 30 December 2013 at 22:30:02 UTC, John Colvin wrote: On Monday, 30 December 2013 at 22:17:21 UTC, John Colvin wrote: On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert al

Re: A better way to write this function? (style question)

2013-12-30 Thread Brad Anderson
On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by s

Re: A better way to write this function? (style question)

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 22:17:21 UTC, John Colvin wrote: On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowe

Re: A better way to write this function? (style question)

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by s

A better way to write this function? (style question)

2013-12-30 Thread Thomas Gann
I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by splitting the string up by whitespace. Here is the function is qu

Re: style question on structs

2013-12-29 Thread Ali Çehreli
On 12/29/2013 10:58 AM, Jonathan wrote: > Given a struct > > struct Foo{ >enum INT_C {Yes, No} >INT_C a; > } [...] > The second choice is: do we qualify by the struct name: > > this(int y) > { >//option 1 >a = Foo.INT_C.Yes; That's what I do without thinking much about it. >

Re: style question on structs

2013-12-29 Thread John Colvin
On Sunday, 29 December 2013 at 18:58:07 UTC, Jonathan wrote: Given a struct struct Foo{ enum INT_C {Yes, No} INT_C a; } -- we wish to make a constructor. We want to set the answer to Yes if we construct the struct with an integer. There are some stylistic choices to be made. The first

style question on structs

2013-12-29 Thread Jonathan
Given a struct struct Foo{ enum INT_C {Yes, No} INT_C a; } -- we wish to make a constructor. We want to set the answer to Yes if we construct the struct with an integer. There are some stylistic choices to be made. The first choice is: do we use this (I seem to recall being told in Ja

Re: Style question

2013-07-12 Thread Simen Kjaeraas
On 2013-07-11, 20:22, Namespace wrote: What should he do? As far as I can see he has 3 options: 1. An external file with the enum information. Both classes would import it and could use the same enum. But he cannot change the API, so this is no real option. 2. Change test1 into this:

Re: Style question

2013-07-12 Thread Regan Heath
On Thu, 11 Jul 2013 19:22:10 +0100, Namespace wrote: I have a style question, because a friend of mine has a similar problem currently and I have no good advice for him. Let's assume we have this classes: class MyClass { public: enum A { Fo

Re: Style question

2013-07-12 Thread Namespace
On Friday, 12 July 2013 at 06:54:40 UTC, Jacob Carlborg wrote: On 2013-07-11 20:22, Namespace wrote: [snip] Does anyone have any advice? Who is supposed to access these enums? Can you put it in a separate module but in the same package with package protection? No. Both modules are in differ

Re: Style question

2013-07-11 Thread Jacob Carlborg
On 2013-07-11 20:22, Namespace wrote: [snip] Does anyone have any advice? Who is supposed to access these enums? Can you put it in a separate module but in the same package with package protection? -- /Jacob Carlborg

Re: Style question

2013-07-11 Thread Maxim Fomin
On Thursday, 11 July 2013 at 20:15:52 UTC, Namespace wrote: The whole situation looks strange. If you can change both files, than it is unclear what made you to write such inconsistent code. If you can change only one of them, then it should be adjusted to another (meaning importing external fi

Re: Style question

2013-07-11 Thread Namespace
The whole situation looks strange. If you can change both files, than it is unclear what made you to write such inconsistent code. If you can change only one of them, then it should be adjusted to another (meaning importing external file and using that enum instead of trying to define different

Re: Style question

2013-07-11 Thread Maxim Fomin
On Thursday, 11 July 2013 at 18:22:11 UTC, Namespace wrote: I have a style question, because a friend of mine has a similar problem currently and I have no good advice for him. Let's assume we have this classes: The whole situation looks strange. If you can change both files, than

Re: Style question

2013-07-11 Thread Simen Kjaeraas
On 2013-07-11, 21:05, Namespace wrote: It seems to me that MyClass has access to MyStaticClass, and thus should also have access to B. If this is the case, why is MyClass using an A instead of a B? No, they are sadly not part of the same file / module. The // should symbolize that. :D I

Re: Style question

2013-07-11 Thread Namespace
It seems to me that MyClass has access to MyStaticClass, and thus should also have access to B. If this is the case, why is MyClass using an A instead of a B? No, they are sadly not part of the same file / module. The // should symbolize that. :D One option might be to use alias A = B; T

Re: Style question

2013-07-11 Thread Simen Kjaeraas
On 2013-07-11, 20:22, Namespace wrote: What should he do? As far as I can see he has 3 options: 1. An external file with the enum information. Both classes would import it and could use the same enum. But he cannot change the API, so this is no real option. 2. Change test1 into this:

Style question

2013-07-11 Thread Namespace
I have a style question, because a friend of mine has a similar problem currently and I have no good advice for him. Let's assume we have this classes: class MyClass { public: enum A { Foo = 0, Bar = 1 } private: A _a; p