Re: Adam D. Ruppe's D Cookbook now available!

2014-06-11 Thread Jacob Carlborg via Digitalmars-d-announce

On 10/06/14 19:43, Adam D. Ruppe wrote:


blargh, I thought it could do more. Does it at least work to pull out
extern C functions from a C++ header?


Hmm, I haven't tried that. You need to specified which language to use. 
Currently DStep has hard coded its language support, in which C++ is not 
included.


It starts to get more complicate if it needs to support multiple 
languages in the same file. It should be possible, but then I think 
every declaration will need to be prefixed with extern (C).


--
/Jacob Carlborg


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-10 Thread Lars T. Kyllingstad via Digitalmars-d-announce

On Friday, 30 May 2014 at 11:48:57 UTC, Chris wrote:
There's _always_ something you can learn, even if you think you 
know it all.


Like the fact that you can @disable this() for a struct, even 
though you can't implement it. I didn't know that, but I have the 
perfect use case for it (and it's one which has bothered me for a 
long time). Thanks, Adam!


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-10 Thread Adam D. Ruppe via Digitalmars-d-announce

On Monday, 9 June 2014 at 19:14:15 UTC, Jacob Carlborg wrote:
Adam, I noticed that you mentioned DStep in the book. By 
reading the part about integrating with C++ I got the 
impression that DStep can handle C++. Currently, that's not the 
case.


blargh, I thought it could do more. Does it at least work to pull 
out extern C functions from a C++ header?


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-10 Thread Adam D. Ruppe via Digitalmars-d-announce
On Tuesday, 10 June 2014 at 17:31:52 UTC, Lars T. Kyllingstad 
wrote:
Like the fact that you can @disable this() for a struct, even 
though you can't implement it.


If my memory is working properly I actually think I was the one 
who suggested that to Walter a few years ago when it was 
introduced, though odds are I stole the idea from somebody else 
first and my memory is just a bit selectively egotistical :P


But I think @disable is a really cool thing for so many reasons. 
The two first ideas I had with it was the not null and ranged 
integer structs. Then the move semantics can come from it too. So 
can selectively disabling other operator overloads; forwarding 
most things to a member but filtering out some operations.


Disabling default construction still has a few compiler bugs so 
it isn't watertight but I've found it is really nice to have.


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-09 Thread Jacob Carlborg via Digitalmars-d-announce

On 2014-05-28 20:14, Walter Bright wrote:

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book


http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/


After watching Adam's most excellent presentation at Dconf, I'm sure the
book will be great! My copy gets here on Friday.


Adam, I noticed that you mentioned DStep in the book. By reading the 
part about integrating with C++ I got the impression that DStep can 
handle C++. Currently, that's not the case.


--
/Jacob Carlborg


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-06 Thread Chris via Digitalmars-d-announce

On Thursday, 5 June 2014 at 17:48:44 UTC, Jacob Carlborg wrote:

On 2014-06-05 11:25, Chris wrote:

My hard copy arrived today. Now I can read it anywhere I like 
;)


Funnily enough, it's only the second book about D and still 
I've been
more productive in D than in any other language, languages for 
which

thousands of titles are available.


There's a book about D1 and Tango as well. Also some Chinese 
book, or that might have been a translation.


There's Ali's online tutorial, of course. Great stuff. But a 
cookbook was really the thing I needed. Just to pick it up and to 
know How to send an email is great.


A lot of stuff here on the forum is about language design, which 
made D what it is. However, a lot of things in programming are 
plain and simple everyday problems like having your program send 
an email. I recently told a coworker to have a look at D and 
maybe use it for his number crunching algorithms. You can get far 
in D without templates, mixins and ranges. You don't need to 
learn them before you can use the language. You learn about them 
as you go along. You can dig right in. Maybe that's part of the 
reasons why people are reluctant to use D. They think you have to 
be a rocket scientist to write a program. You don't. But it will 
turn you into one :-)


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-05 Thread Chris via Digitalmars-d-announce

On Wednesday, 4 June 2014 at 09:45:39 UTC, ezneh wrote:

On Wednesday, 28 May 2014 at 18:14:28 UTC, Walter Bright wrote:

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, 
I'm sure the book will be great! My copy gets here on Friday.



Just received mine in the mail =)

I now have something interesting to read ;)


My hard copy arrived today. Now I can read it anywhere I like ;)

Funnily enough, it's only the second book about D and still I've 
been more productive in D than in any other language, languages 
for which thousands of titles are available.


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-05 Thread Jacob Carlborg via Digitalmars-d-announce

On 2014-06-05 11:25, Chris wrote:


My hard copy arrived today. Now I can read it anywhere I like ;)

Funnily enough, it's only the second book about D and still I've been
more productive in D than in any other language, languages for which
thousands of titles are available.


There's a book about D1 and Tango as well. Also some Chinese book, or 
that might have been a translation.


--
/Jacob Carlborg


Re: Adam D. Ruppe's D Cookbook now available!

2014-06-01 Thread WhatMeWorry via Digitalmars-d-announce


I am happy to report that it is on Safari Books website as well. 
Sweet!


It really compliment's TDPL and Ali's book as well.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Mike James via Digitalmars-d-announce
Walter Bright newshou...@digitalmars.com wrote in message 
news:lm5924$7r8$1...@digitalmars.com...

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, I'm sure the 
book will be great! My copy gets here on Friday.


Just got a copy - now I need the time to read it... :-)

-=mike=- 



Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Chris via Digitalmars-d-announce

On Friday, 30 May 2014 at 09:07:54 UTC, Mike James wrote:
Walter Bright newshou...@digitalmars.com wrote in message 
news:lm5924$7r8$1...@digitalmars.com...

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, 
I'm sure the book will be great! My copy gets here on Friday.


Just got a copy - now I need the time to read it... :-)

-=mike=-


If you already know D, you don't need to read it cover-to-cover. 
Just read the sexy bits :)


(Although I will read it thoroughly one day when I find the time. 
The good thing is, you don't need to read it c-t-c to make it 
work for you, like, errr, a cookbook.)


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread w0rp via Digitalmars-d-announce
I received my copy this morning, earlier than I thought I would. 
I shall check it out over the weekend. I suspect I'll probably 
know a lot of the things in the book, but I'm the type who likes 
to watch introductory lectures because there's always something I 
didn't see before.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Chris via Digitalmars-d-announce

On Friday, 30 May 2014 at 11:46:35 UTC, w0rp wrote:
I received my copy this morning, earlier than I thought I 
would. I shall check it out over the weekend. I suspect I'll 
probably know a lot of the things in the book, but I'm the type 
who likes to watch introductory lectures because there's always 
something I didn't see before.


You're right, of course. There's _always_ something you can 
learn, even if you think you know it all.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Adam D. Ruppe via Digitalmars-d-announce

On Friday, 30 May 2014 at 11:25:45 UTC, Chris wrote:
If you already know D, you don't need to read it 
cover-to-cover. Just read the sexy bits :)


Yea, I also tried to keep the dependencies on previous content to 
a minimum or at the least, explicit to make jumping around that 
much easier.


That said though, after the first few pages, I tried to say 
things that are at least interesting to the target intermediate+ 
audience; like page one talks about installing dmd, boring, but 
by page 4 I tried to answer a FAQ about modules and also worked 
my agenda to clear up the directory structure common 
misconception Modules have logical names that do not need to 
match the filename. which is something you can get work done 
without knowing; it might be new even to someone who has used D 
before and understanding this can make sense of a number of 
compile/link errors that come up.


So, while I feel chapters one and two are the weakest links (and 
I definitely dropped the ball on editing the code on chapter 
one), hopefully none of the stuff is outright useless even if 
you've seen it before and have read the website documentation.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Adam D. Ruppe via Digitalmars-d-announce

On Friday, 30 May 2014 at 11:46:35 UTC, w0rp wrote:

I received my copy this morning, earlier than I thought I would.


I still haven't gotten my copies! Hopefully will be here today 
though.



I suspect I'll probably know a lot of the things in the book


Yea, especially if you're a regular on the ng or irc, though you 
never know :P



BTW if any of you who has read it want to write amazon reviews, 
make it so!


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Chris via Digitalmars-d-announce

On Friday, 30 May 2014 at 13:25:28 UTC, Adam D. Ruppe wrote:

On Friday, 30 May 2014 at 11:25:45 UTC, Chris wrote:
If you already know D, you don't need to read it 
cover-to-cover. Just read the sexy bits :)


Yea, I also tried to keep the dependencies on previous content 
to a minimum or at the least, explicit to make jumping around 
that much easier.


That said though, after the first few pages, I tried to say 
things that are at least interesting to the target 
intermediate+ audience; like page one talks about installing 
dmd, boring, but by page 4 I tried to answer a FAQ about 
modules and also worked my agenda to clear up the directory 
structure common misconception Modules have logical names that 
do not need to match the filename. which is something you can 
get work done without knowing; it might be new even to someone 
who has used D before and understanding this can make sense of 
a number of compile/link errors that come up.


So, while I feel chapters one and two are the weakest links 
(and I definitely dropped the ball on editing the code on 
chapter one), hopefully none of the stuff is outright useless 
even if you've seen it before and have read the website 
documentation.


Yep. I read bits of Chapter 1 and learned things I didn't know 
yet. No matter how much you know, something always escapes you. 
I've learned tricks even from bad musicians (like the AK 47 
thing).


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Jonathan M Davis via Digitalmars-d-announce
On Fri, 30 May 2014 11:48:56 +
Chris via Digitalmars-d-announce digitalmars-d-announce@puremagic.com
wrote:

 On Friday, 30 May 2014 at 11:46:35 UTC, w0rp wrote:
  I received my copy this morning, earlier than I thought I
  would. I shall check it out over the weekend. I suspect I'll
  probably know a lot of the things in the book, but I'm the type
  who likes to watch introductory lectures because there's always
  something I didn't see before.

 You're right, of course. There's _always_ something you can
 learn, even if you think you know it all.

What I find sometimes is that even if I know most things about something, I
still forget things that I knew (particularly if I don't use that knowledge
regularly), so reading something like this could jog your memory about things
and thus improve your knowledge, even if you actually had known all of it at
some point (though the odds are still that there are at least a few things
in it that you never learned, even if you know a lot).

- Jonathan M Davis


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-30 Thread Dejan Lekic via Digitalmars-d-announce
Walter Bright wrote:

 http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book
 
 http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217
 
 
http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/
 
 After watching Adam's most excellent presentation at Dconf, I'm sure the
 book will be great! My copy gets here on Friday.

https://drive.google.com/file/d/0BzpDFld47vULS1VSZl9JaG1PMkk

:D

-- 
http://dejan.lekic.org


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Jacob Carlborg via Digitalmars-d-announce

On 2014-05-28 20:14, Walter Bright wrote:

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book


http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/


After watching Adam's most excellent presentation at Dconf, I'm sure the
book will be great! My copy gets here on Friday.


I've already bought the ebook version.

--
/Jacob Carlborg


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread simendsjo via Digitalmars-d-announce
On 05/29/2014 11:51 AM, Jacob Carlborg wrote:
 On 2014-05-28 20:14, Walter Bright wrote:
 http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book



 http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

 http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/



 After watching Adam's most excellent presentation at Dconf, I'm sure the
 book will be great! My copy gets here on Friday.
 
 I've already bought the ebook version.
 

Ditto. Just had time to look at the ToC though. Really looking forward
to reading it (and all the dconf talks)


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Chris via Digitalmars-d-announce

On Wednesday, 28 May 2014 at 18:14:28 UTC, Walter Bright wrote:

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, I'm 
sure the book will be great! My copy gets here on Friday.


I dug into Chapter 3 about ranges. It clarifies a lot of things 
about ranges. These little questions I kept asking my self, like 
is this good practice or a hack? etc. Thanks to one of his 
examples (+explanation) I've already been able to improve my 
production code. Thanks a million Adam!


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Philippe Sigaud via Digitalmars-d-announce
On Thu, May 29, 2014 at 12:28 PM, Chris via Digitalmars-d-announce
digitalmars-d-announce@puremagic.com wrote:
 On Wednesday, 28 May 2014 at 18:14:28 UTC, Walter Bright wrote:


 http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

 http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217


 http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

 After watching Adam's most excellent presentation at Dconf, I'm sure the
 book will be great! My copy gets here on Friday.

I bought it today, more D goodness, yummy.

btw, I bought it through Packt. It was cheaper and came with the
e-book version. Does Amazon also send you an electronic version along
the paper one?


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-announce

On Thursday, 29 May 2014 at 10:28:45 UTC, Chris wrote:
I dug into Chapter 3 about ranges. It clarifies a lot of things 
about ranges.


Yeah, a lot of the stuff there comes from my own process when 
writing my first range consuming function (which is still in a 
pretty ugly form in my sha.d on github, I have never really fixed 
it).


I had to ask on the newsgroup: what does it really mean to accept 
a generic input range? Does it mean to attempt data 
transformations to receive anything? Or is it semi-strict? (the 
answer is to take any input range but be strict on the element 
type - don't try to transform it yourself as that introduces bugs 
and hidden performance issues for the algorithm's user)


I didn't quite understand the answer until some time later and 
now I think it is fairly simple, but since I was so wrong about 
it for such a long while I figured other people probably had the 
same problems and tried to cover them in the book.


One of the sections there talks about emulating random access on 
a structure that doesn't really support it (a linked list) and 
focuses on the hidden performance. That's the range-writer side 
of the same range-consumer rule: don't try to get fancy and 
support something the underlying data doesn't natively do because 
then you'll introduce bugs and slowdowns that might be hard to 
find.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread uri via Digitalmars-d-announce

On Thursday, 29 May 2014 at 10:28:45 UTC, Chris wrote:

On Wednesday, 28 May 2014 at 18:14:28 UTC, Walter Bright wrote:

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, 
I'm sure the book will be great! My copy gets here on Friday.


I dug into Chapter 3 about ranges. It clarifies a lot of things 
about ranges. These little questions I kept asking my self, 
like is this good practice or a hack? etc. Thanks to one of 
his examples (+explanation) I've already been able to improve 
my production code. Thanks a million Adam!


+1, just purchased my copy :)


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Szymon Gatner via Digitalmars-d-announce

On Wednesday, 28 May 2014 at 18:14:28 UTC, Walter Bright wrote:

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, I'm 
sure the book will be great! My copy gets here on Friday.


A question(s) regarding Chapter 5: Making a reference-counted 
object:


(btw do we need separate thread for content-related questions?)

- point 5 (of How to do it...) says: ... and free the object if 
necessary, but then in code:


~this() {
  if(data is null) return;
  data.refcount--;
  writeln(Released. Refcount = , data.refcount);
  if(data.refcount == 0)
  writeln(Destroyed.);
}

is actual freeing missing? Or am I missing something?

Later in same chapter: ... or being collected by the garbage 
collector—its destructor is called, if present.


Is that really true? My understanding (and unfortunate test) is 
that it is never guaranteed that d-tor of GD allocated object is 
ever called. If that is the case then: is that true that dynamic 
array of RefCountedObject does not guarantee any of d-tors 
called? That would also mean that if any of objects in object 
graph is GC-allocated then NONE of its child nodes have any 
guarantees about destruction?


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Chris via Digitalmars-d-announce

On Thursday, 29 May 2014 at 12:45:20 UTC, Adam D. Ruppe wrote:

On Thursday, 29 May 2014 at 10:28:45 UTC, Chris wrote:
I dug into Chapter 3 about ranges. It clarifies a lot of 
things about ranges.


Yeah, a lot of the stuff there comes from my own process when 
writing my first range consuming function (which is still in a 
pretty ugly form in my sha.d on github, I have never really 
fixed it).


I have different types of range implementations throughout my 
code now, which basically depicts the learning process while I 
was trying to grasp the concept. I think the D website could do 
with something like your Chapter 3. It's not really rocket 
science, but when you have no guidelines, best practices 
whatsoever, you have to experiment yourself which always leaves a 
weird after taste, i.e. questions like is this really the right 
way? am I doing something wrong?.


I had to ask on the newsgroup: what does it really mean to 
accept a generic input range? Does it mean to attempt data 
transformations to receive anything? Or is it semi-strict? (the 
answer is to take any input range but be strict on the element 
type - don't try to transform it yourself as that introduces 
bugs and hidden performance issues for the algorithm's user)


Yes, I always adhered to this rule.

I didn't quite understand the answer until some time later and 
now I think it is fairly simple, but since I was so wrong about 
it for such a long while I figured other people probably had 
the same problems and tried to cover them in the book.


True, true. Your book was direly needed, and if it's just to 
clarify things. Sometimes I would feel like a fool to ask 
questions about ranges, thinking everybody understands them 
except for me. Once you get the hang of it, it's pretty straight 
forward.


One of the sections there talks about emulating random access 
on a structure that doesn't really support it (a linked list) 
and focuses on the hidden performance. That's the range-writer 
side of the same range-consumer rule: don't try to get fancy 
and support something the underlying data doesn't natively do 
because then you'll introduce bugs and slowdowns that might be 
hard to find.




Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Steven Schveighoffer via Digitalmars-d-announce
On Thu, 29 May 2014 06:20:51 -0400, Atila Neves atila.ne...@gmail.com  
wrote:



For some reason I didn't even know it was available as an ebook
until I read this. At which point I promptly bought it. Dead
trees and their lack of Ctrl-F... :)


To be fair, the physical book comes with access to the ebook.

But the reason for me to buy the ebook was simpler -- it's half the price  
:)


Still lack time to read it, but I like the AK47 tip (don't have one, but  
I'm sure it works for most rifles)!


-Steve


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-announce

On Thursday, 29 May 2014 at 13:12:33 UTC, Chris wrote:
a weird after taste, i.e. questions like is this really the 
right way? am I doing something wrong?.


I ask myself that a lot too, even the book isn't really meant to 
be authoritative, more like this works pretty well for me 
hopefully it works for you too.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-announce

On Thursday, 29 May 2014 at 13:01:50 UTC, Szymon Gatner wrote:
Later in same chapter: ... or being collected by the garbage 
collector—its destructor is called, if present.


Is that really true?


hmm, you seem to be right, but this might be a bug. I'm pretty 
sure the struct dtors were called on arrays not long ago but it 
isn't really reliable with the GC (My weasel word there is 
provably, sometimes the GC can't prove there are no references; 
false pointers etc) but still blargh this current reality seems 
weird.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Szymon Gatner via Digitalmars-d-announce

On Thursday, 29 May 2014 at 13:57:41 UTC, Adam D. Ruppe wrote:

On Thursday, 29 May 2014 at 13:01:50 UTC, Szymon Gatner wrote:
Later in same chapter: ... or being collected by the garbage 
collector—its destructor is called, if present.


Is that really true?


hmm, you seem to be right, but this might be a bug. I'm pretty 
sure the struct dtors were called on arrays not long ago but it 
isn't really reliable with the GC (My weasel word there is 
provably, sometimes the GC can't prove there are no 
references; false pointers etc) but still blargh this current 
reality seems weird.


:(

And the 1st question?


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Steven Schveighoffer via Digitalmars-d-announce
On Thu, 29 May 2014 09:57:40 -0400, Adam D. Ruppe  
destructiona...@gmail.com wrote:



On Thursday, 29 May 2014 at 13:01:50 UTC, Szymon Gatner wrote:
Later in same chapter: ... or being collected by the garbage  
collector—its destructor is called, if present.


Is that really true?


hmm, you seem to be right, but this might be a bug. I'm pretty sure the  
struct dtors were called on arrays not long ago but it isn't really  
reliable with the GC (My weasel word there is provably, sometimes the  
GC can't prove there are no references; false pointers etc) but still  
blargh this current reality seems weird.


The GC never has called struct destructors for arrays of structs or  
individual structs allocated on the heap.


It will call destructors on structs that are members of classes ONLY  
because the class destructor will call the struct destructor.


One other situation a heap allocated struct will have it's destructor  
called (I think) is due to a closure allocation, but I'm not 100% sure how  
that works. A way to verify is to make a closure occur, then test the  
closure's block to see if FINALIZE flag is set on it.


-Steve


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-announce

On Thursday, 29 May 2014 at 13:01:50 UTC, Szymon Gatner wrote:
- point 5 (of How to do it...) says: ... and free the object 
if necessary, but then in code:


Sorry, I typed this answer but forgot to actually post it. But to 
keep the example focused on postblit and destructor stuff instead 
of malloc/free so I used the writeln instead of the actual calls.


So all you'd have to do is do free() where it says Destroyed 
instead and alloc in the ctor.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-announce
On Thursday, 29 May 2014 at 14:42:02 UTC, Steven Schveighoffer 
wrote:
The GC never has called struct destructors for arrays of 
structs or individual structs allocated on the heap.


Hmm, that's some weird behavior.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Nick Sabalausky via Digitalmars-d-announce

On 5/29/2014 8:45 AM, Adam D. Ruppe wrote:


One of the sections there talks about emulating random access on a
structure that doesn't really support it (a linked list) and focuses on
the hidden performance. That's the range-writer side of the same
range-consumer rule: don't try to get fancy and support something the
underlying data doesn't natively do because then you'll introduce bugs
and slowdowns that might be hard to find.


FWIW, and in the spirit of maybe others could benefit too (not sure 
whether your book touches on this or not):


I *used to be* strongly opposed to what you suggest there, deliberately 
not emulating accesses the data doesn't support. Even had a big long 
debate over it with Andrei. My reasoning was that you should be able to 
swap different data structures in and out to find the best performance, 
because *even if* you're relying on an operation the underlying data 
doesn't support, it could still be such a *small* and infrequent 
reliance that the localized performance hit is overshadowed by improved 
performance in the rest of your code.


Seemed a perfectly sound argument to be, but then I realized: It's 
trivial to write an adapter to emulate features on ranges or containers 
that don't support them. Not only is this more re-usable (ex: only need 
to write a particular method of emulate random access once), but far 
more importantly, this makes the feature-emulation EXPLICIT instead of 
hidden.


The upshot of that is, if a range or container doesn't support some 
feature, you can *still* trivially have an emulated drop-in-replacement, 
and it's equally easy (or even easier still) but BETTER because it's 
explicit, not hidden.




Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-announce

Packt made an excerpt from the range chapter available too:

https://www.packtpub.com/article/ranges

That's from the tail end of the chapter where I started talking 
about emulation performance (relevant to this little convo) and 
how to put some stuff together.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-29 Thread Philippe Sigaud via Digitalmars-d-announce
On Thu, May 29, 2014 at 2:31 PM, Jacob Carlborg wrote:
 Amazon has a version for their Kindle [1]. I have not seen any mentioning of
 other formats.

 [1]
 http://www.amazon.com/D-Cookbook-Adam-D-Ruppe-ebook/dp/B00KLAJ62M/ref=sr_1_1_title_1_kin?s=booksie=UTF8qid=1401366690sr=1-1

But the paper edition does not come with the electronic version,
contrary to a buy through Packt. Anyway, I'm already throwing far too
much money at Amazon all year long :-)

Now for some time to read this book...


Adam D. Ruppe's D Cookbook now available!

2014-05-28 Thread Walter Bright via Digitalmars-d-announce

http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book

http://www.amazon.com/D-Cookbook-Adam-D-Ruppe/dp/1783287217

http://www.reddit.com/r/programming/comments/26pn00/d_cookbook_officially_published_consists_of_d/

After watching Adam's most excellent presentation at Dconf, I'm sure the book 
will be great! My copy gets here on Friday.


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-28 Thread Olivier Pisano via Digitalmars-d-announce

I have just ordered mine. I can't wait to get it ! 


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-28 Thread Misu via Digitalmars-d-announce

Thank you, I ordered mine as well !


Re: Adam D. Ruppe's D Cookbook now available!

2014-05-28 Thread Szymon Gatner via Digitalmars-d-announce

On Wednesday, 28 May 2014 at 19:06:04 UTC, Misu wrote:

Thank you, I ordered mine as well !


I am already half through mine :) Great stuff!