Source code:
https://alexvincent.us/d-language/samples/intervalmap-rev1.d.txt

After reading Ali Çehreli's book, "Programming in D", I wrote this little sample up as a starting point for my explorations into D. I've long admired the D language, but I've never actually tried to write practical code in D.

So I wrote this little sample up in dlangide, and as I was going, I realized I had quite a few questions.

(1) It's not clear how to specify certain parts of a module or library as non-exportable. Is that possible? Is it desirable? (It's not that important, yet, but still...)

(2) In the unittest code, I have a block that I want to rewrite using assertThrown, but I can't figure out from either the book or the website the correct usage. What's the right way to specify a StringException with a particular message I expect to receive?

(3) How do I actually create a library in dub? How does dub determine what files to build?

(4) How should the scope(exit) and scope(failure) guard statements intermix with preconditions and postconditions?

(5) My append() function has a postcondition that currently depends on debug-only members of the class being set in the precondition. This seems artificial - not the part about setting these variables in the precondition, but having the variables defined on the class to begin with. If they were defined only for the lifetime of the function's execution, starting in the precondition, this would be more natural. Is there a Right Way to define function-only debug variables for use in postconditions? If not, would this be a valid use-case to consider amending the language specification to clarify?

(6) Would someone please review my sample code and offer feedback? :-)

(7) Naming: This code is the start of a port of a mini-library I wrote in JavaScript which I called "ObjectRange". However, in Phobos, the term "Range" has a very different meaning - in fact, almost the opposite meaning of what this code does. I asked for a better name in the D IRC channel, and someone suggested Interval, based on the mathematical definition of the word. IntervalMap seemed more accurate, since there is a payload to each interval. Does the name make sense in the context?

(8) Is there a similar, more mature library out there which tries to achieve what I'm doing here? I'm rather surprised I didn't see anything like it in the standard library...

Reply via email to