Re: Get memory used by current process at specific point in time

2020-01-13 Thread Per Nordlöw via Digitalmars-d-learn

On Monday, 13 January 2020 at 20:08:19 UTC, Jacob Carlborg wrote:

On 2020-01-12 14:58, Per Nordlöw wrote:
Is there a druntime/phobos function for getting the amount of 
memory (both, stack, malloc, and GC) being used by the current 
process?


I don't think so. But if you're on macOS you can use 
Instruments (shipped with Xcode) and pick the Allocations 
template.


I'm sitting on Linux :)

Thanks anway


Re: Invalid memory operation during allocation with `new`

2020-01-13 Thread Per Nordlöw via Digitalmars-d-learn

On Monday, 13 January 2020 at 20:30:33 UTC, Adam D. Ruppe wrote:

Reading symbols from pain...
(gdb) break onInvalidMemoryOperationError
Breakpoint 1 at 0x4614f8
(gdb) r
Starting program: /home/me/test/pain
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".


Thanks a lot.

Unfortunately that didn't tell me the cause of the problem but 
only the stack trace of the failing call to `new` which is not 
called inside a destructor.


Re: How to create meson.build with external libs?

2020-01-13 Thread p.shkadzko via Digitalmars-d-learn

On Monday, 13 January 2020 at 20:53:43 UTC, p.shkadzko wrote:

On Monday, 13 January 2020 at 19:56:35 UTC, p.shkadzko wrote:

On Monday, 13 January 2020 at 17:14:29 UTC, p.shkadzko wrote:

[...]


I had to set PKG_CONFIG_PATH to "/usr/local/lib/pkgconfig". 
For some reason Manjaro distro doesn't have it set by default. 
After setting the pkgconfig path, lubeck is getting found and 
everything works.


After I ran "meson build" I got the following output:
---
The Meson build system
Version: 0.52.1
Source dir: /home/tastyminerals/dev/test_proj
Build dir: /home/tastyminerals/dev/test_proj/build
Build type: native build
Project name: mir_quickstart
Project version: 0.1
D compiler for the host machine: ldc2 (llvm 1.18.0 "LDC - the 
LLVM D compiler (1.18.0):")

D linker for the host machine: GNU ld.gold 2.33.1
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (1.6.3)
Run-time dependency mir-algorithm found: YES 3.4.0
Run-time dependency lubeck found: YES 1.0.0
Build targets in project: 1
Found ninja-1.9.0 at /usr/bin/ninja

I then cd to build/ dir and run "ninja"

[2/2] Linking target test_proj.tart@exe/app.d.o'.

But when I try to run compiled app.d file as demo_run, I get:

./demo_run: error while loading shared libraries: 
libmir-algorithm.so: cannot open shared object file: No such 
file or directory


I thought that if meson builds and finds the external libs 
successfully and ninja links everything, all should be fine. I 
don't understand. Why the compiled file cannot find the 
external library?


$LD_LIBRARY_PATH was not set to "/usr/local/lib" where 
libmir-algorithm.so is located. I had to set it explicitly and 
recompile the project but then I get another error message:


./demo_proj: error while loading shared libraries: 
subprojects/mir-algorithm/libmir-algorithm.so.3.4.0: cannot open 
shared object file: No such file or directory



(ಠ_ಠ)


Re: How to create meson.build with external libs?

2020-01-13 Thread p.shkadzko via Digitalmars-d-learn

On Monday, 13 January 2020 at 19:56:35 UTC, p.shkadzko wrote:

On Monday, 13 January 2020 at 17:14:29 UTC, p.shkadzko wrote:
On Sunday, 12 January 2020 at 22:12:14 UTC, Rasmus Thomsen 
wrote:

On Sunday, 12 January 2020 at 22:00:33 UTC, p.shkadzko wrote:

[...]


In difference to dub, meson will _not_ auto-download required 
software for you. You have to ways to go forward with this:


[...]


I followed the 1 step, namely git cloned the lubeck and 
installed it with meson into /usr/local however, I still get 
the same error. Could I miss anything?


I had to set PKG_CONFIG_PATH to "/usr/local/lib/pkgconfig". For 
some reason Manjaro distro doesn't have it set by default. 
After setting the pkgconfig path, lubeck is getting found and 
everything works.


After I ran "meson build" I got the following output:
---
The Meson build system
Version: 0.52.1
Source dir: /home/tastyminerals/dev/test_proj
Build dir: /home/tastyminerals/dev/test_proj/build
Build type: native build
Project name: mir_quickstart
Project version: 0.1
D compiler for the host machine: ldc2 (llvm 1.18.0 "LDC - the 
LLVM D compiler (1.18.0):")

D linker for the host machine: GNU ld.gold 2.33.1
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (1.6.3)
Run-time dependency mir-algorithm found: YES 3.4.0
Run-time dependency lubeck found: YES 1.0.0
Build targets in project: 1
Found ninja-1.9.0 at /usr/bin/ninja

I then cd to build/ dir and run "ninja"

[2/2] Linking target test_proj.tart@exe/app.d.o'.

But when I try to run compiled app.d file as demo_run, I get:

./demo_run: error while loading shared libraries: 
libmir-algorithm.so: cannot open shared object file: No such file 
or directory


I thought that if meson builds and finds the external libs 
successfully and ninja links everything, all should be fine. I 
don't understand. Why the compiled file cannot find the external 
library?


Re: Compilation error: undefined reference to 'cblas_dgemv' / 'cblas_dger' / 'cblas_dgemm'

2020-01-13 Thread p.shkadzko via Digitalmars-d-learn

On Sunday, 12 January 2020 at 13:07:33 UTC, dnsmt wrote:

On Saturday, 11 January 2020 at 16:45:22 UTC, p.shkadzko wrote:
I am trying to run example code from 
https://tour.dlang.org/tour/en/dub/lubeck


...

This is Linux Manjaro with openblas package installed.


The Lubeck library depends on CBLAS, but the openblas package 
in the Arch repository is compiled without CBLAS. You can see 
that here (note the NO_CBLAS=1 parameter): 
https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/openblas


Try installing the cblas package: 
https://www.archlinux.org/packages/extra/x86_64/cblas/


yeah, so I thought too but I have CBLAS installed as a distro 
package. I also have OpenBLAS installed instead of BLAS because 
BLAS was removed since it conflicts with OpenBLAS ¯\_(ツ)_/¯


Re: Invalid memory operation during allocation with `new`

2020-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 13 January 2020 at 09:34:42 UTC, Per Nordlöw wrote:
Without finding any potential problems. Any other suggestions 
on how to trace this problem?


Run the program in a debugger with the `--DRT-trapExceptions=0` 
argument to the program with certain versions of druntime, or set 
a breakpoint at that function.


On Linux for example, I made a program "pain" that deliberately 
crashes:


-

$ gdb pain
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 


This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-slackware-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from pain...
(gdb) break onInvalidMemoryOperationError
Breakpoint 1 at 0x4614f8
(gdb) r
Starting program: /home/me/test/pain
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, 0x004614f8 in onInvalidMemoryOperationError 
()

(gdb) where
#0  0x004614f8 in onInvalidMemoryOperationError ()
#1  0x0045da4b in 
_D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs12mallocNoSyncMFNbmkKmxC8TypeInfoZPvS_DQEgQEgQEeQEp10mallocTimelS_DQFiQFiQFgQFr10numMallocslTmTkTmTxQCzZQFcMFNbKmKkKmKxQDsZQDl ()
#2  0x00455a6e in 
_D2gc4impl12conservativeQw14ConservativeGC6mallocMFNbmkxC8TypeInfoZPv ()

#3  0x0043546b in gc_malloc ()
#4  0x0043160b in _d_newclass ()
#5  0x0042f65c in pain.Foo.~this() (this=0x77af1000) 
at pain.d:3

#6  0x0043671c in rt_finalize2 ()
#7  0x00460647 in rt_finalizeFromGC ()
#8  0x00459790 in 
_D2gc4impl12conservativeQw3Gcx5sweepMFNbZm ()
#9  0x0045a202 in 
_D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm ()
#10 0x0045e408 in 
_D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs18fullCollectNoStackMFNbZ2goFNbPSQEaQEaQDyQEj3GcxZmTQvZQDfMFNbKQBgZm ()
#11 0x00456f38 in 
_D2gc4impl12conservativeQw14ConservativeGC18fullCollectNoStackMFNbZv ()
#12 0x00456ed6 in 
_D2gc4impl12conservativeQw14ConservativeGC14collectNoStackMFNbZv 
()

#13 0x00446e21 in gc_term ()
#14 0x00435bc3 in rt_term ()
#15 0x00430882 in 
_D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv ()
#16 0x00430769 in 
_D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv ()

#17 0x004306d2 in _d_run_main2 ()
#18 0x0043048e in _d_run_main ()
#19 0x0042f6a2 in main ()
#20 0x77c19e5b in __libc_start_main () from 
/lib64/libc.so.6

(gdb)

-


So, first make a debug build of the program (dmd -g pain.d). 
Then, run the program in the debugger:


gdb ./pain

And then ask the debugger to break on this invalid operation:

break onInvalidMemoryOperationError

NOTE: the onInvalidMemoryOperationError is actually a function 
time inside druntime.


Then run the program with gdb's `r` command.

It breaks when that function is called, right before it actually 
would throw


Breakpoint 1, 0x004614f8 in onInvalidMemoryOperationError 
()


So then I asked the debugger where this occurred:

(gdb) where

And visually scanned for a function I recognized (and my gdb also 
conveniently highlighted the filename in green)


#5  0x0042f65c in pain.Foo.~this() (this=0x77af1000) 
at pain.d:3


That looks like my code! pain.d line 3 caused the problem.

class Foo {
~this() {
auto a = new Object(); // this
}
}

void main() {
auto foo = new Foo();
}


It might not be this simple in a real bug situation - this 
program was specifically written to cause it - but the same 
approach should narrow it down pretty quickly for you.


Re: Get memory used by current process at specific point in time

2020-01-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2020-01-12 14:58, Per Nordlöw wrote:
Is there a druntime/phobos function for getting the amount of memory 
(both, stack, malloc, and GC) being used by the current process?


I don't think so. But if you're on macOS you can use Instruments 
(shipped with Xcode) and pick the Allocations template.


--
/Jacob Carlborg


Re: How to create meson.build with external libs?

2020-01-13 Thread p.shkadzko via Digitalmars-d-learn

On Monday, 13 January 2020 at 17:14:29 UTC, p.shkadzko wrote:
On Sunday, 12 January 2020 at 22:12:14 UTC, Rasmus Thomsen 
wrote:

On Sunday, 12 January 2020 at 22:00:33 UTC, p.shkadzko wrote:

[...]


In difference to dub, meson will _not_ auto-download required 
software for you. You have to ways to go forward with this:


[...]


I followed the 1 step, namely git cloned the lubeck and 
installed it with meson into /usr/local however, I still get 
the same error. Could I miss anything?


I had to set PKG_CONFIG_PATH to "/usr/local/lib/pkgconfig". For 
some reason Manjaro distro doesn't have it set by default. After 
setting the pkgconfig path, lubeck is getting found and 
everything works.


Re: Fetching an element using find

2020-01-13 Thread lithium iodate via Digitalmars-d-learn
On Monday, 13 January 2020 at 17:58:57 UTC, Steven Schveighoffer 
wrote:

On 1/13/20 12:47 PM, H. S. Teoh wrote:


Why not write your own convenience wrapper?

auto firstElement(R)(R r)
if (isInputRange!R)
{
if (r.empty) throw new Exception(...);
return r.front;
}

auto e = myData.find!(e => blah(e)).firstElement;


I certainly can (and did). I was wondering if there was 
something in Phobos to do it.


-Steve


`adjoin` can be used to run an inline lambda:
auto answer = arr.find!((item,x) => item.id == 
x)(id).adjoin!((n){enforce(!n.empty); return n.front;});


Using a simple alias you can have a flexible and nice to read 
solution:
alias ensure(alias pred) = (n, const(char)[] msg = "`ensure` 
failed"){enforce(pred(n), msg); return n;}; // module scope for 
UFCS!


auto answer = arr.find!((item,x) => item.id == x)(id).ensure!(n 
=> !n.empty).front;

or with custom message:
auto answer = arr.find!((item,x) => item.id == x)(id).ensure!(n 
=> !n.empty)("element with id not found").front;


Re: Fetching an element using find

2020-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2020 at 12:58:57PM -0500, Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> On 1/13/20 12:47 PM, H. S. Teoh wrote:
> > 
> > Why not write your own convenience wrapper?
> > 
> > auto firstElement(R)(R r)
> > if (isInputRange!R)
> > {
> > if (r.empty) throw new Exception(...);
> > return r.front;
> > }
> > 
> > auto e = myData.find!(e => blah(e)).firstElement;
> 
> I certainly can (and did). I was wondering if there was something in
> Phobos to do it.
[...]

Maybe add a new function to Phobos? :-D


T

-- 
It always amuses me that Windows has a Safe Mode during bootup. Does that mean 
that Windows is normally unsafe?


Re: Fetching an element using find

2020-01-13 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/13/20 12:47 PM, H. S. Teoh wrote:


Why not write your own convenience wrapper?

auto firstElement(R)(R r)
if (isInputRange!R)
{
if (r.empty) throw new Exception(...);
return r.front;
}

auto e = myData.find!(e => blah(e)).firstElement;


I certainly can (and did). I was wondering if there was something in 
Phobos to do it.


-Steve


Re: Fetching an element using find

2020-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2020 at 12:39:30PM -0500, Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> I have a range (array), I want to find an element and get it from that
> array.
> 
> The code I'm writing looks like this:
> 
> auto answer = arr.find!((item,x) => item.id == x)(id);
> enforce(!answer.empty, "id not in the range");
> auto realAnswer = answer.front;
> 
> I can't do find(id).front, because that relies on asserts, which throw
> errors and kill the program, and are not always compiled in. I need an
> exception thrown so I can recover and report the error to the user.
> 
> But I hate to write 3 lines of code to do this every time.
> 
> I'm not seeing an easy solution in Phobos, am I missing it?
[...]

Why not write your own convenience wrapper?

auto firstElement(R)(R r)
if (isInputRange!R)
{
if (r.empty) throw new Exception(...);
return r.front;
}

auto e = myData.find!(e => blah(e)).firstElement;


T

-- 
I think Debian's doing something wrong, `apt-get install pesticide', doesn't 
seem to remove the bugs on my system! -- Mike Dresser


Fetching an element using find

2020-01-13 Thread Steven Schveighoffer via Digitalmars-d-learn
I have a range (array), I want to find an element and get it from that 
array.


The code I'm writing looks like this:

auto answer = arr.find!((item,x) => item.id == x)(id);
enforce(!answer.empty, "id not in the range");
auto realAnswer = answer.front;

I can't do find(id).front, because that relies on asserts, which throw 
errors and kill the program, and are not always compiled in. I need an 
exception thrown so I can recover and report the error to the user.


But I hate to write 3 lines of code to do this every time.

I'm not seeing an easy solution in Phobos, am I missing it?

-Steve


Re: books for learning D

2020-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2020 at 04:23:19AM -0800, Ali Çehreli via Digitalmars-d-learn 
wrote:
> On 1/13/20 2:28 AM, mark wrote:
> > I'm just starting out learning D.
> > 
> > Andrei Alexandrescu's "The D Programming Language" is 10 years old,
> > so is it still worth getting? (I don't know how much D has changed
> > in 10 years.)
[...]

I think it's still worth it.  The basics of the language haven't changed
that much.  Plus, for your reference, here's Andrei errata that updates
the book in a few places:

https://erdani.com/tdpl/errata/


T

-- 
"Outlook not so good." That magic 8-ball knows everything! I'll ask about 
Exchange Server next. -- (Stolen from the net)


Re: How to create meson.build with external libs?

2020-01-13 Thread p.shkadzko via Digitalmars-d-learn

On Sunday, 12 January 2020 at 22:12:14 UTC, Rasmus Thomsen wrote:

On Sunday, 12 January 2020 at 22:00:33 UTC, p.shkadzko wrote:

[...]


In difference to dub, meson will _not_ auto-download required 
software for you. You have to ways to go forward with this:


[...]


I followed the 1 step, namely git cloned the lubeck and installed 
it with meson into /usr/local however, I still get the same 
error. Could I miss anything?


Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn

On Monday, 13 January 2020 at 16:37:31 UTC, Ron Tarrant wrote:
Actually, Andrei's book has been updated a few times over the 
years since first being published. The latest version says this 
on the copyright page:


D version: 2.081.1
Book revision: 2018-10-17

So, it's really only about 14 months old.


Is that an ebook edition? The "look inside" of the physical book 
shows "First Printing, May 2010".


Re: books for learning D

2020-01-13 Thread Pavel Shkadzko via Digitalmars-d-learn

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D has 
changed in 10 years.)


Start with "Programming in D" by Ali: 
http://ddili.org/ders/d.en/index.html
A good all-rounder book for any level, you can easily skip the 
chapters if you already know the domain. It starts slowly with a 
lot of detail (which I personally liked) but then gets a bit 
rushed and sketchy in the end still a **must-read** for anyone 
who comes from Python or any other "high level" language since a 
lot of things will be new to you.


After studying Ali's book you will be pretty much ready to code, 
in fact you'll be ready to code in roughly a week or so since D 
is such an easy language to pick up ;)


Then you can go straight to "D Cookbook" by Adam: 
https://dlang.org/blog/2016/08/04/the-origins-of-the-d-cookbook/
Don't start this book if you don't know D at least a little or if 
you're quite experienced with C++. I find that C++ devs can 
quickly jump to D. The book is basically a collection of various 
problems and solutions in D with nice explanations. I am still on 
it.


"The D Programming Language" book by Andrei: 
https://www.amazon.com/gp/product/0321635361/ref=as_li_qf_sp_asin_il_tl?ie=UTF8=1789=9325=0321635361=as2=dlang-20=BOLS7NQK6MXCZTMG
I really enjoy Anrei's style of writing but I think this book is 
mostly an good evening read that is -- it is more about the 
history and ideas behind D. Good for high level understanding of 
the language concepts. (Correct me if I am wrong because I 
haven't read it fully yet).


Finally, you have plenty of materials on dlang website:
https://dlang.org/comparison.html
https://dlang.org/articles/index.html



Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn

On Monday, 13 January 2020 at 16:45:46 UTC, mark wrote:

On Monday, 13 January 2020 at 16:37:31 UTC, Ron Tarrant wrote:
Actually, Andrei's book has been updated a few times over the 
years since first being published. The latest version says 
this on the copyright page:


D version: 2.081.1
Book revision: 2018-10-17

So, it's really only about 14 months old.


Is that an ebook edition? The "look inside" of the physical 
book shows "First Printing, May 2010".


(Oh, you can't post-edit like in discourse.)

Anyway, I'll start with Mike's and if I get on with D I'll 
probably get all three.


Re: books for learning D

2020-01-13 Thread Ron Tarrant via Digitalmars-d-learn

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D has 
changed in 10 years.)


Actually, Andrei's book has been updated a few times over the 
years since first being published. The latest version says this 
on the copyright page:


D version: 2.081.1
Book revision: 2018-10-17

So, it's really only about 14 months old.


Re: Invalid memory operation during allocation with `new`

2020-01-13 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/13/20 4:34 AM, Per Nordlöw wrote:

On Sunday, 12 January 2020 at 17:36:23 UTC, Adam D. Ruppe wrote:
Of course that doesn't help the case when you don't know the rule and 
don't even think to call it...


Thanks. I checked and @nogc-qualified all the class destructors defined 
in my project. Without finding any potential problems. Any other 
suggestions on how to trace this problem?


Finding where this is happening is a really difficult problem. Not only 
because there is no stack trace (I believe this is because the invalid 
memory operation error cannot allocate any GC memory, and there are very 
small parts of the stack trace printing code that allocate), but because 
it is invariably happening inside a GC collection -- so the error is far 
away from where you allocated (sometimes the conditions that trigger the 
dtor to allocate are hard to figure out from looking at the object when 
it's destroyed).


I actually had a problem in my vibe.d code where the error didn't 
display until the system was shutting down. Figuring out where it was 
involved defining the extern(C) function onInvalidMemoryOperationError 
(I think if you define this in your code, it overrides the runtime 
library's version), so I could do some diagnostics, and set a breakpoint.


Try starting there and see if you can find why the IMO is happening.

https://github.com/dlang/druntime/blob/c85dea29cb721ec76af6793076aa93e2f62a23da/src/core/exception.d#L535

-Steve


Re: books for learning D

2020-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 13 January 2020 at 11:58:51 UTC, mark wrote:
Both those books are published by Packt who normally have no 
quality control at all as I've discovered to my cost.


I found working with Packt to be difficult on a lot of levels 
too. Like chapter 1 of my book had various symbols mangled 
through the review process... and that made it to print. (I 
realized the problem through the chapter 2 process at least and 
fixed most of it there, but once chapter 1 was submitted there 
was no chance to go back and fix it.)


So like there's stuff like

import foo;;;

with 3 ; actually in there. Ugh. But at least those are easy to 
fix if you already know basic D syntax and doesn't affect the 
explanatory text, which (I think anyway) mostly turned quite good.


I also have downloads of the intended code samples on my website:

http://arsdnet.net/dcode/book/

so you can look there too (and copy/paste more easily!).

also spying the code samples there will give you some idea of 
what the text is about before buying as well.


I recently did an unofficial second edition of the socket sample 
on my blog too so that's a freebie lol 
http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_11.html#sockets-tutorial


Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn
Thanks for all the comments. Look's like I'll be buying Mike's 
"Learning D"!


Re: books for learning D

2020-01-13 Thread René Heldmaier via Digitalmars-d-learn

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D has 
changed in 10 years.)


I found the book amazing. It not only explains the language, but 
also how things work behind the scenes. For a book on programming 
languages it's written in an entertaining style. It's also a joy 
to see how beautiful the design of D is, compared to languages 
like C++ or C#.


But...

The book is definitely not written for beginners. You should at 
least have a good understanding of C (Especially the concept of 
pointers). Even though the chapter on pointers is only 2 pages 
long, the word "pointer" occurs 155 times in the book (I made a 
quick search over my ebook version).


Re: books for learning D

2020-01-13 Thread Mike Parker via Digitalmars-d-learn

On Monday, 13 January 2020 at 11:58:51 UTC, mark wrote:



Both those books are published by Packt who normally have no 
quality control at all as I've discovered to my cost. However


It's hit and miss in my experience. I've picked up some utter 
crap from them, but I've also found some real gems. There's no 
real vetting of the authors they sign, so the writing quality and 
knowledge level vary. Assuming those are up to snuff, much 
depends on feedback from the technical reviewers and the author's 
ability to evaluate the editor's revisions.


Packt's editors follow a rote process where certain words and 
phrases are *always* replaced from a set of alternatives and 
certain phrases are *always* inserted in certain circumstances 
(e.g., to introduce a code snippet) without any regard for the 
surrounding context. Fortunately, they give the author a chance 
to review the edits before publication. In my case, they were 
willing to accept my revision of the revisions (the ones I 
caught, anyway). Sadly, I never had a chance to do the same with 
the two chapters they published online.


I can attest that Adam's and Kai's books are worth the buy. I own 
and have enjoyed both. If either of them were to do a 2nd 
edition, I'd pick it up!





Re: Tour: unneeded import

2020-01-13 Thread drug via Digitalmars-d-learn

On 1/13/20 3:11 PM, drug wrote:

On 1/13/20 2:45 PM, mark wrote:

In the D tour example shown here
https://tour.dlang.org/tour/en/basics/ranges
there is the following import:
import std.range : drop, generate, take;
But generate is not used so I think it ought to be deleted to avoid 
confusion.




done - https://github.com/dlang-tour/english/pull/303


You can easily do it yourself.
https://github.com/dlang-tour/core/tree/master/public/content
Here you select `en`
Then go to `basics/ranges.md`
Switch to master branch using combobox in top left corner
Then press the pen icon next to Raw, Blame, History buttons.
Edit text as needed
In bottom add comment for commit and commit
Then create pull request
Profit!


Re: books for learning D

2020-01-13 Thread Ali Çehreli via Digitalmars-d-learn

On 1/13/20 2:28 AM, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years old, so 
is it still worth getting? (I don't know how much D has changed in 10 
years.)




Yes, Andrei's book is dated but it offers a great perspective on D and 
programming languages in general.


Unfortunately, my book is lagging behind as well. For example, I still 
have to replace post-blit with copy constructors.


I recommend Mike's book as well and Adam's book is a great complement to 
all the tutorials. Kai's book is great too but it is on vibe.d and I 
don't know how much vibe.d has changed since the book was written.


Ali


Re: Tour: unneeded import

2020-01-13 Thread drug via Digitalmars-d-learn

On 1/13/20 2:45 PM, mark wrote:

In the D tour example shown here
https://tour.dlang.org/tour/en/basics/ranges
there is the following import:
import std.range : drop, generate, take;
But generate is not used so I think it ought to be deleted to avoid 
confusion.




done - https://github.com/dlang-tour/english/pull/303


Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn

On Monday, 13 January 2020 at 11:35:51 UTC, bachmeier wrote:

On Monday, 13 January 2020 at 11:20:31 UTC, mark wrote:
On Monday, 13 January 2020 at 11:13:32 UTC, Ferhat Kurtulmuş 
wrote:
On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş 
wrote:

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 
years old, so is it still worth getting? (I don't know how 
much D has changed in 10 years.)


Depending on your background:

https://wiki.dlang.org/First_Language
https://wiki.dlang.org/Coming_From


Even if you are not new to programming this book would be a 
good start:

http://ddili.org/ders/d.en/index.html


Thanks for the links.

I should have said that I find it a *lot* easier learning from 
a print book than online which is why I asked about the 
Alexandrescu book.


Has D changed enough in 10 years to outdate that book? I know 
most other languages have but I'm completely new to D.


I'll also throw out that the books by Andrei, Mike Parker, and 
Adam Ruppe are available on O'Reilly's Safari if you have 
access. You could see which you like best and order that one.


Both those books are published by Packt who normally have no 
quality control at all as I've discovered to my cost. However 
they do seem to have people with good D credentials as 
reviewers/foreword writers, so I guess I'll try Parker's after 
I've tried the "official" one.

Thanks.


Tour: unneeded import

2020-01-13 Thread mark via Digitalmars-d-learn

In the D tour example shown here
https://tour.dlang.org/tour/en/basics/ranges
there is the following import:
import std.range : drop, generate, take;
But generate is not used so I think it ought to be deleted to 
avoid confusion.




Re: books for learning D

2020-01-13 Thread bachmeier via Digitalmars-d-learn

On Monday, 13 January 2020 at 11:20:31 UTC, mark wrote:
On Monday, 13 January 2020 at 11:13:32 UTC, Ferhat Kurtulmuş 
wrote:
On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş 
wrote:

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 
years old, so is it still worth getting? (I don't know how 
much D has changed in 10 years.)


Depending on your background:

https://wiki.dlang.org/First_Language
https://wiki.dlang.org/Coming_From


Even if you are not new to programming this book would be a 
good start:

http://ddili.org/ders/d.en/index.html


Thanks for the links.

I should have said that I find it a *lot* easier learning from 
a print book than online which is why I asked about the 
Alexandrescu book.


Has D changed enough in 10 years to outdate that book? I know 
most other languages have but I'm completely new to D.


I'll also throw out that the books by Andrei, Mike Parker, and 
Adam Ruppe are available on O'Reilly's Safari if you have access. 
You could see which you like best and order that one.


Re: books for learning D

2020-01-13 Thread bachmeier via Digitalmars-d-learn

On Monday, 13 January 2020 at 11:20:31 UTC, mark wrote:
On Monday, 13 January 2020 at 11:13:32 UTC, Ferhat Kurtulmuş 
wrote:
On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş 
wrote:

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 
years old, so is it still worth getting? (I don't know how 
much D has changed in 10 years.)


Depending on your background:

https://wiki.dlang.org/First_Language
https://wiki.dlang.org/Coming_From


Even if you are not new to programming this book would be a 
good start:

http://ddili.org/ders/d.en/index.html


Thanks for the links.

I should have said that I find it a *lot* easier learning from 
a print book than online which is why I asked about the 
Alexandrescu book.


Has D changed enough in 10 years to outdate that book? I know 
most other languages have but I'm completely new to D.


Ali's book
http://ddili.org/ders/d.en/index.html
is D's "official tutorial". You can buy a print copy. If you have 
experience with other languages, Mike Parker's Learning D is also 
an excellent choice. There's nothing wrong with Andrei's book for 
a beginner, but I would personally recommend those two over 
Andrei's for someone new to D.


Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn
On Monday, 13 January 2020 at 11:13:32 UTC, Ferhat Kurtulmuş 
wrote:
On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş 
wrote:

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 
years old, so is it still worth getting? (I don't know how 
much D has changed in 10 years.)


Depending on your background:

https://wiki.dlang.org/First_Language
https://wiki.dlang.org/Coming_From


Even if you are not new to programming this book would be a 
good start:

http://ddili.org/ders/d.en/index.html


Thanks for the links.

I should have said that I find it a *lot* easier learning from a 
print book than online which is why I asked about the 
Alexandrescu book.


Has D changed enough in 10 years to outdate that book? I know 
most other languages have but I'm completely new to D.


Re: books for learning D

2020-01-13 Thread IGotD- via Digitalmars-d-learn

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D has 
changed in 10 years.)


Andrei Alexandrescu's is still a good read for those who wants to 
learn D coming from other languages. What I like about the book 
is that he also could explain the reasoning behind different 
design choices. Some of it might be out of date but not that much 
and it is still useful.


Re: books for learning D

2020-01-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş 
wrote:

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D 
has changed in 10 years.)


Depending on your background:

https://wiki.dlang.org/First_Language
https://wiki.dlang.org/Coming_From


Even if you are not new to programming this book would be a good 
start:

http://ddili.org/ders/d.en/index.html


Re: books for learning D

2020-01-13 Thread Ferhat Kurtulmuş via Digitalmars-d-learn

On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote:

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D has 
changed in 10 years.)


Depending on your background:

https://wiki.dlang.org/First_Language
https://wiki.dlang.org/Coming_From


books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn

I'm just starting out learning D.

Andrei Alexandrescu's "The D Programming Language" is 10 years 
old, so is it still worth getting? (I don't know how much D has 
changed in 10 years.)




Re: Invalid memory operation during allocation with `new`

2020-01-13 Thread Per Nordlöw via Digitalmars-d-learn

On Sunday, 12 January 2020 at 17:36:23 UTC, Adam D. Ruppe wrote:
Of course that doesn't help the case when you don't know the 
rule and don't even think to call it...


Thanks. I checked and @nogc-qualified all the class destructors 
defined in my project. Without finding any potential problems. 
Any other suggestions on how to trace this problem?