Re: Idiomatic D using GC as a library writer

2022-12-05 Thread vushu via Digitalmars-d-learn
On Monday, 5 December 2022 at 14:48:33 UTC, cc wrote: On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: [...] If your program runs, does some stuff, and terminates, use the GC. If your program runs, stays up for a while with user occasionally interacting with it, use the GC. If your

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread vushu via Digitalmars-d-learn
On Sunday, 4 December 2022 at 17:47:38 UTC, ryuukk_ wrote: On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: [...] D gives you the choice But the most important thing is your usecase, what kind of library are you making? Once you answer this question, you can then ask what your

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread vushu via Digitalmars-d-learn
On Monday, 5 December 2022 at 10:53:33 UTC, Guillaume Piolat wrote: On Sunday, 4 December 2022 at 21:55:52 UTC, Siarhei Siamashka wrote: Is it possible to filter packages in this list by @nogc or @safe compatibility? You can list DUB packages for "@nogc usage"

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread vushu via Digitalmars-d-learn
On Monday, 5 December 2022 at 10:48:59 UTC, Guillaume Piolat wrote: There are legitimate uses cases when you can't afford the runtime machinery (attach/detach every incoming thread in a shared library), more than not being able to afford the GC from a performance point of view. [...]

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread jmh530 via Digitalmars-d-learn
On Sunday, 4 December 2022 at 23:25:34 UTC, Adam D Ruppe wrote: On Sunday, 4 December 2022 at 22:46:52 UTC, Ali Çehreli wrote: That's way beyond my pay grade. Explain please. :) The reason that the GC stops threads right now is to ensure that something doesn't change in the middle of its

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread cc via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: What are your thoughts about using GC as a library writer? If your program runs, does some stuff, and terminates, use the GC. If your program runs, stays up for a while with user occasionally interacting with it, use the GC. If your

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread Guillaume Piolat via Digitalmars-d-learn
On Sunday, 4 December 2022 at 21:55:52 UTC, Siarhei Siamashka wrote: Is it possible to filter packages in this list by @nogc or @safe compatibility? You can list DUB packages for "@nogc usage" https://code.dlang.org/?sort=score=20=library.nogc

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread Guillaume Piolat via Digitalmars-d-learn
There are legitimate uses cases when you can't afford the runtime machinery (attach/detach every incoming thread in a shared library), more than not being able to afford the GC from a performance point of view. GC gives you higher productivity and better performance with the time gained.

Re: Idiomatic D using GC as a library writer

2022-12-05 Thread Patrick Schluter via Digitalmars-d-learn
On Sunday, 4 December 2022 at 23:37:39 UTC, Ali Çehreli wrote: On 12/4/22 15:25, Adam D Ruppe wrote: > which would trigger the write barrier. The thread isn't > allowed to complete this operation until the GC is done. According to my limited understanding of write barriers, the thread moving

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 15:25, Adam D Ruppe wrote: > which would trigger the write barrier. The thread isn't > allowed to complete this operation until the GC is done. According to my limited understanding of write barriers, the thread moving to 800 could continue because order of memory operations may

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 December 2022 at 22:46:52 UTC, Ali Çehreli wrote: That's way beyond my pay grade. Explain please. :) The reason that the GC stops threads right now is to ensure that something doesn't change in the middle of its analysis. Consider for example, the GC scans address 0 - 1000 and

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread rikki cattermole via Digitalmars-d-learn
ALl it means is certain memory patterns (such as writes), will tell the GC about it. Its required for pretty much all advanced GC designs, as a result we are pretty much maxing out what we can do. Worth reading:

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 12:17, Adam D Ruppe wrote: On Sunday, 4 December 2022 at 17:53:00 UTC, Adam D Ruppe wrote: Interesting... you know, maybe D's GC should formally expose a mutex that you can synchronize on for when it is running. .. or compile in write barriers. then it doesn't matter if the

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 December 2022 at 21:55:52 UTC, Siarhei Siamashka wrote: Do you mean the top of the https://code.dlang.org/?sort=score=library list? Well, I was referring to the five that appear on the homepage, which shows silly instead of emsi containers. How do you know that they embrace

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Siarhei Siamashka via Digitalmars-d-learn
On Sunday, 4 December 2022 at 12:37:08 UTC, Adam D Ruppe wrote: All of the top 5 most popular libraries on code.dlang.org embrace the GC. Do you mean the top of the https://code.dlang.org/?sort=score=library list? How do you know that they embrace GC? Is it possible to filter packages in

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 December 2022 at 17:53:00 UTC, Adam D Ruppe wrote: Interesting... you know, maybe D's GC should formally expose a mutex that you can synchronize on for when it is running. .. or compile in write barriers. then it doesn't matter if the thread is unregistered, the write

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 December 2022 at 16:02:28 UTC, Ali Çehreli wrote: D's GC needed to stop the world, which meant it would have to know what threads were running. You can never be sure whether your D library function is being called from a thread you've known or whether the Java runtime (or other

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread ryuukk_ via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: Dear dlang community. I am unsure about what idiomatic D is. Some of the Dconf talks tells people just to use the GC, until you can't afford it. If there are documents that describes what idiomatic D is then I would appreciate

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread vushu via Digitalmars-d-learn
On Sunday, 4 December 2022 at 15:57:26 UTC, Ali Çehreli wrote: On 12/4/22 05:58, vushu wrote: > I was worried if my library should be GC free May I humbly recommend you question where that thinking comes from? Ali P.S. I used to be certain that the idea of GC was wrong and the creators of

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 06:27, Sergey wrote: > if it will be possible to write > library in D and use it from > C/++/Python/R/JVM(JNI)/Erlang(NIF)/nameYourChoice smoothly it will be a > win. Years ago we tried to call D from Java. I realized that it was very tricky to introduce the calling thread to D's

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 05:58, vushu wrote: > I was worried if my library should be GC free May I humbly recommend you question where that thinking comes from? Ali P.S. I used to be certain that the idea of GC was wrong and the creators of runtimes with GC were simpletons. In contrast, people like me,

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Sergey via Digitalmars-d-learn
On Sunday, 4 December 2022 at 12:37:08 UTC, Adam D Ruppe wrote: All of the top 5 most popular libraries on code.dlang.org embrace the GC. Interesting. It seems that most of the community suppose that “library” should be used from D :-) But in my opinion - “foreign library experience” is much

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread vushu via Digitalmars-d-learn
On Sunday, 4 December 2022 at 13:03:07 UTC, Hipreme wrote: On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: Dear dlang community. I am unsure about what idiomatic D is. Some of the Dconf talks tells people just to use the GC, until you can't afford it. If there are documents

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread vushu via Digitalmars-d-learn
On Sunday, 4 December 2022 at 12:37:08 UTC, Adam D Ruppe wrote: On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: What are your thoughts about using GC as a library writer? Do it. It is lots of gain for very little loss. If you wan't to include a library into your project aren't you

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread bachmeier via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: Dear dlang community. I am unsure about what idiomatic D is. Idiomatic D code produces the correct result, it's readable, and it's easy for others to use. Some of the Dconf talks tells people just to use the GC, until you can't

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Hipreme via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: Dear dlang community. I am unsure about what idiomatic D is. Some of the Dconf talks tells people just to use the GC, until you can't afford it. If there are documents that describes what idiomatic D is then I would appreciate

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:53:41 UTC, vushu wrote: What are your thoughts about using GC as a library writer? Do it. It is lots of gain for very little loss. If you wan't to include a library into your project aren't you more inclined to use a library which is gc free? No, GC free

Idiomatic D using GC as a library writer

2022-12-04 Thread vushu via Digitalmars-d-learn
Dear dlang community. I am unsure about what idiomatic D is. Some of the Dconf talks tells people just to use the GC, until you can't afford it. If there are documents that describes what idiomatic D is then I would appreciate it. So my questions are: What are your thoughts about

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-06 Thread Martin Tschierschke via Digitalmars-d-learn
On Monday, 3 August 2020 at 15:33:54 UTC, Dominikus Dittes Scherkl wrote: [...] For really long expressions you could also split it on multiple lines: c = (b_expression == 0) ? (d_longer_expression) : (a_expression/b_expression); +1 looks clean!

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 3 August 2020 at 14:50:36 UTC, Steven Schveighoffer wrote: On 8/3/20 5:53 AM, Martin Tschierschke wrote: I prefer putting additional bracket around For really long expressions you could also split it on multiple lines: c = (b_expression == 0) ? (d_longer_expression) :

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/20 5:53 AM, Martin Tschierschke wrote: On Friday, 31 July 2020 at 14:18:15 UTC, Steven Schveighoffer wrote: On 7/31/20 9:55 AM, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero.

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Martin Tschierschke via Digitalmars-d-learn
On Friday, 31 July 2020 at 14:18:15 UTC, Steven Schveighoffer wrote: On 7/31/20 9:55 AM, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Martin Tschierschke via Digitalmars-d-learn
On Friday, 31 July 2020 at 15:19:25 UTC, Andrea Fontana wrote: On Friday, 31 July 2020 at 13:55:18 UTC, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero

Re: Idiomatic D code to avoid or detect devision by zero

2020-07-31 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 31 July 2020 at 13:55:18 UTC, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than set c to an other value (d). (In the moment I

Re: Idiomatic D code to avoid or detect devision by zero

2020-07-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/31/20 9:55 AM, Martin Tschierschke wrote: What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than set c to an other value (d). (In the moment I check the divisor being

Idiomatic D code to avoid or detect devision by zero

2020-07-31 Thread Martin Tschierschke via Digitalmars-d-learn
What would be the idiomatic way to write a floating point division occuring inside a loop and handle the case of division by zero. c = a/b; // b might be zero sometimes, than set c to an other value (d). (In the moment I check the divisor being zero or not, with an if-than-else structure,

Re: __traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread aliak via Digitalmars-d-learn
On Monday, 8 January 2018 at 23:03:46 UTC, H. S. Teoh wrote: On Mon, Jan 08, 2018 at 10:59:44PM +, aliak via Digitalmars-d-learn wrote: [...] onlineapp.d(61): Error: template std.traits.TemplateOf does not match any template declaration. And I use it like this: enum r1Sorted =

Re: __traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread aliak via Digitalmars-d-learn
On Monday, 8 January 2018 at 23:22:04 UTC, Seb wrote: On Monday, 8 January 2018 at 23:14:32 UTC, Seb wrote: Your problem is that `TemplateOf!(int[])` isn't defined. It should probably be changed to return `void`. https://github.com/dlang/phobos/pull/6016 Damn that's some fast turnaround!

Re: __traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread Seb via Digitalmars-d-learn
On Monday, 8 January 2018 at 23:14:32 UTC, Seb wrote: Your problem is that `TemplateOf!(int[])` isn't defined. It should probably be changed to return `void`. https://github.com/dlang/phobos/pull/6016

Re: __traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 08, 2018 at 10:59:44PM +, aliak via Digitalmars-d-learn wrote: [...] > onlineapp.d(61): Error: template std.traits.TemplateOf does not match > any template declaration. And I use it like this: > > enum r1Sorted = __traits(isSame, TemplateOf!(R1), SortedRange); This seems

Re: __traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread Seb via Digitalmars-d-learn
On Monday, 8 January 2018 at 22:59:44 UTC, aliak wrote: Hi, trying to write some idiomatic generic D code and I'm a bit stuck with using the TemplateOf to check if a range is a SortedRange or not. A bit about the code, I'm basically rewriting

__traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread aliak via Digitalmars-d-learn
Hi, trying to write some idiomatic generic D code and I'm a bit stuck with using the TemplateOf to check if a range is a SortedRange or not. A bit about the code, I'm basically rewriting https://dlang.org/library/std/algorithm/setops/set_difference.html but I want to do different things based

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread Laeeth Isharc via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 17:41:53 UTC, Tobias Pankrath wrote: On Tuesday, 13 January 2015 at 17:19:42 UTC, Laeeth Isharc wrote: The GC is allowed to move structs around, as I undestand it. Under what circumstances do I get into trouble having a pointer to them? None, a GC that moves

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread via Digitalmars-d-learn
(( It follows from this that it will be challenging to achieve full memory safety without fixing the type system first. ))

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 14, 2015 at 07:05:16PM +, Laeeth Isharc via Digitalmars-d-learn wrote: On Tuesday, 13 January 2015 at 17:41:53 UTC, Tobias Pankrath wrote: On Tuesday, 13 January 2015 at 17:19:42 UTC, Laeeth Isharc wrote: The GC is allowed to move structs around, as I undestand it. Under

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 14, 2015 at 07:43:17PM +, via Digitalmars-d-learn wrote: On Wednesday, 14 January 2015 at 19:36:44 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Moral of the story: don't have struct fields that point to the struct itself. This is almost always a bad idea. Structs have value

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread via Digitalmars-d-learn
On Wednesday, 14 January 2015 at 19:36:44 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Moral of the story: don't have struct fields that point to the struct itself. This is almost always a bad idea. Structs have value semantics, and the implicit copying around will almost certainly break any

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-14 Thread via Digitalmars-d-learn
On Wednesday, 14 January 2015 at 20:23:26 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Huh? ints have value semantics, yet you can take the address of a local int variable. What's your point? Strictly speaking the int looses its value semantics if you take the address of it, hold it and

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-13 Thread Laeeth Isharc via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 14:59:58 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Jan 07, 2015 at 02:52:51PM +, Laeeth Isharc via Digitalmars-d-learn wrote: Another schoolboy question. Suppose I am constructing a tree (in this case it is an AST). In C I would have a pointer

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-13 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 17:19:42 UTC, Laeeth Isharc wrote: The GC is allowed to move structs around, as I undestand it. Under what circumstances do I get into trouble having a pointer to them? None, a GC that moves structs around must update every pointer afterwards and as far as I

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-10 Thread Laeeth Isharc via Digitalmars-d-learn
Small recommendation (apart from the reserved word issue which you fixed): it's generally considered good D style to give structs and classes names that start with capital letters, JustLikeThis. So, I suggest Node rather than node. Very minor point, and of course, your code is yours to style

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 07/01/15 16:02, Laeeth Isharc via Digitalmars-d-learn wrote: class node { string name; node ref; } Small recommendation (apart from the reserved word issue which you fixed): it's generally considered good D style to give structs and classes names that start with capital letters,

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Laeeth Isharc via Digitalmars-d-learn
this conversation is so funny: well what's wrong with this . It's a keyword... Aa Ha ha ha ha , rol. Seriously, is it so complicated to use a D editor ? I mean with syntax color... Man afraid to ask stoopid questions stays stoopid. And compiler error message far from informative. Not

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Mengu via Digitalmars-d-learn
On Thursday, 8 January 2015 at 11:29:30 UTC, Laeeth Isharc wrote: this conversation is so funny: well what's wrong with this . It's a keyword... Aa Ha ha ha ha , rol. Seriously, is it so complicated to use a D editor ? I mean with syntax color... Man afraid to ask stoopid questions stays

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Tobias Pankrath via Digitalmars-d-learn
what's wrong with the code above ? i get an error no identifier for declarator node. (I have not used classes much, since structs often seem to be enough for what I need to do mostly). ref is a reserved keyword. -- Paulo this conversation is so funny: well what's wrong with this .

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 08, 2015 at 11:29:29AM +, Laeeth Isharc via Digitalmars-d-learn wrote: this conversation is so funny: well what's wrong with this . It's a keyword... Aa Ha ha ha ha , rol. Seriously, is it so complicated to use a D editor ? I mean with syntax color... Man afraid to ask

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/8/15 12:15 AM, Meta wrote: On Wednesday, 7 January 2015 at 23:27:19 UTC, anonymous wrote: Don't do this without `dup`ing. Quoting the documentation: Oh, whoops. I thought those special variadic args were always allocated on the heap. Nope, Which makes it annoying, what if the argument

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Ali Çehreli via Digitalmars-d-learn
On 01/08/2015 09:40 AM, H. S. Teoh via Digitalmars-d-learn wrote: Vim supports syntax highlighting. But I don't use it either -- I find it distracts from clarity of thought. I use plain vanilla vim in a text-only terminal. I am halfway there: I use syntax highlighting in Emacs but I chose

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread Paulo Pinto via Digitalmars-d-learn
On Thursday, 8 January 2015 at 17:42:23 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Jan 08, 2015 at 11:29:29AM +, Laeeth Isharc via Digitalmars-d-learn wrote: this conversation is so funny: well what's wrong with this . It's a keyword... Aa Ha ha ha ha , rol. Seriously, is it

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 08, 2015 at 07:13:28PM +, Paulo Pinto via Digitalmars-d-learn wrote: On Thursday, 8 January 2015 at 17:42:23 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [...] Vim supports syntax highlighting. But I don't use it either -- I find it distracts from clarity of thought. I

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Baz via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 15:04:24 UTC, Paulo Pinto wrote: On Wednesday, 7 January 2015 at 15:02:34 UTC, Laeeth Isharc wrote: Not true. If you're using a tree structure, you *should* use pointers. Unless you're using classes, which are by-reference, in which case you can just use the

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 23:27:19 UTC, anonymous wrote: Don't do this without `dup`ing. Quoting the documentation: Oh, whoops. I thought those special variadic args were always allocated on the heap.

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread anonymous via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 20:25:10 UTC, Meta wrote: struct Tree { this(string data, Tree[] children...) { this.data = data; this.children = children; Don't do this without `dup`ing. Quoting the documentation: An implementation may construct the object or array

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 16:17:47 UTC, Tobias Pankrath wrote: A slice seems overkill to refer to just one object, but is that the best way ? struct Tree { Tree[] children; } Is one way to do it. You can add some nice sugar for this as well: struct Tree { this(string data,

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Laeeth Isharc via Digitalmars-d-learn
ref is a reserved keyword. doh! Thanks.

idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Laeeth Isharc via Digitalmars-d-learn
Another schoolboy question. Suppose I am constructing a tree (in this case it is an AST). In C I would have a pointer for the child to find the parent, and an array or linked list of pointers to find the children from the parent. Obviously, I could still use pointers, but that would not be

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Tobias Pankrath via Digitalmars-d-learn
A slice seems overkill to refer to just one object, but is that the best way ? struct Tree { Tree[] children; } Is one way to do it.

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 07, 2015 at 02:52:51PM +, Laeeth Isharc via Digitalmars-d-learn wrote: Another schoolboy question. Suppose I am constructing a tree (in this case it is an AST). In C I would have a pointer for the child to find the parent, and an array or linked list of pointers to find the

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Laeeth Isharc via Digitalmars-d-learn
Not true. If you're using a tree structure, you *should* use pointers. Unless you're using classes, which are by-reference, in which case you can just use the class as-is. :-) Thanks v much. I just came to that realization also when I stepped away. class node { string name;

Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?

2015-01-07 Thread Paulo Pinto via Digitalmars-d-learn
On Wednesday, 7 January 2015 at 15:02:34 UTC, Laeeth Isharc wrote: Not true. If you're using a tree structure, you *should* use pointers. Unless you're using classes, which are by-reference, in which case you can just use the class as-is. :-) Thanks v much. I just came to that realization

Re: Idiomatic D?

2014-01-31 Thread qznc
kind of things should some one think about if they are trying to do idiomatic D? There is no official idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most

Re: Idiomatic D?

2014-01-31 Thread Dicebot
On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: There is no official idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most attention from most

Re: Idiomatic D?

2014-01-30 Thread Dicebot
On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote: I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to do idiomatic D? There is no official idiomatic style like

Idiomatic D?

2014-01-30 Thread Tofu Ninja
I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to do idiomatic D?

Re: Idiomatic D?

2014-01-30 Thread Tofu Ninja
to do idiomatic D? There is no official idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most attention from most experienced D developers. Got any tips?

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote: On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: Got any tips? Ranges, templates and structs. ~= CTFE ~ UFCS

Re: Idiomatic D?

2014-01-30 Thread Meta
kind of things should some one think about if they are trying to do idiomatic D? There is no official idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most

Re: Idiomatic D?

2014-01-30 Thread Meta
On Friday, 31 January 2014 at 00:09:34 UTC, Stanislav Blinov wrote: On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote: On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote: Got any tips? Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared

Re: Idiomatic D?

2014-01-30 Thread Meta
On Friday, 31 January 2014 at 00:17:47 UTC, Stanislav Blinov wrote: On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared :

Re: Idiomatic D?

2014-01-30 Thread Matt Soucy
On 01/30/2014 07:17 PM, Stanislav Blinov wrote: On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared ); //

Re: Idiomatic D?

2014-01-30 Thread Kelet
On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote: I hear it thrown around a lot but what does it actually mean? What does the ideal D code look like? What kind of things should some one think about if they are trying to do idiomatic D? Here is one of the few previous threads

Re: Idiomatic D?

2014-01-30 Thread Stanislav Blinov
On Friday, 31 January 2014 at 04:53:48 UTC, Matt Soucy wrote: Ranges, templates and structs. ~= CTFE ~ UFCS ~= std.algorithm ~ std.range ~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared ); // Sorry but that was going to cause a slight

Re: Idiomatic D?

2012-06-18 Thread Matt Diesel
Sorry, forgot to post the code: http://pastie.org/4109337 Is there no way to edit posts?

Idiomatic D?

2012-06-18 Thread Matt Diesel
it useful it's always better to write it the way it was meant to be written. Firstly, is there any good resource on what idiomatic D usage is? For instance Go has a huge page called Effective Go which tells you how you should use features, rather than what they are. And secondly, I would be grateful

Re: Idiomatic D?

2012-06-18 Thread bearophile
Matt Diesel: Firstly, is there any good resource on what idiomatic D usage is? For instance Go has a huge page called Effective Go which tells you how you should use features, rather than what they are. I don't know any such page, but it looks like an interesting addition for the online

Re: Idiomatic D?

2012-06-18 Thread Justin Whear
On Mon, 18 Jun 2012 18:22:34 +0200, Matt Diesel wrote: Sorry, forgot to post the code: http://pastie.org/4109337 Is there no way to edit posts? A couple of observations: - According to the D style guide (http://dlang.org/dstyle.html), you should prefer to capitalize class and struct

Re: Idiomatic D?

2012-06-18 Thread Matt Diesel
Thanks to both of you, that was exactly the sort of input I was looking for :) The D Style guide looks like what I wanted. It's more just about formatting but that should be enough for now. I can't really reply to each individual point, but there is a lot of new stuff there that at first

Re: Idiomatic D?

2012-06-18 Thread Jonathan M Davis
teach myself a language no problem, but to make it useful it's always better to write it the way it was meant to be written. Firstly, is there any good resource on what idiomatic D usage is? For instance Go has a huge page called Effective Go which tells you how you should use features, rather