Re: For those ready to take the challenge
On Friday, 9 January 2015 at 17:18:43 UTC, Adam D. Ruppe wrote: Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls! Yeah... Surprising, since languages like python includes a HTML parser in the standard library. Besides, if you want all resource links you have to do a lot better, since the following attributes can contain resource addresses: href, src, data, cite, xlink:href… You also need to do entity expansion since the links can contain html entities like amp;. Depressing.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 15:13:27 UTC, Adam D. Ruppe wrote: On Saturday, 10 January 2015 at 12:34:42 UTC, Tobias Pankrath wrote: Since it is a comparison of languages it's okay to match the original behaviour. I don't think this is really a great comparison of languages either though because it is gluing together a couple library tasks. Only a few bits about the actual language are showing through. In the given regex solutions, C++ has an advantage over C wherein the regex structure can be freed automatically in a destructor and a raw string literal in here, but that's about all from the language itself. The original one is kinda long because he didn't use a http get library, not because the language couldn't do one. There are bits where the language can make those libraries nicer too: dom.d uses operator overloading and opDispatch to support things like .attribute and also .attr.X and .style.foo and element[selector].addClass(foo) and so on implemented in very very little code - I didn't have to manually list methods for the collection or properties for the attributes - ...but a library *could* do it that way and get similar results for the end user; the given posts wouldn't show that. I agree and one of the answers says: I think the no third-party assumption is a fallacy. And is a specific fallacy that afflicts C++ developers, since it's so hard to make reusable code in C++. When you are developing anything at all, even if it's a small script, you will always make use of whatever pieces of reusable code are available to you. The thing is, in languages like Perl, Python, Ruby (to name a few), reusing someone else's code is not only easy, but it is how most people actually write code most of the time. I think he's wrong, because it spoils the comparison. Every answer should delegate those tasks to a library that Stroustroup used as well, e.g. regex matching, string to number conversion and some kind of TCP sockets. But it must do the same work that he's solution does: Create and parse HTML header and extract the html links, probably using regex, but I wouldn't mind another solution. Everyone can put a libdo_the_stroustroup_thing on dub and then call do_the_stroustroup_thing() in main. To compare what the standard libraries (and libraries easily obtained or quasi standard) offer is another challenge.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 15:52:21 UTC, Tobias Pankrath wrote: ... The thing is, in languages like Perl, Python, Ruby (to name a few), reusing someone else's code is not only easy, but it is how most people actually write code most of the time. I think he's wrong, because it spoils the comparison. Every answer should delegate those tasks to a library that Stroustroup used as well, e.g. regex matching, string to number conversion and some kind of TCP sockets. But it must do the same work that he's solution does: Create and parse HTML header and extract the html links, probably using regex, but I wouldn't mind another solution. Everyone can put a libdo_the_stroustroup_thing on dub and then call do_the_stroustroup_thing() in main. To compare what the standard libraries (and libraries easily obtained or quasi standard) offer is another challenge. I disagree. The great thing about comes with batteries runtimes is that I have the guarantee the desired features exist in all platforms supported by the language. If the libraries are dumped into a repository, there is always a problem if the library works across all OS supported by the language or even if they work together at all. Specially if they depend on common packages with incompatible versions. This is the cause of so many string and vector types across all C++ libraries as most of those libraries were developed before C++98 was even done. Or why C runtime isn't nothing more than a light version of UNIX as it was back in 1989, without any worthwhile feature since then, besides some extra support for numeric types and a little more secure libraries. Nowadays, unless I am doing something very OS specific, I hardly care which OS I am using, thanks to such comes with batteries runtimes. -- Paulo
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 15:52:21 UTC, Tobias Pankrath wrote: I think he's wrong, because it spoils the comparison. Every answer should delegate those tasks to a library that Stroustroup used as well, e.g. regex matching, string to number conversion and some kind of TCP sockets. But it must do the same work that he's solution does: Create and parse HTML header and extract the html links, probably using regex, but I wouldn't mind another solution. The challenge is completely pointless. Different languages have different ways of hacking together a compact incorrect solution. How to directly translate a C++ hack into another language is a task for people who are drunk. For the challenge to make sense it would entail parsing all legal HTML5 documents, extracting all resource links, converting them into absolute form and printing them one per line. With no hickups.
Re: For those ready to take the challenge
On Friday, 9 January 2015 at 17:15:43 UTC, Adam D. Ruppe wrote: import arsd.dom; import std.net.curl; import std.stdio, std.algorithm; void main() { auto document = new Document(cast(string) get(http://www.stroustrup.com/C++.html;)); writeln(document.querySelectorAll(a[href]).map!(a=a.href)); } Or perhaps better yet: import arsd.dom; import std.net.curl; import std.stdio; void main() { auto document = new Document(cast(string) get(http://www.stroustrup.com/C++.html;)); foreach(a; document.querySelectorAll(a[href])) writeln(a.href); } Which puts each one on a separate line. Both these code examples triggers the same assert() dmd: expression.c:3761: size_t StringExp::length(int): Assertion `encSize == 1 || encSize == 2 || encSize == 4' failed. on dmd git master. Ideas anyone?
Re: core.atomic: atomicFence, atomicLoad, atomicStore
On Saturday, 10 January 2015 at 12:16:24 UTC, ref2401 wrote: I learned how 'atomicOp' and 'cas' work and why i need them from the following sources: http://ddili.org/ders/d.en/concurrency_shared.html (Ali's book) http://www.informit.com/articles/article.aspx?p=1609144 (Andrei's book) Can anybody tell me how 'atomicFence', 'atomicLoad' and 'atomicStore' work and what do i need them for? Unfortunately official documentation didn't make it clear for me. I seem to be posting this a few times a week now: http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-1-of-2 and http://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-2-of-2 Although we don't have std::atomic in D, the same principles apply to using core.atomic.atomicLoad and friends.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 17:23:31 UTC, Ola Fosheim Grøstad wrote: For the challenge to make sense it would entail parsing all legal HTML5 documents, extracting all resource links, converting them into absolute form and printing them one per line. With no hickups. Though, that's still a library thing rather than a language thing. dom.d and the Url struct in cgi.d should be able to do all that, in just a few lines even, but that's just because I've done a *lot* of web scraping with the libs before so I made them work for that. In fact let me to do it. I'll use my http2.d instead of cgi.d, actually, it has a similar Url struct just more focused on client requests. import arsd.dom; import arsd.http2; import std.stdio; void main() { auto base = Uri(http://www.stroustrup.com/C++.html;); // http2 is a newish module of mine that aims to imitate // a browser in some ways (without depending on curl btw) auto client = new HttpClient(); auto request = client.navigateTo(base); auto document = new Document(); // and http2 provides an asynchonous api but you can // pretend it is sync by just calling waitForCompletion auto response = request.waitForCompletion(); // parseGarbage uses a few tricks to fixup invalid/broken HTML // tag soup and auto-detect character encodings, including when // it lies about being UTF-8 but is actually Windows-1252 document.parseGarbage(response.contentText); // Uri.basedOn returns a new absolute URI based on something else foreach(a; document.querySelectorAll(a[href])) writeln(Uri(a.href).basedOn(base)); } Snippet of the printouts: [...] http://www.computerhistory.org http://www.softwarepreservation.org/projects/c_plus_plus/ http://www.morganstanley.com/ http://www.cs.columbia.edu/ http://www.cse.tamu.edu http://www.stroustrup.com/index.html http://www.stroustrup.com/C++.html http://www.stroustrup.com/bs_faq.html http://www.stroustrup.com/bs_faq2.html http://www.stroustrup.com/C++11FAQ.html http://www.stroustrup.com/papers.html [...] The latter are relative links that it based on and the first few are absolute. Seems to have worked. There's other kinds of links than just a[href], but fetching them is as simple as adding them to the selector or looping for them too separately: foreach(a; document.querySelectorAll(script[src])) writeln(Uri(a.src).basedOn(base)); none on that page, no links either, but it is easy enough to do with the lib. Looking at the source of that page, I find some invalid HTML and lies about the character set. How did Document.parseGarbage do? Pretty well, outputting the parsed DOM tree shows it auto-corrected the problems I see by eye.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 15:52:21 UTC, Tobias Pankrath wrote: But it must do the same work that he's solution does: Create and parse HTML header and extract the html links, probably using regex, but I wouldn't mind another solution. Yeah, that would be best. BTW interesting line here: s GET http://; + server + / + file HTTP/1.0\r\n; s Host: server \r\n; Why + instead of ? C++'s usage of is totally blargh to me anyway, but seeing both is even stranger. Weird language, weird library. Everyone can put a libdo_the_stroustroup_thing on dub and then call do_the_stroustroup_thing() in main. To compare what the standard libraries (and libraries easily obtained or quasi standard) offer is another challenge. Yeah.
Re: For those ready to take the challenge
Adam D. Ruppe: Don't use git master :P Is the issue in Bugzilla? Bye, bearophile
Re: For those ready to take the challenge
Vladimir Panteleev via Digitalmars-d-learn píše v So 10. 01. 2015 v 07:42 +: On Saturday, 10 January 2015 at 02:10:04 UTC, Jesse Phillips wrote: On Friday, 9 January 2015 at 13:50:29 UTC, eles wrote: https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro Link to answer in D: http://codegolf.stackexchange.com/a/44417/13362 I think byLine is not necessary. By default . will not match line breaks. One statement solution: import std.net.curl, std.stdio; import std.algorithm, std.regex; void main() { get(http://www.stroustrup.com/C++.html;) .matchAll(`a.*?href=(.*)`) .map!(m = m[1]) .each!writeln(); } Requires Phobos PR#2024 ;) Oh here is it, I was looking for each. I think it is allready in a phobos but I can not find. Now I know why :D
core.atomic: atomicFence, atomicLoad, atomicStore
I learned how 'atomicOp' and 'cas' work and why i need them from the following sources: http://ddili.org/ders/d.en/concurrency_shared.html (Ali's book) http://www.informit.com/articles/article.aspx?p=1609144 (Andrei's book) Can anybody tell me how 'atomicFence', 'atomicLoad' and 'atomicStore' work and what do i need them for? Unfortunately official documentation didn't make it clear for me.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 12:34:42 UTC, Tobias Pankrath wrote: Since it is a comparison of languages it's okay to match the original behaviour. I don't think this is really a great comparison of languages either though because it is gluing together a couple library tasks. Only a few bits about the actual language are showing through. In the given regex solutions, C++ has an advantage over C wherein the regex structure can be freed automatically in a destructor and a raw string literal in here, but that's about all from the language itself. The original one is kinda long because he didn't use a http get library, not because the language couldn't do one. There are bits where the language can make those libraries nicer too: dom.d uses operator overloading and opDispatch to support things like .attribute and also .attr.X and .style.foo and element[selector].addClass(foo) and so on implemented in very very little code - I didn't have to manually list methods for the collection or properties for the attributes - ...but a library *could* do it that way and get similar results for the end user; the given posts wouldn't show that.
Traits and functions
Is there a way to get all functions within a module using traits? I tried allMembers and it seem to work, but I can't use getFunctionAttributes with it and if I use getAttributes then it won't find any applied attributes. What I do is having a package module with a staic constructor which loops through allMembers and then I want to find functions with a specific attribute. All the members are imported using public imports. However it can find the specific functions, but it does not find the attributes.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 13:22:57 UTC, Nordlöw wrote: on dmd git master. Ideas anyone? Don't use git master :P Definitely another regression. That line was just pushed to git like two weeks ago and the failing assertion is pretty obviously a pure dmd code bug, it doesn't know the length of char apparently.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 15:24:45 UTC, bearophile wrote: Is the issue in Bugzilla? https://issues.dlang.org/show_bug.cgi?id=13966
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 15:24:45 UTC, bearophile wrote: Is the issue in Bugzilla? I don't know, bugzilla is extremely difficult to search. I guess I'll post it again and worst case it will be closed as a duplicate.
Re: For those ready to take the challenge
On Friday, 9 January 2015 at 17:18:43 UTC, Adam D. Ruppe wrote: Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls! Since it is a comparison of languages it's okay to match the original behaviour.
Re: For those ready to take the challenge
On Friday, 9 January 2015 at 13:50:29 UTC, eles wrote: https://codegolf.stackexchange.com/questions/44278/debunking-stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro From the link: Let's show Stroustrup what small and readable program actually is. Alright, there are a lot a examples in many languagens, but those examples doesn't should handle exceptions like the original code does? Matheus.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 19:17:22 UTC, Ola Fosheim Grøstad wrote: Nice and clean code; does it expand html entities (amp)? Of course. It does it both ways: spana amp;/span span.innerText == a span.innerText = a \ b; assert(span.innerHTML == a quot; b); parseGarbage also tries to fix broken entities, so like standing alone it will translate to amp; for you. there's also parseStrict which just throws an exception in cases like that. That's one thing a lot of XML parsers don't do in the name of speed, but I do since it is pretty rare that I don't want them translated. One thing I did for a speedup though was scan the string for and if it doesn't find one, return a slice of the original, and if it does, return a new string with the entity translated. Gave a surprisingly big speed boost without costing anything in convenience. The HTML5 standard has improved on HTML4 by now being explicit on how incorrect documents shall be interpreted in section 8.2. That ought to be sufficient, since that is what web browsers are supposed to do. http://www.w3.org/TR/html5/syntax.html#html-parser Huh, I never read that, my thing just did what looked right to me over hundreds of test pages that were broken in various strange and bizarre ways.
Re: idiomatic D: what to use instead of pointers in constructing a tree data structure?
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 as you wish, but it can be helpful to meet the standard style conventions in order to make it as easy as possible for everyone else to understand. Thanks for the reminder. I use D Style when I am writing properly, but haven't yet internalized it for a quick example and old habits die hard.
Re: Wrapping a C library with its own GC + classes vs refcounted structs
Hi Aldanor. I wrote a slightly longer reply, but mislaid the file somewhere. I guess your question might relate to wrapping the HDF5 library - something that I have already done in a basic way, although I welcome your project, as no doubt we will get to a higher quality eventual solution that way. One question about accurately representing the HDF5 object hierarchy. Are you sure you wish to do this rather than present a flattened approach oriented to what makes sense to make things easy for the user in the way that is done by h5py and pytables? In terms of the actual garbage generated by this library - there are lots of small objects. The little ones are things like a file access attribute, or a schema for a dataset. But really the total size taken up by the small ones is unlikely to amount to much for scientific computing or for quant finance if you have a small number of users and are not building some kind of public web server. I think it should be satisfactory for the little objects just to wrap the C functions with a D wrapper and rely on the object destructor calling the C function to free memory. On the rare occasions when not, it will be pretty obvious to the user and he can always call destroy directly. For the big ones, maybe reference counting brings enough value to be useful - I don't know. But mostly you are either passing data to HDF5 to write, or you are receiving data from it. In the former case you pass it a pointer to the data, and I don't think it keeps it around. In the latter, you know how big the buffer needs to be, and you can just allocate something from the heap of the right size (and if using reflection, type) and use destroy on it when done. So I don't have enough experience yet with either D or HDF5 to be confident in my view, but my inclination is to think that one doesn't need to worry about reference counting. Since objects are small and there are not that many of them, relying on the destructor to be run (manually if need be) seems likely to be fine, as I understand it. I may well be wrong on this, and would like to understand the reasons if so. Laeeth.
Re: endsWith - for a string vs an array of strings
Laeeth Isharc: I understand from previous discussion there is some difficulty over immutability. I did not quite figure out what the solution was in this case: import std.array; import std.string; import std.stdio; void main(string[] args) { string[] test=[1,two,three!]; auto a=arghtwo.endsWith(test); writefln(%s,a); } This does not compile... Take a look at your error messages: std.algorithm.endsWith(alias pred = a == b, Range, Needles...)(Range doesThisEnd, Needles withOneOfThese) Needles is not an array type, it's a type tuple, so withOneOfThese doesn't accept an array of strings. This is correct: auto a = arghtwo.endsWith(1,two,three!); In D there is a feature that allows a function to accept both an array of items and items, but it's not used here by endsWith, for reasons I don't understand (other people can answer this). So if you really want to pack the strings in some kind of unity, you can do this as workaround: void main() { import std.stdio, std.array, std.string, std.typetuple; alias test = TypeTuple!(1, two, three!); auto b = arghtwo.endsWith(test[]); b.writeln; } Bye, bearophile
Re: endsWith - for a string vs an array of strings
On 2015-01-10 at 21:58, bearophile wrote: Needles is not an array type, it's a type tuple, so withOneOfThese doesn't accept an array of strings. [...] So if you really want to pack the strings in some kind of unity, you can do this as workaround: [...] I would suggest create a function that does the same thing as endsWith(Range, Needles...) but instead of Needles expanded as a list of arguments it takes in a range of them. In fact I was surprised that there was no such function in std.algorithm present. Therefore I have written endsWithAny for this purpose a moment ago. Is it any good? Please correct if necessary. import std.array; import std.string; import std.stdio; import std.range; uint endsWithAny(alias pred = a == b, Range, Needles)(Range haystack, Needles needles) if (isBidirectionalRange!Range isInputRange!Needles is(typeof(.endsWith!pred(haystack, needles.front)) : bool)) { foreach (i, e; needles) if (endsWith!pred(haystack, e)) return i + 1; return 0; } void main(string[] args) { string[] test = [1, two, three!]; auto a = arghtwo.endsWithAny(test); writefln(%s, a); } unittest { string[] hs = [no-one, thee, there were three, two]; string[] tab = [one, two, three]; assert(endsWithAny(hs[0], tab) == 1); assert(endsWithAny(hs[1], tab) == 0); assert(endsWithAny(hs[2], tab) == 3); assert(endsWithAny(hs[3], tab) == 2); }
endsWith - for a string vs an array of strings
I understand from previous discussion there is some difficulty over immutability. I did not quite figure out what the solution was in this case: import std.array; import std.string; import std.stdio; void main(string[] args) { string[] test=[1,two,three!]; auto a=arghtwo.endsWith(test); writefln(%s,a); } This does not compile... test.d(7): Error: template std.algorithm.endsWith cannot deduce function from argument types !()(string, string[]), candidates are: /usr/include/dmd/phobos/std/algorithm.d(6143): std.algorithm.endsWith(alias pred = a == b, Range, Needles...)(Range doesThisEnd, Needles withOneOfThese) if (isBidirectionalRange!Range Needles.length 1 is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : bool) is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[1..__dollar])) : uint)) /usr/include/dmd/phobos/std/algorithm.d(6210): std.algorithm.endsWith(alias pred = a == b, R1, R2)(R1 doesThisEnd, R2 withThis) if (isBidirectionalRange!R1 isBidirectionalRange!R2 is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : bool)) /usr/include/dmd/phobos/std/algorithm.d(6237): std.algorithm.endsWith(alias pred = a == b, R, E)(R doesThisEnd, E withThis) if (isBidirectionalRange!R is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool)) Thanks. Laeeth.
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 14:56:09 UTC, Adam D. Ruppe wrote: On Saturday, 10 January 2015 at 13:22:57 UTC, Nordlöw wrote: on dmd git master. Ideas anyone? Don't use git master :P Do use git master. The more people do, the fewer regressions will slip into the final release. You can use Dustmite to reduce the code to a simple example, and Digger to find the exact pull request which introduced the regression. (Yes, shameless plug, preaching to the choir, etc.)
Re: For those ready to take the challenge
On Saturday, 10 January 2015 at 17:39:17 UTC, Adam D. Ruppe wrote: Though, that's still a library thing rather than a language thing. It is a language-library-platform thing, things like how composable the eco system is would be interesting to compare. But it would be unfair to require a minimalistic language to not use third party libraries. One should probably require that the library used is generic (not a spider-framework), not using FFI, mature and maintained? document.parseGarbage(response.contentText); // Uri.basedOn returns a new absolute URI based on something else foreach(a; document.querySelectorAll(a[href])) writeln(Uri(a.href).basedOn(base)); } Nice and clean code; does it expand html entities (amp)? The HTML5 standard has improved on HTML4 by now being explicit on how incorrect documents shall be interpreted in section 8.2. That ought to be sufficient, since that is what web browsers are supposed to do. http://www.w3.org/TR/html5/syntax.html#html-parser
Re: Traits and functions
On 01/10/2015 08:21 AM, Bauss wrote: Is there a way to get all functions within a module using traits? I tried allMembers and it seem to work, but I can't use getFunctionAttributes with it and if I use getAttributes then it won't find any applied attributes. What I do is having a package module with a staic constructor which loops through allMembers and then I want to find functions with a specific attribute. All the members are imported using public imports. However it can find the specific functions, but it does not find the attributes. The following program prints both the function attributes and user defined attributes e.g. of foo(): module deneme; import std.string; import std.traits; struct MyAttr {} @MyAttr void foo(int i, double d) pure @nogc nothrow @property {} void main() { foreach (m; __traits(allMembers, deneme)) { pragma(msg, format(module member: %s, m)); static if (mixin (isCallable! ~ m)) { pragma(msg, format(%s is callable, m)); foreach (funcAttr; mixin (format(__traits(getFunctionAttributes, %s), m))) { pragma(msg, format( function attribute: %s, funcAttr)); } foreach (attr; mixin (format(__traits(getAttributes, %s), m))) { static if (is (attr == MyAttr)) { pragma(msg, format( uda: %s, attr.stringof)); } } } } } Ali
Re: endsWith - for a string vs an array of strings
Laeeth Isharc: In D there is a feature that allows a function to accept both an array of items and items, yes - it is funny there is not an overloading that accepts arrays I meant this D feature: void foo(T)(T[] items...) { import std.stdio; items.writeln; } void main() { foo(red, green, blue); foo([red, green, blue]); auto a = [red, green, blue]; foo(a); } Bye, bearophile
Re: Wrapping a C library with its own GC + classes vs refcounted structs
On Saturday, 10 January 2015 at 20:55:05 UTC, Laeeth Isharc wrote: Hi Aldanor. I wrote a slightly longer reply, but mislaid the file somewhere. I guess your question might relate to wrapping the HDF5 library - something that I have already done in a basic way, although I welcome your project, as no doubt we will get to a higher quality eventual solution that way. One question about accurately representing the HDF5 object hierarchy. Are you sure you wish to do this rather than present a flattened approach oriented to what makes sense to make things easy for the user in the way that is done by h5py and pytables? In terms of the actual garbage generated by this library - there are lots of small objects. The little ones are things like a file access attribute, or a schema for a dataset. But really the total size taken up by the small ones is unlikely to amount to much for scientific computing or for quant finance if you have a small number of users and are not building some kind of public web server. I think it should be satisfactory for the little objects just to wrap the C functions with a D wrapper and rely on the object destructor calling the C function to free memory. On the rare occasions when not, it will be pretty obvious to the user and he can always call destroy directly. For the big ones, maybe reference counting brings enough value to be useful - I don't know. But mostly you are either passing data to HDF5 to write, or you are receiving data from it. In the former case you pass it a pointer to the data, and I don't think it keeps it around. In the latter, you know how big the buffer needs to be, and you can just allocate something from the heap of the right size (and if using reflection, type) and use destroy on it when done. So I don't have enough experience yet with either D or HDF5 to be confident in my view, but my inclination is to think that one doesn't need to worry about reference counting. Since objects are small and there are not that many of them, relying on the destructor to be run (manually if need be) seems likely to be fine, as I understand it. I may well be wrong on this, and would like to understand the reasons if so. Laeeth. Thanks for the reply. Yes, this concerns my HDF5 wrapper project; the main concern is not that the memory consumption of course, but rather explicitly controlling lifetimes of the objects (especially objects like files -- so you are can be sure there are no zombie handles floating around). Most of the time when you're doing some operations on an HDF5 file you want all handles to get closed by the time you're done (i.e. by the time you leave the scope) which feels natural (e.g. close groups, links etc). Some operations in HDF5, particularly those related to linking/unlinking/closing may behave different if an object has any chilld objects with open handles. In addition to that, the C HDF5 library retains the right to reuse both the memory and id once the refcount drops to zero so it's best to be precise about that and keep a registry of weak references to all C ids that D knows about (sort of the same way as h5py does in Python).
Re: Traits and functions
On Saturday, 10 January 2015 at 23:23:52 UTC, Ali Çehreli wrote: On 01/10/2015 08:21 AM, Bauss wrote: Is there a way to get all functions within a module using traits? I tried allMembers and it seem to work, but I can't use getFunctionAttributes with it and if I use getAttributes then it won't find any applied attributes. What I do is having a package module with a staic constructor which loops through allMembers and then I want to find functions with a specific attribute. All the members are imported using public imports. However it can find the specific functions, but it does not find the attributes. The following program prints both the function attributes and user defined attributes e.g. of foo(): module deneme; import std.string; import std.traits; struct MyAttr {} @MyAttr void foo(int i, double d) pure @nogc nothrow @property {} void main() { foreach (m; __traits(allMembers, deneme)) { pragma(msg, format(module member: %s, m)); static if (mixin (isCallable! ~ m)) { pragma(msg, format(%s is callable, m)); foreach (funcAttr; mixin (format(__traits(getFunctionAttributes, %s), m))) { pragma(msg, format( function attribute: %s, funcAttr)); } foreach (attr; mixin (format(__traits(getAttributes, %s), m))) { static if (is (attr == MyAttr)) { pragma(msg, format( uda: %s, attr.stringof)); } } } } } Ali Thank you this was exactly what I was looking for!