Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread aliak via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 03:24:56 UTC, Neia Neutuladh wrote: On Tue, 20 Nov 2018 00:30:44 +, Jordi Gutiérrez Hermoso wrote: On Monday, 19 November 2018 at 21:57:11 UTC, Neia Neutuladh wrote: Programmers coming from nearly any language other than C++ would find it expected and

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread aliak via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 00:30:44 UTC, Jordi Gutiérrez Hermoso wrote: On Monday, 19 November 2018 at 21:57:11 UTC, Neia Neutuladh wrote: [...] What do you think about making the syntax slightly more explicit and warn or possibly error out if you don't do it that way? Either

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 19, 2018 5:30:00 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On 11/19/18 7:21 PM, Jordi Gutiérrez Hermoso wrote: > > On Monday, 19 November 2018 at 21:52:47 UTC, Steven Schveighoffer wrote: > >> A null pointer dereference is an immediate error, and it's also a

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Tue, 20 Nov 2018 00:30:44 +, Jordi Gutiérrez Hermoso wrote: > On Monday, 19 November 2018 at 21:57:11 UTC, Neia Neutuladh wrote: > >> Programmers coming from nearly any language other than C++ would find >> it expected and intuitive that declaring a class instance variable >> leaves it

Re: What is best way to read and interpret binary files?

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 19 Nov 2018 14:32:55 -0800, H. S. Teoh wrote: >> Standard caveats about byte order and alignment. > > Alignment shouldn't be a problem, since local variables should already > be properly aligned. Right, and the IO layer probably doesn't need to read to aligned memory anyway. Struct

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread NoMoreBugs via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 00:30:44 UTC, Jordi Gutiérrez Hermoso wrote: Yeah, maybe this bit of C++ syntax isn't the best idea. What about other alternatives? You could try testing for null before dereferencing ;-) If the following code in D, did what you'd reasonably expect it to do,

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
On Monday, 19 November 2018 at 21:57:11 UTC, Neia Neutuladh wrote: Programmers coming from nearly any language other than C++ would find it expected and intuitive that declaring a class instance variable leaves it null. What do you think about making the syntax slightly more explicit and

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/19/18 7:21 PM, Jordi Gutiérrez Hermoso wrote: On Monday, 19 November 2018 at 21:52:47 UTC, Steven Schveighoffer wrote: A null pointer dereference is an immediate error, and it's also a safe error. It does not cause corruption, and it is free (the MMU is doing it for you). Is this

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
On Monday, 19 November 2018 at 21:52:47 UTC, Steven Schveighoffer wrote: A null pointer dereference is an immediate error, and it's also a safe error. It does not cause corruption, and it is free (the MMU is doing it for you). Is this always true for all arches that D can compile to? I

Re: What is best way to read and interpret binary files?

2018-11-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 19, 2018 at 10:14:25PM +, Neia Neutuladh via Digitalmars-d-learn wrote: > On Mon, 19 Nov 2018 21:30:36 +, welkam wrote: > > So my question is in subject/title. I want to parse binary file into D > > structs and cant really find any good way of doing it. What I try to do > >

Re: What is best way to read and interpret binary files?

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 19 Nov 2018 21:30:36 +, welkam wrote: > So my question is in subject/title. I want to parse binary file into D > structs and cant really find any good way of doing it. What I try to do > now is something like this > > byte[4] fake_integer; > auto fd = File("binary.data", "r"); >

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Neia Neutuladh via Digitalmars-d-learn
On Mon, 19 Nov 2018 21:23:31 +, Jordi Gutiérrez Hermoso wrote: > When I was first playing with D, I managed to create a segfault by doing > `SomeClass c;` and then trying do something with the object I thought I > had default-created, by analogy with C++ syntax. Seasoned D programmers > will

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/19/18 4:23 PM, Jordi Gutiérrez Hermoso wrote: When I was first playing with D, I managed to create a segfault by doing `SomeClass c;` and then trying do something with the object I thought I had default-created, by analogy with C++ syntax. Seasoned D programmers will recognise that I did

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 19 November 2018 at 21:23:31 UTC, Jordi Gutiérrez Hermoso wrote: What's the reasoning for allowing this? The mistake is immediately obvious when you run the program, so I just don't see it as a big deal. You lose a matter of seconds, realize the mistake, and fix it. What is your

What is best way to read and interpret binary files?

2018-11-19 Thread welkam via Digitalmars-d-learn
So my question is in subject/title. I want to parse binary file into D structs and cant really find any good way of doing it. What I try to do now is something like this byte[4] fake_integer; auto fd = File("binary.data", "r"); fd.rawRead(fake_integer); int real_integer = *(cast(int*)

Why does nobody seem to think that `null` is a serious problem in D?

2018-11-19 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
When I was first playing with D, I managed to create a segfault by doing `SomeClass c;` and then trying do something with the object I thought I had default-created, by analogy with C++ syntax. Seasoned D programmers will recognise that I did nothing of the sort and instead created c is null

Re: generate debug file, DUB, LDC etc...

2018-11-19 Thread kinke via Digitalmars-d-learn
On Monday, 19 November 2018 at 10:04:25 UTC, willo wrote: Im trying to get MSVC to debug my binary. I've added... "dflags": ["-g"], at the top level in dub.json to try and get LDC to generate debug info. But doesnt seem to have done anything. I guess you need `-g` for the `lflags` too,

Re: task can't take a class method

2018-11-19 Thread helxi via Digitalmars-d-learn
On Monday, 19 November 2018 at 17:18:14 UTC, John Chapman wrote: 1) task() Thanks, that helped.

Re: task can't take a class method

2018-11-19 Thread John Chapman via Digitalmars-d-learn
On Monday, 19 November 2018 at 16:29:01 UTC, helxi wrote: On Monday, 19 November 2018 at 16:10:15 UTC, helxi wrote: ... Oh wait never mind I was missing a bracket: auto proc = task!(ddCall.dd()); Now I have another thing to worry about: ddcall.dd() cannot be read at compile

Re: task can't take a class method

2018-11-19 Thread helxi via Digitalmars-d-learn
On Monday, 19 November 2018 at 16:10:15 UTC, helxi wrote: ... Oh wait never mind I was missing a bracket: auto proc = task!(ddCall.dd()); Now I have another thing to worry about: ddcall.dd() cannot be read at compile time.

task can't take a class method

2018-11-19 Thread helxi via Digitalmars-d-learn
I want to create a task out of an object's method. My Class is: public class Calldd { private: const string tmpFileName = "/tmp/nixwriter.progress.txt"; string deviceName, sourceFileName; public: this(in string sourceFileName, in string deviceName) { this.sourceFileName

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 19 November 2018 at 14:51:14 UTC, Steven Schveighoffer wrote: Or just use inout. This is literally what inout is for: inout(q32) toQ32 inout { return q32(x); } This should transfer whatever constancy of the original is used for the return value. Yep, I just wanted to

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 19 November 2018 at 14:04:29 UTC, Dennis wrote: On Monday, 19 November 2018 at 13:34:50 UTC, Stanislav Blinov wrote: Because it's not mutation, it's initialization. Oh. That's an epiphany for me. :) When a ctor is `pure`, the compiler knows it doesn't mutate any state other

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/18/18 1:17 PM, Stanislav Blinov wrote: On Sunday, 18 November 2018 at 17:30:18 UTC, Dennis wrote: I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2;  // compiles! despite `a` being const. Ouch. That's

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 13:34:50 UTC, Stanislav Blinov wrote: Because it's not mutation, it's initialization. Oh. That's an epiphany for me. When a ctor is `pure`, the compiler knows it doesn't mutate any state other than the object's, so it allows conversion to all three

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 19 November 2018 at 12:28:43 UTC, Dennis wrote: On Monday, 19 November 2018 at 02:39:32 UTC, Stanislav Blinov wrote: You're skimming the examples ;) I'm not saying your examples don't work, I'm trying to understand the minimum requirements. You said: "That's [constructors

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 02:39:32 UTC, Stanislav Blinov wrote: You're skimming the examples ;) I'm not saying your examples don't work, I'm trying to understand the minimum requirements. You said: "That's [constructors needing to be pure is] only for types with indirections

generate debug file, DUB, LDC etc...

2018-11-19 Thread willo via Digitalmars-d-learn
Im trying to get MSVC to debug my binary. I've added... "dflags": ["-g"], at the top level in dub.json to try and get LDC to generate debug info. But doesnt seem to have done anything.