Re: Newbie style question about string constants

2025-03-30 Thread FeepingCreature via Digitalmars-d-learn
On Thursday, 27 March 2025 at 06:20:25 UTC, cc wrote: I got in the habit of using `static immutable` whenever possible as enum just can't be trusted to use CTFE. ```d enum string RfuncName = fullyQualifiedName!... // Oops! Allocates on runtime every frame this is referenced enum string funcName

Re: Newbie style question about string constants

2025-03-26 Thread cc via Digitalmars-d-learn
On Monday, 24 February 2025 at 16:07:07 UTC, Ian wrote: Hello, What's the recommended D way to declare a string constant? Say, for example, for a path used inside a class constructor? I've seen const string, immutable, enum etc... Is this the place for these kinds of questions? Is there a D

Re: Newbie style question about string constants

2025-03-17 Thread Ian via Digitalmars-d-learn
On Monday, 17 March 2025 at 08:27:17 UTC, Jonathan M Davis wrote: In any case, the normal way in D to declare a string constant is to use enum. So, that's primarily what you're going to see in most code. Whether you choose to do that in your own code is up to you. - Jonathan M Davis Hi Jo

Re: Newbie style question about string constants

2025-03-17 Thread monkyyy via Digitalmars-d-learn
On Sunday, 16 March 2025 at 15:22:04 UTC, Ian wrote: It seems that in some cases static immutable is preferred, so why not use that always then, rather than having to keep two cases in my head? Enum is the indispensable one, immutable isnt important just theres a subsection of the community t

Re: Newbie style question about string constants

2025-03-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 16, 2025 9:22:04 AM MDT Ian via Digitalmars-d-learn wrote: > On Tuesday, 25 February 2025 at 00:34:45 UTC, Jonathan M Davis > wrote: > > For strings, the way that you normally do constants is with > > enum, e.g > > > > enum foo = "dlang"; > > > > An enum like this is called a m

Re: Newbie style question about string constants

2025-03-16 Thread Ian via Digitalmars-d-learn
On Tuesday, 25 February 2025 at 00:34:45 UTC, Jonathan M Davis wrote: For strings, the way that you normally do constants is with enum, e.g enum foo = "dlang"; An enum like this is called a manifest constant. And you use manifest constants for most constants in D, with the caveat that fo

Re: Newbie style question about string constants

2025-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 24, 2025 9:07:07 AM MST Ian via Digitalmars-d-learn wrote: > Hello, > > What's the recommended D way to declare a string constant? Say, > for example, for a path used inside a class constructor? I've > seen const string, immutable, enum etc... > > Is this the place for these kin

Re: Newbie style question about string constants

2025-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 24, 2025 11:19:48 AM MST Elias Batek (0xEAB) via Digitalmars-d-learn wrote: > For string constants you’ll usually want to mark them as `static > immutable`. Strings with this combination will usually be put > into read-only sections (ROM) of the resulting binaries. > > Unlike `

Re: Newbie style question about string constants

2025-02-24 Thread Elias Batek (0xEAB) via Digitalmars-d-learn
On Monday, 24 February 2025 at 16:07:07 UTC, Ian wrote: Hello, What's the recommended D way to declare a string constant? Say, for example, for a path used inside a class constructor? I've seen const string, immutable, enum etc... Is this the place for these kinds of questions? Is there a D

Re: Newbie style question about string constants

2025-02-24 Thread monkyyy via Digitalmars-d-learn
On Monday, 24 February 2025 at 16:07:07 UTC, Ian wrote: Hello, What's the recommended D way to declare a string constant? Say, for example, for a path used inside a class constructor? I've seen const string, immutable, enum etc... enum vs value is a tradeoff of when a decision is made; not s

Newbie style question about string constants

2025-02-24 Thread Ian via Digitalmars-d-learn
Hello, What's the recommended D way to declare a string constant? Say, for example, for a path used inside a class constructor? I've seen const string, immutable, enum etc... Is this the place for these kinds of questions? Is there a D stack overflow? Cheers, Ian

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