Re: Need way to compare classes, and primitive types in bst Template
On 06/09/2017 05:32 AM, Mark wrote: https://dpaste.dzfl.pl/ff58876ce213 [...] What Id like to do is this: auto tree = new BSTbase!int; ... tree.insert(7); and auto Tree2 = new BSTbase!Aclass; ... Tree2.insert(Aclassobject); What I have is: Tree.insert(7, cast(real) 7); and Tree2.insert(Aclassobject, cast(real) (cast(void*) Aclassobject)); I tried a few things, but I can't get them to work. Can anyone give a way for me to avoid doing it this clumsy way? Get rid of `real val;` and just compare `payload`s. For classes, you can detect them with `static if (is(T == class))` or some such, and cast to void* when comparing. But when you cast to void*, you're ignoring an opEquals or opCmp the class might have. That might be surprising. So maybe just require that classes implement opCmp. Or try to detect when a class doesn't have opCmp and only cast then.
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On Friday, 9 June 2017 at 05:07:37 UTC, Ali Çehreli wrote: On 06/08/2017 01:39 AM, Walter Bright wrote: https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/ Can someone verify and make corrections to my response to LordJebbs please: https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/dinumey/ Thank you, Ali Indeed, there is no special thread. I'd say for the more relaxed reddit audience it can be put like this: the GC isn't "running" at all. Not persistently, not at all times, not in any special thread. It is not actively scanning anything. Any allocation on GC heap made by *any* thread *may* cause a collection, which is performed there and then in the same thread that triggered said allocation, and is observed as part of that allocation. All registered threads except the one that triggered the allocation (and thus, collection) are paused for scanning and resumed afterwards. Threads not registered with the runtime or those that were explicitly detached from the runtime are expected to not hold any pointers to the GC heap, and are neither paused nor scanned.
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On 06/08/2017 01:39 AM, Walter Bright wrote: https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/ Can someone verify and make corrections to my response to LordJebbs please: https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/dinumey/ Thank you, Ali
[Issue 17484] New: high penalty for vbroadcastsd with -mcpu=avx
https://issues.dlang.org/show_bug.cgi?id=17484 Issue ID: 17484 Summary: high penalty for vbroadcastsd with -mcpu=avx Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P3 Component: dmd Assignee: nob...@puremagic.com Reporter: c...@dawg.eu With -mcpu=avx, the compiler emits vbroadcastsd ymm2, qword ptr [rsp] even when initializing only 128-bit wide double2 variables. This causes a high 50-80 cycle penalty when later some legacy SSE instruction is used with such a register value (or a derived value), because the CPU does not know that the upper bits are zero, and apparently preserves them in an internal register buffer. https://software.intel.com/en-us/articles/intel-avx-state-transitions-migrating-sse-code-to-avx We should A not write to 256-bit wide YMM registers when only 128-bit wide XMM registers are used, and B avoid mixing legacy encoded SSE instructions (movsd) with vex encoded AVX-128 instructions, i.e. use vmovsd instead of movsd. --
Re: D for Web Development?
On Thursday, 8 June 2017 at 08:36:38 UTC, Nicholas Wilson wrote: Yes. Adam D. Ruppe also has some easy to use libraries that may suit your need. Indeed, my cgi.d, database.d, and postgres.d would give a foundation. https://github.com/adamdruppe/arsd you download the individual files and compile them into your program. Depending on how you want to set up, you can change the backend with `-version=embedded_httpd` or `-version=fastcgi` or `-version=scgi`. I recommend using a production grade web server in front of any application server, whether it is mine or vibe or node or whatever, then use a cgi mode to talk to the app or reverse proxy to an embedded http server. anyway, if you are interested let me know and I'll write a simple demo. vibe is more popular but with it's async lib requirement it isn't as compatible. With mine you can use C libraries with ease regardless of i/o model.
Need way to compare classes, and primitive types in bst Template
Ok. So I have a BST template, and it passes my tests. However, if you look at how I insert the data into the BST, you'll quickly notice the problem I have. https://dpaste.dzfl.pl/ff58876ce213 Keep in mind I just pasted that stack in there because I use it in my last unittest at the bottom. It has its own file. the method that I use is called insert, on line 79. What Id like to do is this: auto tree = new BSTbase!int; ... tree.insert(7); and auto Tree2 = new BSTbase!Aclass; ... Tree2.insert(Aclassobject); What I have is: Tree.insert(7, cast(real) 7); and Tree2.insert(Aclassobject, cast(real) (cast(void*) Aclassobject)); I tried a few things, but I can't get them to work. Can anyone give a way for me to avoid doing it this clumsy way? The only otpion I can think of is just using inheritance, one for Complex Data types, and the other for primitives. But that defeats the purpose of having be a template (a little bit). Thanks.
[Issue 17478] Socket.select return a write status change, but no connection is established.
https://issues.dlang.org/show_bug.cgi?id=17478 springchanged: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |WONTFIX --- Comment #2 from spring --- thanks for your reply. i misunderstand the c's api select. Either established or error occurred , a write status will change. i'm afraid the d document [https://dlang.org/library/std/socket/socket.select.html] has a little mistake. for a connecting socket , a writet status change . may establelished or error occurred. --
[Issue 17483] New: std.numeric.gcd cannot inline function
https://issues.dlang.org/show_bug.cgi?id=17483 Issue ID: 17483 Summary: std.numeric.gcd cannot inline function Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: stanislav.bli...@gmail.com Not only can it not be inlined, due to this function's implementation it turns into two function calls when called with const/immutable arguments. --- import std.traits : isIntegral, Unqual; pragma(inline, true) // pasted from std.numeric T gcd(T)(T a, T b) if (isIntegral!T) { static if (is(T == const) || is(T == immutable)) { return gcd!(Unqual!T)(a, b); } else version(DigitalMars) { static if (T.min < 0) { assert(a >= 0 && b >= 0); } while (b) { immutable t = b; b = a % b; a = t; } return a; } else { if (a == 0) return b; if (b == 0) return a; import core.bitop : bsf; import std.algorithm.mutation : swap; immutable uint shift = bsf(a | b); a >>= a.bsf; do { b >>= b.bsf; if (a > b) swap(a, b); b -= a; } while (b); return a << shift; } } void foo() { size_t a, b; gcd(a, b); } --- --
Re: CTFE Status 2
On Thursday, 16 February 2017 at 21:05:51 UTC, Stefan Koch wrote: [ ... ] Hi there, I just pulled another all nighter. I found a bug in the code that was supposed to adjust the values of || and &&. As will as a mixup in the error messages for overlapping slice-assignment. Both are fixed. I am aware that overlapping slice assignment check is not yet good enough. This is on my short-term todo list. But in the even shorter-term, there are a couple hours sleep waiting to be claimed. Night guys, Stefan
Re: Compile-Time Sort in D
On Friday, 9 June 2017 at 01:34:14 UTC, Mike Parker wrote: On Thursday, 8 June 2017 at 19:07:50 UTC, cym13 wrote: Seeing that the one and only D example in the nim article is a broken one (using static instead of enum or static immutable for 'b') we should have started with a correct example before showing the broken one... Good to know for next time. static variables are initialized with compile-time values. They don't need be immutable for that. they need immutable if you want to use them again at compile-time. Therefore it is a good habit to get into.
Re: Compile-Time Sort in D
On Thursday, 8 June 2017 at 19:07:50 UTC, cym13 wrote: Seeing that the one and only D example in the nim article is a broken one (using static instead of enum or static immutable for 'b') we should have started with a correct example before showing the broken one... Good to know for next time. static variables are initialized with compile-time values. They don't need be immutable for that.
[Issue 17482] New: [REG 2.074] comile error: Comparing Nullable!Variant with basic type
https://issues.dlang.org/show_bug.cgi?id=17482 Issue ID: 17482 Summary: [REG 2.074] comile error: Comparing Nullable!Variant with basic type Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: regression Priority: P1 Component: phobos Assignee: nob...@puremagic.com Reporter: bus_dbugzi...@semitwist.com Worked fine up through 2.073.2, but 2.074.0 gives a compiler error: import std.variant, std.typecons; void main() { Nullable!Variant a; a == 11; // Yes, comparison intended } test_nullable_variant.d(6): Error: template std.typecons.Nullable!(VariantN!32LU).Nullable.opEquals cannot deduce function from argument types !()(int), candidates are: /home/nick/.dvm/compilers/dmd-2.074.0/linux/bin/../../src/phobos/std/typecons.d(2212): std.typecons.Nullable!(VariantN!32LU).Nullable.opEquals()(auto ref const(typeof(this)) rhs) /home/nick/.dvm/compilers/dmd-2.074.0/linux/bin/../../src/phobos/std/typecons.d(): std.typecons.Nullable!(VariantN!32LU).Nullable.opEquals()(auto ref const(T) rhs) --
mysql-native v1.1.0 - small bugfix update
mysql-native is a native D client driver for MySQL/MariaDB. It works with or without Vibe.d. Small bugfix update: - Fixed: #99: Update dub.sdl to allow vibe-d 0.8.* releases. - Fixed: #111: NEWDECIMAL type returns the wrong value. Since this type is intended as arbitrary precision, the server itself sends it as a string. In order to avoid unexpected loss of precision, mysql-native does not attempt to convert the string to a floating-point type. If conversion to floating point is required, users can simply pass the string to Phobos's to!real.
Vittorio Romeo comments on his D impressions at C++Now 2017
Vittorio is a new friend who I met at C++Now 2017. He is also the author of a DIP on "Value closures": https://github.com/SuperV1234/DIPs/blob/master/DIPs/DIP.md I'm happy that he talks favorably of D during the following chat (you should continue watching him till the end until he gives the microphone away (not when he first attempts to give it away)): https://youtu.be/QsYuEsZVy3I?t=994 Some more here: https://youtu.be/QsYuEsZVy3I?t=2209 Some of the other participants talk about appreciating the "other language" keynotes as well. Ali
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On 6/8/17 5:03 PM, Wulfklaue wrote: On Thursday, 8 June 2017 at 20:38:33 UTC, Ali Çehreli wrote: That link doesn't work for me. Besides, I've heard that it's better not to click through a link as HN either rates it lower or flags it as spam. Not sure though, I'm just contributing to cargo cult... :) Ali Removed the old one and add new one with the full youtube link: https://news.ycombinator.com/item?id=14517183 Posting direct HN links in any forum is a sure way to have the entry classified as spam (HN uses an algorithm that flags as spam many accesses that do not have their own site as referrer). -- Andrei
Re: DList efficiency
On Thursday, 8 June 2017 at 22:42:14 UTC, Boris-Barboris wrote: 1). Do I understand correctly, that there is currently no way (aside from editing the sources of course) to efficiently (using one underlying iteration) remove all\first element(s) from DList based on a predicate? Oh, sorry, I guess I didn't search thoroughly enough: https://github.com/dlang/phobos/blob/master/std/container/dlist.d#L769
DList efficiency
Good day to you reader! I have a couple questions about Phobos: 1). Do I understand correctly, that there is currently no way (aside from editing the sources of course) to efficiently (using one underlying iteration) remove all\first element(s) from DList based on a predicate? Can such operation be performed for arrays using std.algorithm (though in array case it can at least be done manually)? 2). Was the idea of range types, that allow underlying structure modification ever considered ("remove element from the collection being iterated and shift to next element" is first candidate). 3). Is there a container library featuring alternative concepts, namely, iterators?
Re: SCons and D
On Thursday, 8 June 2017 at 14:27:53 UTC, Russel Winder wrote: It seems I am on a bit of a roll getting changesets relating to D support for SCons into an appropriate state so that they get merged into the mainline SCons repository. So maybe now is a time to get any "pet peeves" with D support in SCons fixed. When I create a shared library I get an error message. SharedLibrary('lib2', ['lib2.d']) leads to dmd -oflib2.so -shared -defaultlib=libphobos2.so -L-soname=lib2.so lib2.os Error: unrecognized file extension os Apparently using the .os extension works for C but not with dmd.
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On 06/08/2017 02:03 PM, Wulfklaue wrote: Removed the old one and add new one with the full youtube link: That worked. Thanks. I recommend others not to click on the link but search for "competitive advantage with d" on the main page instead: https://news.ycombinator.com/news Ali
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On Thursday, 8 June 2017 at 20:38:33 UTC, Ali Çehreli wrote: That link doesn't work for me. Besides, I've heard that it's better not to click through a link as HN either rates it lower or flags it as spam. Not sure though, I'm just contributing to cargo cult... :) Ali Removed the old one and add new one with the full youtube link: https://news.ycombinator.com/item?id=14517183
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On Thursday, 8 June 2017 at 20:38:33 UTC, Ali Çehreli wrote: On 06/08/2017 01:29 PM, Wulfklaue wrote: That link doesn't work for me. Besides, I've heard that it's better not to click through a link as HN either rates it lower or flags it as spam. Not sure though, I'm just contributing to cargo cult... :) Ali Strange because its the same link that was used in the reddit topic. Its just Belgium Youtube link ( owned by Google in the whois, so fairly sure its official :) ).
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On 06/08/2017 01:29 PM, Wulfklaue wrote: On Thursday, 8 June 2017 at 08:39:58 UTC, Walter Bright wrote: https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/ Added to Hacker News ... https://news.ycombinator.com/item?id=14516927 That link doesn't work for me. Besides, I've heard that it's better not to click through a link as HN either rates it lower or flags it as spam. Not sure though, I'm just contributing to cargo cult... :) Ali
Re: Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
On Thursday, 8 June 2017 at 08:39:58 UTC, Walter Bright wrote: https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/ Added to Hacker News ... https://news.ycombinator.com/item?id=14516927
Re: SCons, Python 3, and D
On Thursday, 8 June 2017 at 09:42:50 UTC, Russel Winder wrote: In case anyone has missed recent news, SCons seems now to work without any problems using Python 3 Nice. I am using Python 3 to run all my SCons D builds. Me too :)
Re: Compile-Time Sort in D
On 06/08/2017 09:07 PM, cym13 wrote: Seeing that the one and only D example in the nim article is a broken one (using static instead of enum or static immutable for 'b') we should have started with a correct example before showing the broken one... Good to know for next time. Broken? It works just fine.
Re: Compile-Time Sort in D
On Wednesday, 7 June 2017 at 21:47:58 UTC, John Carter wrote: On Monday, 5 June 2017 at 14:23:34 UTC, Mike Parker wrote: https://dlang.org/blog/2017/06/05/compile-time-sort-in-d/ Seems like you have inspired people... http://blog.zdsmith.com/posts/compiletime-sort-in-nim.html Seeing that the one and only D example in the nim article is a broken one (using static instead of enum or static immutable for 'b') we should have started with a correct example before showing the broken one... Good to know for next time.
Re: Mutiple AliasSeq as input to template
On Wednesday, 7 June 2017 at 19:03:39 UTC, David Sanders wrote: You can use nested templates to process multiple AliasSeqs like so: [snip] Interesting approach also.
Re: Concept proposal: Safely catching error
I want to start by stating that the discussion around being able to throw Error from nothrow functions and the compiler optimizations that follow is important to the thoughts below. The other aspect of array bounds checking is that those particular checks will not be added in -release. There has been much discussion around this already and I do recall that the solution was that @safe code will retain the array bounds checks (I'm not sure if contracts was included in this). Thus if using -release and @safe you'd be able to rely on having an Error to catch. Now it might make sense for @safe code to throw an ArrayOutOfBounds Exception, but that would mean the function couldn't be marked as nothrow if array indexing is used. This is probably a terrible idea, but @safe nothrow functions could throw ArrayIndexError while @safe could throw ArrayIndexException. It would really suck that adding nothrow would change the semantics silently.
[Issue 17399] core.checkedint.addu cannot inline function
https://issues.dlang.org/show_bug.cgi?id=17399 github-bugzi...@puremagic.com changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --
[Issue 17399] core.checkedint.addu cannot inline function
https://issues.dlang.org/show_bug.cgi?id=17399 --- Comment #6 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/8ff0a0a185e0a7d0c04812cf916fbbe6615f792c fix Issue 17399 - core.checkedint.addu cannot inline function https://github.com/dlang/dmd/commit/c18a27f5a11912695f0b7a74177bde149427496b Merge pull request #6815 from WalterBright/fix17399 fix Issue 17399 - core.checkedint.addu cannot inline function merged-on-behalf-of: unknown --
Re: .sort vs sort(): std.algorithm not up to the task?
On 08.06.2017 14:06, Steven Schveighoffer wrote: The issue here is that arrays are special. Arrays allow foreach(i, v; arr) and foreach(v; arr). Ranges in general do not. So there is no way to forward this capability via the range interface. Not only that, but foreach(i, v; arr) is much different than iterating even a range that returns a tuple in that the index is *specific to the loop* and doesn't involve the array at all. It's more similar to opApply. opApply can help, but still is different than how arrays work (foreach with array is handled directly by the compiler). But ranges are not going to be forwarding this feature just for arrays. Arguably, foreach over ranges and foreach over arrays are badly designed. Automatic tuple expansion only works with ranges, and indexed iteration only works with arrays, and they are mutually incompatible. Therefore, there is no good way to fix the problem.
Re: DMD [-O flag] vs. [memory allocation in a synchronized class]
On Thursday, 8 June 2017 at 15:35:06 UTC, Ivan Kazmenko wrote: Perhaps a regression should be filed, or searched for, at issues.dlang.org. I can do it, but not right now, and would be glad if someone beats me to it. Reported: https://issues.dlang.org/show_bug.cgi?id=17481
[Issue 17481] New: [REG 2.069.0] synchronized: Access Violation with dmd -O on win32
https://issues.dlang.org/show_bug.cgi?id=17481 Issue ID: 17481 Summary: [REG 2.069.0] synchronized: Access Violation with dmd -O on win32 Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: regression Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: ga...@mail.ru Code: - class Obj{ synchronized void trigger(){ new ubyte[1]; } } void main(){ auto k = new shared Obj; k.trigger; } - When compiled on win32 with just "dmd", it runs fine. When compiled with "dmd -O -g", it gives the following error at runtime: - object.Error@(0): Access Violation 0x0065 0x00402C6B in _d_newarrayU 0x004023EF in _d_newarrayT 0x00402A7F in scope void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x00402980 in _d_run_main 0x00402288 in main at C:\programs\stuff\dlang\synchronized-memory-bug\a.d(8) 0x76D5336A in BaseThreadInitThunk 0x77369902 in RtlInitializeExceptionChain 0x773698D5 in RtlInitializeExceptionChain - Win64 is OK. Win32 with dmd 2.068.2 or earlier is OK. Win32 with dmd 2.069.0 or later gives the error above. Original thread at D.learn: https://forum.dlang.org/post/wdebefxpjvvxyqiol...@forum.dlang.org --
Re: Concept proposal: Safely catching error
On 6/8/17 11:19 AM, Stanislav Blinov wrote: On Thursday, 8 June 2017 at 14:13:53 UTC, Steven Schveighoffer wrote: void foo(Mutex m, Data d) pure { synchronized(m) { // ... manipulate d } // no guarantee m gets unlocked } Isn't synchronized(m) not nothrow? You're right, it isn't. I actually didn't know that. Also forgot to make my function nothrow. Fixed: void foo(Mutex m, Data d) pure nothrow { try { synchronized(m) { // .. manipulate d } } catch(Exception) { } } -Steve
Re: vibe.d on Web Framework Benchmarks
On 06/08/2017 05:09 AM, Dominikus Dittes Scherkl wrote: > Wow. Answer was actually visible before the OP. THAT is what I would > call fast. Did you use vibe.d? Your answer hasn't arrived yet. Using something other than vibe.d? :p Ali
Re: DMD [-O flag] vs. [memory allocation in a synchronized class]
On Thursday, 8 June 2017 at 11:41:40 UTC, realhet wrote: I've managed to narrow the problem even more: //win32 dmd -O class Obj{ synchronized void trigger(){ new ubyte[1]; } } void main(){ auto k = new shared Obj; k.trigger; } This time I got a more sophisticated error message: object.Error@(0): Access Violation 0x7272456D in SymInitialize 0x00402667 0x00402A97 0x00402998 0x004022A0 0x76F13744 in BaseThreadInitThunk 0x773B9E54 in RtlSetCurrentTransaction 0x773B9E1F in RtlSetCurrentTransaction I can reproduce this under win32, and it breaks somewhere between 2.068.2 and 2.069.0. The move instructive message with "dmd -O -g": object.Error@(0): Access Violation 0x0065 0x00402C33 in _d_newarrayU 0x004022EB in _d_newarrayT 0x00402A7F in scope void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x00402980 in _d_run_main 0x00402288 in main at C:\a.d(8) 0x757F336A in BaseThreadInitThunk 0x77409902 in RtlInitializeExceptionChain 0x774098D5 in RtlInitializeExceptionChain Perhaps a regression should be filed, or searched for, at issues.dlang.org. I can do it, but not right now, and would be glad if someone beats me to it. Ivan Kazmenko.
Re: Concept proposal: Safely catching error
On Thursday, 8 June 2017 at 14:13:53 UTC, Steven Schveighoffer wrote: void foo(Mutex m, Data d) pure { synchronized(m) { // ... manipulate d } // no guarantee m gets unlocked } -Steve Isn't synchronized(m) not nothrow?
Re: SCons and D
On Thu, 2017-06-08 at 14:37 +, bachmeier via Digitalmars-d wrote: > On Thursday, 8 June 2017 at 14:27:53 UTC, Russel Winder wrote: > > It seems I am on a bit of a roll getting changesets relating to > > D support for SCons into an appropriate state so that they get > > merged into the mainline SCons repository. So maybe now is a > > time to get any "pet peeves" with D support in SCons fixed. > > > > For myself, I am currently working on a new tool "dub" to > > handle getting dependencies from the Dub repository. It works > > for unit_testing in my D projects, but I need to write some > > proper SCons tests before submitting a pull request to the > > SCons mainline. > > > > Anyone wanting to try the dub tool now will need to use dub.py > > from my SCons_D_Experiments Git repository on BitBucket or > > GitHub. > > > > (The dmd, ldc, and gdc tools in that repository are just > > mirrors of what is in the mainline Mercurial repository on > > BitBucket, unless some experiments rather than bug fixes are > > needed.) > > I'd like to give this a try, but do you have a link to your > repository? Sorry I failed to add the actual links: SCons_D_Experiment on BitBucket: https://bitbucket.org/russel/scons_d_experiment SCons_D_Experiment on GitHub: https://github.com/russel/SCons_D_Experiment My SCons clone on BitBucket: https://bitbucket.org/russel/scons SCons mainline on BitBucket: https://bitbucket.org/scons/scons -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: sqlite3 vs. sqlite-d
On Thu, 2017-06-08 at 14:55 +, Dejan Lekic via Digitalmars-d wrote: > On Thursday, 8 June 2017 at 13:37:41 UTC, Russel Winder wrote: > > > Exactly my point. Using SQLAlchemy made me actually enjoy > > writing database code. Which I did last year having avoided it > > Using ORM like SQLAlchemy certainly has benefits but like any > other ORM, it generates hideous SQL code, sometimes terribly > slow... SQLAlchemy is not just an ORM, though there is an ORM, there is also the expression language which is an internal DSL for writing SQL. Also the authors of SQLAlchemy do optimise the generated SQL. Though obviously if you are needing the optimal dark corner optimisation of Oracle 11.2.0.4 say, then you are on your own. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Concept proposal: Safely catching error
On 06/08/2017 04:02 PM, Olivier FAURE wrote: That's true. A "pure after cleanup" function is incompatible with catching Errors (unless we introduce a "scope(error)" keyword that also runs on errors, but that comes with other problems). Is pureMalloc supposed to be representative of pure functions, or more of a special case? That's not a rhetorical question, I genuinely don't know. I think it's supposed to be just as pure as any other pure function. Here's the pull request that added it: https://github.com/dlang/druntime/pull/1746 I don't see anything about it being special-cased in the compiler or such. The spec says a pure function "does not read or write any global or static mutable state", which seems incompatible with "save a global, then write it back like it was". True. Something similar is going on with @safe. There's a list of things that are "not allowed in safe functions" [1], but you can do all those things in @trusted code, of course. The list is about what the compiler rejects, not about what a @safe function can actually do. It might be the same with the things that pure functions can/cannot do. I suppose the idea is that it cannot be observed that pureMalloc messes with global state, so it's ok. The assumption being that you don't catch errors. By the way, with regards to purity and errors, `new` is the same as pureMalloc. When `new` throws an OutOfMemoryError and you catch it, you can see that errno has been set. Yet `new` is considered `pure`. In fact, doing so seems contrary to the assumption that you can run any two pure functions on immutable / independent data at the same time and you won't have race conditions. Actually, now I'm wondering whether pureMalloc & co handle potential race conditions at all, or just hope they don't happen. Apparently errno is thread-local. [1] https://dlang.org/spec/function.html#safe-functions
Re: sqlite3 vs. sqlite-d
On Thursday, 8 June 2017 at 13:37:41 UTC, Russel Winder wrote: Exactly my point. Using SQLAlchemy made me actually enjoy writing database code. Which I did last year having avoided it Using ORM like SQLAlchemy certainly has benefits but like any other ORM, it generates hideous SQL code, sometimes terribly slow...
Re: sqlite3 vs. sqlite-d
On Thursday, 8 June 2017 at 13:06:55 UTC, Ozan (O/N/S) wrote: Your sqlite-d solution would be complete if writing sqlite files are also possible. Ignore the SQL parsing stuff, it does not fit in a world of fast data processing. Writing or rather modifying sqlite-dbs is a bit harder then reading them. Since the B-Tree should not get to imbalanced. I started on write support a while back, but at that time I did not understand the structure well enough to guarantee efficient write-support. (which would also require you to keep the index updated and so on ...) As for parsing sql. Unfortunately the column information is stored in form of a create table statement which forces me to parse at-least that much sql. In order to provide a nice interface in which you don't have to look up the position of your columns manually.
Re: SCons and D
On Thursday, 8 June 2017 at 14:27:53 UTC, Russel Winder wrote: It seems I am on a bit of a roll getting changesets relating to D support for SCons into an appropriate state so that they get merged into the mainline SCons repository. So maybe now is a time to get any "pet peeves" with D support in SCons fixed. For myself, I am currently working on a new tool "dub" to handle getting dependencies from the Dub repository. It works for unit_testing in my D projects, but I need to write some proper SCons tests before submitting a pull request to the SCons mainline. Anyone wanting to try the dub tool now will need to use dub.py from my SCons_D_Experiments Git repository on BitBucket or GitHub. (The dmd, ldc, and gdc tools in that repository are just mirrors of what is in the mainline Mercurial repository on BitBucket, unless some experiments rather than bug fixes are needed.) I'd like to give this a try, but do you have a link to your repository?
SCons and D
It seems I am on a bit of a roll getting changesets relating to D support for SCons into an appropriate state so that they get merged into the mainline SCons repository. So maybe now is a time to get any "pet peeves" with D support in SCons fixed. For myself, I am currently working on a new tool "dub" to handle getting dependencies from the Dub repository. It works for unit_testing in my D projects, but I need to write some proper SCons tests before submitting a pull request to the SCons mainline. Anyone wanting to try the dub tool now will need to use dub.py from my SCons_D_Experiments Git repository on BitBucket or GitHub. (The dmd, ldc, and gdc tools in that repository are just mirrors of what is in the mainline Mercurial repository on BitBucket, unless some experiments rather than bug fixes are needed.) -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Concept proposal: Safely catching error
On 6/8/17 9:42 AM, Olivier FAURE wrote: On Thursday, 8 June 2017 at 12:20:19 UTC, Steven Schveighoffer wrote: Hm... if you locked an object that was passed in on the stack, for instance, there is no guarantee the object gets unlocked. This wouldn't be allowed unless the object was duplicated / created inside the try block. void foo(Mutex m, Data d) pure { synchronized(m) { // ... manipulate d } // no guarantee m gets unlocked } -Steve
[Issue 17480] [Downloads]
https://issues.dlang.org/show_bug.cgi?id=17480 --- Comment #2 from Martin Tschierschke--- Hmm, I tried curl -fsS https://dlang.org/install.sh | bash -s dmd But it seamed that no dub was included. So I used sudo dpkg -i dmd_2.074.1-0_amd64.deb after downloading it with wget http://downloads.dlang.org/releases/2.x/2.074.1/dmd_2.074.1-0_amd64.deb Everything fine. But nevertheless it would be useful to put the info, that the packet manager is included on the page, too. Regards mt. Thanks for your effort! --
Re: Concept proposal: Safely catching error
On Thursday, 8 June 2017 at 13:02:38 UTC, ag0aep6g wrote: Catching the resulting error is @safe when you throw the int* away. So if f is `pure` and you make sure that the arguments don't survive the `try` block, you're good, because f supposedly cannot have reached anything else. This is your proposal, right? Right. I don't think that's sound. At least, it clashes with another relatively recent development: https://dlang.org/phobos/core_memory.html#.pureMalloc That's a wrapper around C's malloc. C's malloc might set the global errno, so it's impure. pureMalloc achieves purity by resetting errno to the value it had before the call. So a `pure` function may mess with global state, as long as it cleans it up. But when it's interrupted (e.g. by an out-of-bounds error), it may leave globals in an invalid state. So you can't assume that a `pure` function upholds its purity when it throws an error. That's true. A "pure after cleanup" function is incompatible with catching Errors (unless we introduce a "scope(error)" keyword that also runs on errors, but that comes with other problems). Is pureMalloc supposed to be representative of pure functions, or more of a special case? That's not a rhetorical question, I genuinely don't know. The spec says a pure function "does not read or write any global or static mutable state", which seems incompatible with "save a global, then write it back like it was". In fact, doing so seems contrary to the assumption that you can run any two pure functions on immutable / independent data at the same time and you won't have race conditions. Actually, now I'm wondering whether pureMalloc & co handle potential race conditions at all, or just hope they don't happen.
Re: Concept proposal: Safely catching error
On Thursday, 8 June 2017 at 12:20:19 UTC, Steven Schveighoffer wrote: Hm... if you locked an object that was passed in on the stack, for instance, there is no guarantee the object gets unlocked. This wouldn't be allowed unless the object was duplicated / created inside the try block. Aside from the point that this still doesn't solve the problem (pure functions do cleanup too), this means a lot of headache for people who just want to write code. I'd much rather just write an array type and be done. -Steve Fair enough. There are other advantages to writing with "create data with pure functions then process it" idioms (easier to do unit tests, better for parallelism, etc), though.
Re: sqlite3 vs. sqlite-d
On Thu, 2017-06-08 at 11:36 +, Stefan Koch via Digitalmars-d wrote: > […] > The Alternative is not doing SQL at all. > But building the queries inside your code. Exactly my point. Using SQLAlchemy made me actually enjoy writing database code. Which I did last year having avoided it since I was born. > Which is what sqlite-d allows you to do. > and which is the reason I wrote it. > > I wanted to express my desires in code rather then having to log > sql-blocks around. Exactly. sqlpp11 made me think about doing database stuff for Me TV in C++ (currently there is a home grown ORM in the previous versions), but that I thought maybe there is something in D sqlite-d is not mentioned on https://wiki.dlang.org/Libraries_and_Frame works -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: sqlite3 vs. sqlite-d
On Wednesday, 7 June 2017 at 19:16:07 UTC, Stefan Koch wrote: On Wednesday, 7 June 2017 at 19:10:26 UTC, Ozan wrote: On Wednesday, 7 June 2017 at 17:51:30 UTC, Stefan Koch wrote: Hi guys I made a small video. Mature and heavily optimized C library vs. young D upstart. See for yourself how it turns out. https://www.youtube.com/watch?v=mOeVftcVsvI Cheers, Stefan Great. I like it (not the color of the terminal font - green!!! ;-) What is the cause for different benchmark results (from 30us up to 48us)? With your small number lines, do you implement the complete sqlite functionality? Regards, Ozan It's the Matrix-Movie green ;) I only implement reading the file format. And a few convenience functions for finding a table, iterating by rows, and extracting columns. The cause for the different results it like the scheduling of the OS. Since we do issue quite a large read before iterating. most of our time-slice has been used. which makes it possible for us to get swapped out during processing. I see, Matrix style. Red or blue pill, that's the question. ;-) Your sqlite-d solution would be complete if writing sqlite files are also possible. Ignore the SQL parsing stuff, it does not fit in a world of fast data processing. Regards Ozan
[Issue 17480] [Downloads]
https://issues.dlang.org/show_bug.cgi?id=17480 greenifychanged: What|Removed |Added CC||greeen...@gmail.com --- Comment #1 from greenify --- DUB is part of the release bundles since 2.072 However, the installer will install DUB even for earlier versions. What version are you testing? --
Re: Concept proposal: Safely catching error
On 06/08/2017 11:27 AM, Olivier FAURE wrote: Contracts are made to preempt memory corruption, and to protect against *programming* errors; they're not recoverable because breaking a contract means that from now on the program is in a state that wasn't anticipated by the programmer. Which means the only way to handle them gracefully is to cancel what you were doing and go back to the pre-contract-breaking state, then produce a big, detailed error message and then exit / remove the thread / etc. I might get the idea now. The throwing code could be in the middle of some unsafe operation when it throws the out-of-bounds error. It would have cleaned up after itself, but it can't because of the (unexpected) error. Silly example: void f(ref int* p) @trusted { p = cast(int*) 13; /* corrupt stuff or partially initialize or whatever */ int[] a; auto x = a[0]; /* trigger an out-of-bounds error */ p = new int; /* would have cleaned up */ } Catching the resulting error is @safe when you throw the int* away. So if f is `pure` and you make sure that the arguments don't survive the `try` block, you're good, because f supposedly cannot have reached anything else. This is your proposal, right? I don't think that's sound. At least, it clashes with another relatively recent development: https://dlang.org/phobos/core_memory.html#.pureMalloc That's a wrapper around C's malloc. C's malloc might set the global errno, so it's impure. pureMalloc achieves purity by resetting errno to the value it had before the call. So a `pure` function may mess with global state, as long as it cleans it up. But when it's interrupted (e.g. by an out-of-bounds error), it may leave globals in an invalid state. So you can't assume that a `pure` function upholds its purity when it throws an error. In the end, an error indicates that something is wrong, and probably all guarantees may be compromised.
[Issue 17480] New: [Downloads]
https://issues.dlang.org/show_bug.cgi?id=17480 Issue ID: 17480 Summary: [Downloads] Product: D Version: D2 Hardware: All URL: http://dlang.org/ OS: All Status: NEW Severity: enhancement Priority: P3 Component: dlang.org Assignee: nob...@puremagic.com Reporter: m...@smartdolphin.de Just realized: Please consider to add that DUB is part of the .deb package but not of the install script! --
[Issue 16615] std.process is missing functionality for child processes
https://issues.dlang.org/show_bug.cgi?id=16615 Vladimir Panteleevchanged: What|Removed |Added See Also||https://issues.dlang.org/sh ||ow_bug.cgi?id=17479 --
[Issue 17479] Public constructor for std.process.Pid
https://issues.dlang.org/show_bug.cgi?id=17479 Vladimir Panteleevchanged: What|Removed |Added See Also||https://issues.dlang.org/sh ||ow_bug.cgi?id=16615 --
Re: D for Web Development?
On 2017-06-08 09:32, Michael Reiland wrote: A few questions: - Is vibe.d the recommended way of doing web work? Yes. - Is that book worth purchasing? Yes. - Does D have a good library for accessing Postgres? I see several listed but I don't know what the most stable would be for production: https://wiki.dlang.org/Libraries_and_Frameworks#Databases I recommend ddb [1], it's compatible with vibe.d. - Why is D a better solution than Go or .Net Core? D is a very flexible and powerful language that doesn't force you to program in a particular style. In my opinion Go is that that good a creating abstractions. [1] http://code.dlang.org/packages/ddb -- /Jacob Carlborg
[Issue 17479] Public constructor for std.process.Pid
https://issues.dlang.org/show_bug.cgi?id=17479 Vladimir Panteleevchanged: What|Removed |Added Keywords||pull --- Comment #2 from Vladimir Panteleev --- I see you created a PR: https://github.com/dlang/phobos/pull/5450 --
[Issue 17479] Public constructor for std.process.Pid
https://issues.dlang.org/show_bug.cgi?id=17479 Vladimir Panteleevchanged: What|Removed |Added CC||thecybersha...@gmail.com --- Comment #1 from Vladimir Panteleev --- (In reply to Chris Wright from comment #0) > I want to handle them in the same fashion. Why? Waiting on a process that is not your child is not possible, so in that way, this would allow constructing an invalid Pid. Is it just for .kill()? --
Re: Concept proposal: Safely catching error
On 6/7/17 12:20 PM, Olivier FAURE wrote: On Monday, 5 June 2017 at 14:05:27 UTC, Steven Schveighoffer wrote: I don't think this will work. Only throwing Error makes a function nothrow. A nothrow function may not properly clean up the stack while unwinding. Not because the stack unwinding code skips over it, but because the compiler knows nothing can throw, and so doesn't include the cleanup code. If the function is @pure, then the only things it can set up will be stored on local or GC data, and it won't matter if they're not properly cleaned up, since they won't be accessible anymore. Hm... if you locked an object that was passed in on the stack, for instance, there is no guarantee the object gets unlocked. I'm not 100% sure about that, though. Can a pure function do impure things in its scope(exit) / destructor code? Even if it does pure things, that can cause problems. Not to mention that only doing this for pure code eliminates usages that sparked the original discussion, as my code communicates with a database, and that wouldn't be allowed in pure code. It would work for sending to a database; but you would need to use the functional programming idiom of "do 99% of the work in pure functions, then send the data to the remaining 1% for impure tasks". Even this still pushes the handling of the error onto the user. I want vibe.d to handle the error, in case I create a bug. But vibe.d can't possibly know what database things I'm going to do. And really this isn't possible. 99% of the work is using the database. A process's structure would be: - Read the inputs from the socket (impure, no catching errors) - Parse them and transform them into database requests (pure) - Send the requests to the database (impure) - Parse / analyse / whatever the results (pure) - Send the results to the socket (impure) And okay, yeah, that list isn't realistic. Using functional programming idioms in real life programs can be a pain in the ass, and lead to convoluted callback-based scaffolding and weird data structures that you need to pass around a bunch of functions that don't really need them. The point is, you could isolate the pure data-manipulating parts of the program from the impure IO parts; and encapsulate the former in Error-catching blocks (which is convenient, since those parts are likely to be more convoluted and harder to foolproof than the IO parts, therefore likely to throw more Errors). Aside from the point that this still doesn't solve the problem (pure functions do cleanup too), this means a lot of headache for people who just want to write code. I'd much rather just write an array type and be done. -Steve
[Issue 17478] Socket.select return a write status change, but no connection is established.
https://issues.dlang.org/show_bug.cgi?id=17478 Vladimir Panteleevchanged: What|Removed |Added CC||thecybersha...@gmail.com --- Comment #1 from Vladimir Panteleev --- std.socket is just a simple translation layer to C APIs. Does the same program written in C behave differently? --
Re: vibe.d on Web Framework Benchmarks
On Wednesday, 7 June 2017 at 21:18:21 UTC, ketmar wrote: Ozan wrote: On Wednesday, 7 June 2017 at 09:44:55 UTC, Ali Çehreli wrote: Is there an issue with the tests? Surprised that vibe.d is not higher in the rating... https://www.techempower.com/benchmarks/#section=data-r14=ph=fortune Same for me. I used a lot of Java (Jetty, Tomcat) and Groovy (Grails) stuff before using D (vibe.d). On my machine I got a factor of 10-50 in difference. Vibe.d was always much faster. So where are the results coming from? most of it came from microbenchmarking. "how fast can we parse json and query db?" wow, what a great benchmark! surely, we don't need to do any data processing, let's measure raw speed of parsing data, and then throwing it away! Wow. Answer was actually visible before the OP. THAT is what I would call fast. Did you use vibe.d?
Re: .sort vs sort(): std.algorithm not up to the task?
On 6/7/17 9:57 PM, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa; // what others have referred to as // standard sort works but is deprecated //auto keys = aa.keys.sort; // Error: cannot infer argument types, expected 1 argument, not 2 import std.algorithm: sort; auto keys = aa.keys.sort(); // this works but why should I have to? //import std.array: array; //auto keys = aa.keys.sort().array; foreach (i, v; keys){} } If I hand you a chihuahua for grooming, why am I getting back a pit bull? I simply want a groomed chihuahua. Why do I need to consult a wizard to get back a groomed chihuahua? The issue here is that arrays are special. Arrays allow foreach(i, v; arr) and foreach(v; arr). Ranges in general do not. So there is no way to forward this capability via the range interface. Not only that, but foreach(i, v; arr) is much different than iterating even a range that returns a tuple in that the index is *specific to the loop* and doesn't involve the array at all. It's more similar to opApply. opApply can help, but still is different than how arrays work (foreach with array is handled directly by the compiler). But ranges are not going to be forwarding this feature just for arrays. In answer to your question, if we returned something that *didn't* take advantage of the fact that the range is now sorted, then people who want that functionality (e.g. builtin binary search) would be complaining. As a recommendation, I suggest you get used to using enumerate, as it will work for all cases of ranges, including arrays. -Steve
Re: DMD [-O flag] vs. [memory allocation in a synchronized class]
I've managed to narrow the problem even more: //win32 dmd -O class Obj{ synchronized void trigger(){ new ubyte[1]; } } void main(){ auto k = new shared Obj; k.trigger; } This time I got a more sophisticated error message: object.Error@(0): Access Violation 0x7272456D in SymInitialize 0x00402667 0x00402A97 0x00402998 0x004022A0 0x76F13744 in BaseThreadInitThunk 0x773B9E54 in RtlSetCurrentTransaction 0x773B9E1F in RtlSetCurrentTransaction
Re: sqlite3 vs. sqlite-d
On Thursday, 8 June 2017 at 08:44:56 UTC, Russel Winder wrote: But what is D's equivalent to Python's SQLAlchemy? C++ now has sqlpp11. Anyone doing SQL code manipulation with strings in another language is doing it wrong. Internal DSLs FTW. The Alternative is not doing SQL at all. But building the queries inside your code. Which is what sqlite-d allows you to do. and which is the reason I wrote it. I wanted to express my desires in code rather then having to log sql-blocks around.
Re: DMD [-O flag] vs. [memory allocation in a synchronized class]
realhet wrote: On Thursday, 8 June 2017 at 10:48:41 UTC, ketmar wrote: worksforme with -O, and with -O -inline. I forgot to mention, that I'm generating win32 output. DMD32 D Compiler v2.074.0 mine: GNU/Linux, 32 bit, dmd git HEAD.
[Issue 16615] std.process is missing functionality for child processes
https://issues.dlang.org/show_bug.cgi?id=16615 --- Comment #1 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/71ca4c5b1428e6b4a9b2d89586cd8851c48619a6 Partial Fix For Issue 16615 - convert os pid to std.process Pid https://github.com/dlang/phobos/commit/15a5a4898c67d0ecb7c7d2a5d9e744eeaf188ca1 Merge pull request #5086 from edi33416/process_enhancement Partial Fix Issue 16615 - convert os pid to std.process Pid merged-on-behalf-of: Andrei Alexandrescu--
[Issue 16615] std.process is missing functionality for child processes
https://issues.dlang.org/show_bug.cgi?id=16615 github-bugzi...@puremagic.com changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --
Re: DMD [-O flag] vs. [memory allocation in a synchronized class]
On Thursday, 8 June 2017 at 10:48:41 UTC, ketmar wrote: worksforme with -O, and with -O -inline. I forgot to mention, that I'm generating win32 output. DMD32 D Compiler v2.074.0
Re: DMD [-O flag] vs. [memory allocation in a synchronized class]
worksforme with -O, and with -O -inline.
DMD [-O flag] vs. [memory allocation in a synchronized class]
Hi, This code works well with the unoptimized compilation with DMD. import std.array; synchronized class Obj{ private int[] arr; void trigger(){ arr.length += 1; } } void main(){ auto k = new shared Obj; k.trigger; } And when I use the -O option, it shows the following error in the trigger() method: core.exception.InvalidMemoryOperationError@src\core\exception.d(696): Invalid memory operation Why? o.O
SCons, Python 3, and D
In case anyone has missed recent news, SCons seems now to work without any problems using Python 3 (the one true Python – until Python 4, obviously). I am using Python 3 to run all my SCons D builds. Obviously this relates to using a checkout of the mainline Mercurial repository and using default branch. I am hoping that Bill will move to creating a new release soon. This will then appear on Arch and Fedora Rawhide fairly quickly I suspect. Debian will be ages yet as it is still in Debian 9 lockdown. Ubuntu and Mint, well who knows. I can recommend using SCons from the mainline repository. I use it with alias: alias scons="python3 /home/users/russel/Repositories/Mercurial/Forks/SCons/src/script/scons.py but, obviously, that only works for my location of the clone. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Concept proposal: Safely catching error
On Wednesday, 7 June 2017 at 19:45:05 UTC, ag0aep6g wrote: You gave the argument against catching out-of-bounds errors as: "it means an invariant is broken, which means the code surrounding it probably makes invalid assumptions and shouldn't be trusted." That line of reasoning applies to @trusted code. Only @trusted code can lose its trustworthiness. @safe code is guaranteed trustworthy (except for calls to @trusted code). To clarify, when I said "shouldn't be trusted", I meant in the general sense, not in the memory safety sense. I think Jonathan M Davis put it nicely: On Wednesday, 31 May 2017 at 23:51:30 UTC, Jonathan M Davis wrote: Honestly, once a memory corruption has occurred, all bets are off anyway. The core thing here is that the contract of indexing arrays was violated, which is a bug. If we're going to argue about whether it makes sense to change that contract, then we have to discuss the consequences of doing so, and I really don't see why whether a memory corruption has occurred previously is relevant. [...] In either case, the runtime has no way of determining the reason for the failure, and I don't see why passing a bad value to index an array is any more indicative of a memory corruption than passing an invalid day of the month to std.datetime's Date when constructing it is indicative of a memory corruption. The sane way to protect against memory corruption is to write safe code, not code that *might* shut down brutally onces memory corruption has already occurred. This is done by using @safe and proofreading all @trusted functions in your libs. Contracts are made to preempt memory corruption, and to protect against *programming* errors; they're not recoverable because breaking a contract means that from now on the program is in a state that wasn't anticipated by the programmer. Which means the only way to handle them gracefully is to cancel what you were doing and go back to the pre-contract-breaking state, then produce a big, detailed error message and then exit / remove the thread / etc. I think the issue of @trusted is tangential to this. If you (or the writer of a library you use) are using @trusted to cast away pureness and then have side effects, you're already risking data corruption and undefined behavior, catching Errors or no catching Errors. The point is that an out-of-bounds error implies a bug somewhere. If the bug is in @safe code, it doesn't affect safety at all. There is no explosion. But if the bug is in @trusted code, you can't determine how large the explosion is by looking at the function signature. I don't think there is much overlap between the problems that can be caused by faulty @trusted code and the problems than can be caught by Errors. Not that this is not a philosophical problem. I'm making an empirical claim: "Catching Errors would not open programs to memory safety attacks or accidental memory safety blunders that would not otherwise happen". For instance, if some poorly-written @trusted function causes the size of an int[10] slice to be registered as 20, then your program becomes vulnerable to buffer overflows when you iterate over it; the buffer overflow will not throw any Error. I'm not sure what the official stance is on this. As far as I'm aware, contracts and OOB checks are supposed to prevent memory corruption, not detect it. Any security based on detecting potential memory corruption can ultimately be bypassed by a hacker.
Re: sqlite3 vs. sqlite-d
On Wed, 2017-06-07 at 20:40 +, Stefan Koch via Digitalmars-d wrote: > On Wednesday, 7 June 2017 at 20:12:22 UTC, cym13 wrote: > > > It should be noted that the benchmark isn't fair, it favours > > the sqlite3 implementation as parsing and preparing the > > statement isn't measured. And yes, it's still faster which is > > cool ^^ > > > > Yes the benchmark is biased slightly in favor of sqlite3 C > implementation. > But sqlite-d does not have the ability to parse sql to the point > where it could implement that functionality. > Also sqlite-d is inefficient in quite a few places and is slowed > down by auto-decoding as I discovered just now. But what is D's equivalent to Python's SQLAlchemy? C++ now has sqlpp11. Anyone doing SQL code manipulation with strings in another language is doing it wrong. Internal DSLs FTW. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Ali's talk C++Now 2017: Competitive Advantage with D on Reddit!
https://www.reddit.com/r/programming/comments/6fz3yh/cnow_2017_competitive_advantage_with_d/
Re: D for Web Development?
Welcome! On Thursday, 8 June 2017 at 07:32:44 UTC, Michael Reiland wrote: A few questions: - Is vibe.d the recommended way of doing web work? Yes. Adam D. Ruppe also has some easy to use libraries that may suit your need. - Is that book worth purchasing? Don't know. - Does D have a good library for accessing Postgres? I see several listed but I don't know what the most stable would be for production: https://wiki.dlang.org/Libraries_and_Frameworks#Databases When looking for D libraries use code.dlang.org. Sorting by most recently updated is the best proxy for activity at the moment. - Why is D a better solution than Go or .Net Core? Is there something else you would recommend given what I'm looking for? Here's my take on the last one. .Net Core is still immature and probably the most complex in terms of infrastructure setup/maintenance. And my impression is that Go vs D in the web space is more about personal preference than any particular advantage, and I'm coming from C++ so I think D would be more my cup of tea. But that's just my impression from some initial googling. thoughts? recommendations? If you're coming from C++ you should pick up D in almost no time and it will feel much more natural and less repetitive than go. The best introductory reference is http://ddili.org/ders/d.en/index.html if you come across something you're unfamiliar with, but that is aimed more at beginners, so you can just skim it. The vibe.d site has may good examples. You've already discovered one of the good places to ask questions (the other being the IRC), so feel free to ask away if you have any more. Good luck!
Re: .sort vs sort(): std.algorithm not up to the task?
On Thu, 2017-06-08 at 00:23 -0700, Jonathan M Davis via Digitalmars-d- learn wrote: > […] > > release is a member of SortedRange. You don't have to import it > separately. > You have it automatically by virtue of the fact that sort returns a > SortedRange. And unlike calling array, it doesn't copy the entire > range or > allocate. > […] I will have to admit, that on my recent return to more full time D programming, that using both class members, and imported functions with UFCS, can lead to annoyance of understanding. I can't put my finger on what paragraph of documentation would help just yet though. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: D for Web Development?
On Thursday, 8 June 2017 at 07:32:44 UTC, Michael Reiland wrote: - Is vibe.d the recommended way of doing web work? Yes - Is that book worth purchasing? Yes - Does D have a good library for accessing Postgres? I see several listed but I don't know what the most stable would be for production: https://wiki.dlang.org/Libraries_and_Frameworks#Databases Go to the code.dlang.org, at the top of the page select the category 'Development Libraries` and the subcategory 'Database clients or implementations' (or follow the link at [0]) and you'll see a few, like dpq2 [1]. [0] https://code.dlang.org/?sort=updated=library.database [1] https://code.dlang.org/packages/dpq2
Re: .sort vs sort(): std.algorithm not up to the task?
On Thursday, 8 June 2017 at 07:23:27 UTC, Jonathan M Davis wrote: release is a member of SortedRange. You don't have to import it separately. You have it automatically by virtue of the fact that sort returns a SortedRange. And unlike calling array, it doesn't copy the entire range or allocate. sorry, I missed that after accidentally making the change in on file and compiled another. having it return SortedRange is beneficial overall, and calling release to get the original out is as short as passing a template argument like you're suggesting. a point I missed do to the aforementioned mistake. Thanks for the assist, Andrew
Re: .sort vs sort(): std.algorithm not up to the task?
On Wed, 2017-06-07 at 19:39 -0700, Jonathan M Davis via Digitalmars-d- learn wrote: > […] > Even better. I hadn't realized that such a function had been added. > Another import from Python. :-) -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: The reason for SIGSEGV function pointer problem
Thanks also to Paolo Invernizzi and ag0aep6g for answering with a similar response. Using Mike's response as it has extra detail. On Wed, 2017-06-07 at 20:00 +0200, Mike Wey via Digitalmars-d-learn wrote: > On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote: > > So why isn't a thing of type check_frontend_t* > > AFAIK, you would usually translate: > > > typedef int (check_frontend_t*)(void *args, struct dvb_v5_fe_parms > *parms); The C code in dvb-scan.h is actually: typedef int (check_frontend_t)(void *args, struct dvb_v5_fe_parms *parms); > into: > > alias check_frontend_t = extern(C) int function (void* args, > dvb_v5_fe_parms* parms); I can't remember what DStep produced initially, but the above is what I have in dvb_scan.d. Per se it seems consistent, but then functions in D, and their signatures, may be totally different to functions in C. > The problem there is that libdvdv5 defines it as (check_frontend_t) > and > not (check_frontend_t*). > To get around that you can ommit the * in the declaration of > dvb_scan_transponder, and then you should be able to pass > > to it. I am now at the stage of wondering if I remember C semantics, C++ semantics, and D semantics for "pointers to functions". There may also be an issue of there being a bug in DStep… -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: import statement placement
On Wed, 2017-06-07 at 10:08 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > On Wed, Jun 07, 2017 at 01:17:39PM +, Nicholas Wilson via > Digitalmars-d-learn wrote: > > On Wednesday, 7 June 2017 at 12:39:07 UTC, Russel Winder wrote: > > > Are there any idiom rules as to where to put import statements in > > > D? > > > > > > In Python they can go anywhere but PEP-8 suggests they should all > > > go > > > at the top of a file, just after the module documentation string. > > > > Well for ones that aren't scoped (i.e. used pervasively throughout > > the > > module) I always put them after the module declaration (if not the > > file containing main) and doc comment. I am also tending to import individual symbols from modules rather than whole modules. In Python this can sometime be the wrong thing to do, but then the scope rules are different to D. The D import scope rules seem to be equivalent to Python star imports, which is a nightmare. > > For scoped imports they go either on the line after the opening > > brace > > of the enclosing scope, or the line before the (selectively) > > imported > > symbol is used (if there is a reasonable amount of code preceding > > the > > opening brace). I hadn't got into scoped imports. I suspect I am now going to become a fan of them. > I follow the same convention. > > Though lately, I've been finding myself moving away more and more > from > global imports, and moving imports into the scope in which they're > actually used. While that sometimes necessitates more typing, I find > that it also improves code readability and movability: having scoped > imports in the block in which the symbol is used means reducing the > likelihood of overload conflicts with unfortunately-named symbols > (there > are a few of these in Phobos). And I can easily move that code into a > different source file and have it Just Work, instead of having to > twiddle with the import statements at the top of the file (and > inadvertently leave useless imports in the original file where they > are > no longer needed). > > Nowadays I generally only use module-level import for things that are > truly used pervasively, like std.range.primitives, and std.stdio in > the > module where main() is defined. I try to avoid importing std.stdio > anywhere else, unless that module is directly concerned with I/O, and > force myself to structure the code such that such a dependency is not > needed in the first place -- e.g., write generic range-based > algorithms > instead of code sprinkled with calls writeln. I found that this has > helped improve my code quality significantly, and my code has become > much more reusable. > OK, I am now convinced. This still leaves the question of "whole module imports" vs "symbols from modules". Because D imports are equivalent to Python or Java star imports, which are anathema, I am thinking "symbols from modules" remains the best strategy even with scoping. > T > -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
D for Web Development?
Hey guys, I'm looking for a web solution that's: 1. Supported on Linux 2. Statically typed, 3. Reasonably performant, 4. Reasonably productive. 5. Simplicity (in terms of infrastructure and the language itself). The contenders as I see them are .Net Core, Go, and D. I know next to nothing about Go and D and I've never attempted to use .Net Core. I'd like to evaluate D, but since I'm so ignorant I thought I'd post here for people's thoughts. It seems as though vibe.d is the most prevalent framework, and even has a book about it here: https://www.amazon.com/D-Web-Development-Kai-Nacke/dp/178528889X/ A few questions: - Is vibe.d the recommended way of doing web work? - Is that book worth purchasing? - Does D have a good library for accessing Postgres? I see several listed but I don't know what the most stable would be for production: https://wiki.dlang.org/Libraries_and_Frameworks#Databases - Why is D a better solution than Go or .Net Core? Is there something else you would recommend given what I'm looking for? Here's my take on the last one. .Net Core is still immature and probably the most complex in terms of infrastructure setup/maintenance. And my impression is that Go vs D in the web space is more about personal preference than any particular advantage, and I'm coming from C++ so I think D would be more my cup of tea. But that's just my impression from some initial googling. thoughts? recommendations?
Re: .sort vs sort(): std.algorithm not up to the task?
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote: Ranges may be finite or infinite but, while the destination may be unreachable, we can definitely tell how far we've traveled. So why doesn't this work? import std.traits; import std.range; void main() { string[string] aa; // what others have referred to as // standard sort works but is deprecated //auto keys = aa.keys.sort; // Error: cannot infer argument types, expected 1 argument, not 2 import std.algorithm: sort; auto keys = aa.keys.sort(); // this works but why should I have to? //import std.array: array; //auto keys = aa.keys.sort().array; foreach (i, v; keys){} } If I hand you a chihuahua for grooming, why am I getting back a pit bull? I simply want a groomed chihuahua. Why do I need to consult a wizard to get back a groomed chihuahua? You may want to slice chihuahua first, pass it to mir.ndslice.sort [1], and get back your groomed sliced chihuahua. [1] http://docs.algorithm.dlang.io/latest/mir_ndslice_sorting.html#.sort.sort
Re: .sort vs sort(): std.algorithm not up to the task?
On Thursday, June 08, 2017 04:07:22 Andrew Edwards via Digitalmars-d-learn wrote: > On Thursday, 8 June 2017 at 03:40:08 UTC, Jonathan M Davis wrote: > > On Thursday, June 08, 2017 03:15:11 Andrew Edwards via > > > > Digitalmars-d-learn wrote: > >> I completely understand the differences between ranges and > >> arrays... the thing is, I wasn't working with ranges but > >> arrays instead. If sort understands a string or array as a > >> sort of range, then given one of those entities, it should > >> manipulate it internally and return it in it's original > >> flavor. Given an array, return an array unless specifically > >> told to do otherwise. > > > > sort() returns a SortedRange so that other algorithms can know > > that the range is sorted and take advantage of that. If sort() > > returned the original range type, it would be detrimental for > > other algorithms. But you can just use the array directly again > > after calling sort or call release() on the SortedRange to get > > the array out of it. > > > > - Jonathan M Davis > > Yes, I understand that. Again, using "std.range: release" earns > me nothing more than I already get from "std.array: array" or if > you prefer "std.range: array". I can understand if sort returns > Range by default but can be instructed to return the original > representation. release is a member of SortedRange. You don't have to import it separately. You have it automatically by virtue of the fact that sort returns a SortedRange. And unlike calling array, it doesn't copy the entire range or allocate. > aa.keys.sort!returnOriginalRepresentation; // or something > to that effect > > But it doesn't, it decides what i'm gonna get like it or not. But > the fact, a lot of times I just want to work with the underlying > data after the operation is performed. And it should be noted > that this applies to Ranges in general not just sort. It's just life with ranges that you're usually going to end up with a new type when you call a range-based functions. Most of them can't even do what they're supposed to do without returning a new type, and that type often is not same level of range as the original (e.g. filter returns a new range, and it's only a forward range even if the original is a random-access range, and it can't do otherwise given that it's lazy). Pretty much the only way for ranges in general to return the same type would be if you were only dealing with dynamic arrays, and you were willing to have the range-based function not only be non-lazy, but you were also willing to have it allocate. And if you're going that route, you might as well just have functions operating on dynamic arrays instead of ranges. As it stands, we have functions that return lazy ranges so that they're efficient, and if you want a dynamic array back, you call array on the result. Sure, if you're looking to only operate on dynamic arrays, then that can be a bit annoying, but overall, it leads to much more efficient code, and a lot of code works just fine without to call array having to worry about whether dynamic arrays are involved at all. It's true that sort could work with returning the original type and without allocating (unlike a function like filter), but having it return SortedRange is beneficial overall, and calling release to get the original out is as short as passing a template argument like you're suggesting. Also, you can simply call sort on a separate line and continue to use the array without worrying about sort's return value. So, while I can understand that you'd like sort to just return the array in this case, it's so simple to work around it that this really doesn't seem like it should be a big deal. The reality of the matter is that if you're going to be annoyed about range-based functions returning new types, you're going to be annoyed a lot when dealing with range-based functions. - Jonathan M Davis