Re: code review based on what I learned from D

2015-07-05 Thread Rikki Cattermole via Digitalmars-d-learn
On 5/07/2015 6:53 p.m., Szabo Bogdan wrote: Hi, Recently while I was reviewing some swift code, a colleague left me the impression that I am the one with the bad habits and these were learned while coding in D. I still think that I proposed some changes to avoid some bugs but I was told that I a

Re: code review based on what I learned from D

2015-07-05 Thread ketmar via Digitalmars-d-learn
On Sun, 05 Jul 2015 06:53:34 +, Szabo Bogdan wrote: > For both of these issues I was told that swift is not Java and if the > situations that I described happens, you don't want to crash the user > app, because this will make the user unhappy. i completely agree. it's way better to keep going

Re: code review based on what I learned from D

2015-07-05 Thread Rikki Cattermole via Digitalmars-d-learn
On 5/07/2015 9:37 p.m., ketmar wrote: On Sun, 05 Jul 2015 19:01:59 +1200, Rikki Cattermole wrote: Failing gracefully. Not something most developers do. usually that is not related. i mean that if program entered invalid state, it may be too late to save user data. it may be even undesirable t

Re: code review based on what I learned from D

2015-07-05 Thread Rikki Cattermole via Digitalmars-d-learn
On 5/07/2015 9:32 p.m., ketmar wrote: On Sun, 05 Jul 2015 06:53:34 +, Szabo Bogdan wrote: For both of these issues I was told that swift is not Java and if the situations that I described happens, you don't want to crash the user app, because this will make the user unhappy. i completely

Re: code review based on what I learned from D

2015-07-05 Thread ketmar via Digitalmars-d-learn
On Sun, 05 Jul 2015 19:01:59 +1200, Rikki Cattermole wrote: > Failing gracefully. Not something most developers do. usually that is not related. i mean that if program entered invalid state, it may be too late to save user data. it may be even undesirable to do so, as the data may be already co

Re: code review based on what I learned from D

2015-07-05 Thread ketmar via Digitalmars-d-learn
On Sun, 05 Jul 2015 21:39:23 +1200, Rikki Cattermole wrote: > Of course of course. > Valid options in failing gracefully include resetting the data and > informing the user. Also giving them an option to send a bug report to > the devs. > Point being, having it just fail on start each time is not

Re: Switching rows with columns

2015-07-05 Thread via Digitalmars-d-learn
On Sunday, 5 July 2015 at 00:18:18 UTC, Tanel Tagaväli wrote: On Saturday, 4 July 2015 at 16:29:44 UTC, Marc Schütz wrote: Try std.range.transposed: http://dlang.org/phobos/std_range.html#.transposed Does this work with user-defined types? I defined two structs that implement the InputRange(p

How to strip struct/class invariants?

2015-07-05 Thread Artem Tarasov via Digitalmars-d-learn
OK, so there was an old bug fixed in 2.067 (https://issues.dlang.org/show_bug.cgi?id=4421) so that now unions apparently can't contain a struct that has invariants. It kinda makes sense, although I don't see why the invariants can be simply ignored, as they don't have as much importance as des

Re: Switching rows with columns

2015-07-05 Thread via Digitalmars-d-learn
On Sunday, 5 July 2015 at 11:35:14 UTC, Marc Schütz wrote: Maybe it's the last condition, `hasAssignableElements`. I don't know whether that one is really necessary... It probably is. The last check returned false. Since I already would have to implement "r.front = ", I'll just use arrays. T

Re: How to strip struct/class invariants?

2015-07-05 Thread John Colvin via Digitalmars-d-learn
On Sunday, 5 July 2015 at 12:15:32 UTC, Artem Tarasov wrote: OK, so there was an old bug fixed in 2.067 (https://issues.dlang.org/show_bug.cgi?id=4421) so that now unions apparently can't contain a struct that has invariants. It kinda makes sense, although I don't see why the invariants can be

Re: How to strip struct/class invariants?

2015-07-05 Thread Artem Tarasov via Digitalmars-d-learn
On Sunday, 5 July 2015 at 14:44:30 UTC, John Colvin wrote: struct A { ubyte[B.sizeof] mem; @property ref B b() { return *cast(B*)(mem.ptr); } mixin std.typecons.Proxy!b; } Thanks, I followed your suggestion and effectively rolled out my own union implementation. U

incorrect data when returning static array in place of dynamic

2015-07-05 Thread sigod via Digitalmars-d-learn
Consider this code: ``` import std.digest.digest; import std.stdio; ubyte[] hmac_sha1(const(ubyte)[] key, const(ubyte)[] message) { import std.digest.sha; enum block_size = 64; if (key.length > block_size) key = sha1Of(key); if (key.length < block

Re: How to setup GDC with Visual D?

2015-07-05 Thread Johannes Pfau via Digitalmars-d-learn
Am Sat, 04 Jul 2015 11:15:57 + schrieb "Guy Gervais" : > On Saturday, 4 July 2015 at 08:34:00 UTC, Johannes Pfau wrote: > > > It's kinda fascinating that GDC/MinGW seems to work for some > > real world applications. > > I haven't really tried a "real world application" as of yet; > mostly

Re: bigint compile time errors

2015-07-05 Thread Kai Nacke via Digitalmars-d-learn
On Friday, 3 July 2015 at 04:08:32 UTC, Paul D Anderson wrote: On Friday, 3 July 2015 at 03:57:57 UTC, Anon wrote: On Friday, 3 July 2015 at 02:37:00 UTC, Paul D Anderson wrote: enum BigInt test1 = BigInt(123); enum BigInt test2 = plusTwo(test1); public static BigInt plusTwo(in bigint n) S

std.experimental.allocator destructor safe?

2015-07-05 Thread Laeeth Isharc via Digitalmars-d-learn
Can I call theAllocator.dispose from a struct destructor? None of the things pointed to by the root will be allocated directly by GC. Laeeth.

Array operations with array of structs

2015-07-05 Thread Peter via Digitalmars-d-learn
Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op == "+"){ Vector3 result; result._p[] = this

Re: Array operations with array of structs

2015-07-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op == "+

Re: Array operations with array of structs

2015-07-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote: On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Ve

Re: incorrect data when returning static array in place of dynamic

2015-07-05 Thread thedeemon via Digitalmars-d-learn
On Sunday, 5 July 2015 at 18:57:46 UTC, sigod wrote: Why does function return incorrect data? Using `.dup` in return expression or using `ubyte[20]` as return type fixes problem, but why? Because sha1Of() returns ubyte[20], this is a stack-allocated array, a value type. If you put correct ret