Re: Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
On Monday, 23 January 2017 at 23:04:45 UTC, Ali Çehreli wrote: On 01/23/2017 02:58 PM, bitwise wrote: I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not: https://github.com/dlang/phobos/blob/04cca5c85ddf2be253

Re: General performance tips

2017-01-23 Thread kinke via Digitalmars-d-learn
On Monday, 23 January 2017 at 12:13:30 UTC, albert-j wrote: There's not much object creation going on there, mostly loops over arrays, so I assume GC is not an issue. When passing arrays around, beware that static arrays are value types in D and are copied unless passed by reference.

Re: Output range and writeln style functions

2017-01-23 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 23 January 2017 at 22:20:59 UTC, Ali Çehreli wrote: On 01/23/2017 12:48 PM, Jon Degenhardt wrote: [snip] > So, what I'm really wondering is if there is built-in way to get closer to: outputStream.writefln(...); If it's about formatted output then perhaps formattedWrite?

Re: Safely moving structs in D

2017-01-23 Thread Ali Çehreli via Digitalmars-d-learn
On 01/23/2017 02:58 PM, bitwise wrote: I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not: https://github.com/dlang/phobos/blob/04cca5c85ddf2be25381fc63c3e941498b17541b/std/container/array.d#L884 Post-blit is

Re: Safely moving structs in D

2017-01-23 Thread sarn via Digitalmars-d-learn
On Monday, 23 January 2017 at 22:26:58 UTC, bitwise wrote: Is it ok to memcpy/memmove a struct in D? Quote from here: https://dlang.org/spec/garbage.html "Do not have pointers in a struct instance that point back to the same instance. The trouble with this is if the instance gets moved in mem

Re: Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not: https://github.com/dlang/phobos/blob/04cca5c85ddf2be25381fc63c3e941498b17541b/std/container/array.d#L884

Re: General performance tips

2017-01-23 Thread sarn via Digitalmars-d-learn
On Monday, 23 January 2017 at 12:13:30 UTC, albert-j wrote: Well it is actually ODE solver from Numerical recipes (originally in C++) that I am trying to do in D. Code translation seems very straightforward. Maybe there's someone around who has done that already? There's not much object creati

Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
Is it ok to memcpy/memmove a struct in D? Quote from here: https://dlang.org/spec/garbage.html "Do not have pointers in a struct instance that point back to the same instance. The trouble with this is if the instance gets moved in memory, the pointer will point back to where it came from, wit

Re: Output range and writeln style functions

2017-01-23 Thread Ali Çehreli via Digitalmars-d-learn
On 01/23/2017 12:48 PM, Jon Degenhardt wrote: On Monday, 23 January 2017 at 08:03:14 UTC, Ali Çehreli wrote: On 01/22/2017 01:54 PM, Jon Degenhardt wrote: I've been increasingly using output ranges in my code (the "component programming" model described in several articles on the D site). It wo

Re: Output range and writeln style functions

2017-01-23 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 23 January 2017 at 08:03:14 UTC, Ali Çehreli wrote: On 01/22/2017 01:54 PM, Jon Degenhardt wrote: I've been increasingly using output ranges in my code (the "component programming" model described in several articles on the D site). It works very well, except that it would often be m

Re: Multiple return type or callback function

2017-01-23 Thread Basile B. via Digitalmars-d-learn
On Monday, 23 January 2017 at 15:15:35 UTC, aberba wrote: I'm creating a function to authenticate user login. I want to determine login failure (Boolean) and error message (will be sent to frontend) but D does have multiple return type [...] Yes, MRV can be done with a tuple auto foo() {

Re: Multiple return type or callback function

2017-01-23 Thread pineapple via Digitalmars-d-learn
On Monday, 23 January 2017 at 15:15:35 UTC, aberba wrote: I'm creating a function to authenticate user login. I want to determine login failure (Boolean) and error message (will be sent to frontend) but D does have multiple return type (IMO could use struct but will make code dirty with too muc

Re: Compile to C?

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 23 January 2017 at 15:24:09 UTC, aberba wrote: Unless you will be limited by tge limitations of C. Vala programming language has that issue even though they utilize GObject What limitations? C/C++ programs go around "limitations" by using compiler extensions and runtime libraries.

Re: Compile to C?

2017-01-23 Thread aberba via Digitalmars-d-learn
On Monday, 23 January 2017 at 14:40:18 UTC, Ola Fosheim Grøstad wrote: On Saturday, 21 January 2017 at 19:30:31 UTC, Jack Stouffer wrote: On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be

Multiple return type or callback function

2017-01-23 Thread aberba via Digitalmars-d-learn
I'm creating a function to authenticate user login. I want to determine login failure (Boolean) and error message (will be sent to frontend) but D does have multiple return type (IMO could use struct but will make code dirty with too much custom types). struct Result { bool success = false

Re: Compile to C?

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 23 January 2017 at 14:53:54 UTC, Bauss wrote: I'd guess the code generation you'd get from doing so with D would be absolute horrific to read, because you'll get rid of CTFE, templates, proper class structure, globals properly stored, since everything in D is TLS and C doesn't then y

Re: Compile to C?

2017-01-23 Thread Bauss via Digitalmars-d-learn
On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability. Nim is able to, because Nim doesn't really compile. The Nim compiler just translates Nim code to C code and

Re: Compile to C?

2017-01-23 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 21 January 2017 at 19:30:31 UTC, Jack Stouffer wrote: On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability. No, and this is actually a terrible idea

Re: Confirming and uninstantiated struct

2017-01-23 Thread Mike Parker via Digitalmars-d-learn
On Monday, 23 January 2017 at 13:57:23 UTC, aberba wrote: if (stu is Student.init) //will confirm when i get to my pc That works, as does this: if(stu == Student.init)

Re: Confirming and uninstantiated struct

2017-01-23 Thread rikki cattermole via Digitalmars-d-learn
Structs are a value type and will always have a type that won't be null. If you want it to be nullable you will have to use pointers or classes (there is also Nullable in std.typecons but it won't work with is null). s/have a type that won't be null/have a value that won't be null/ My bad.

Re: Confirming and uninstantiated struct

2017-01-23 Thread rikki cattermole via Digitalmars-d-learn
On 24/01/2017 2:57 AM, aberba wrote: How do I verify this struct has no value Student getStudent() { ... Student s; if(condition) s = Student; return s; } auto stu = getStudent(); //which will work and is best? if (stu is null) //doesn't wrk. if (stu is Student.init) //will con

Confirming and uninstantiated struct

2017-01-23 Thread aberba via Digitalmars-d-learn
How do I verify this struct has no value Student getStudent() { ... Student s; if(condition) s = Student; return s; } auto stu = getStudent(); //which will work and is best? if (stu is null) //doesn't wrk. if (stu is Student.init) //will confirm when i get to my pc Or how would

Re: General performance tips

2017-01-23 Thread albert-j via Digitalmars-d-learn
Without seeing the source there is nothing we can do. Usually performant d-code looks quite diffrent from java code. For example to avoid the gc :) Well it is actually ODE solver from Numerical recipes (originally in C++) that I am trying to do in D. Code translation seems very straightforward

Re: General performance tips

2017-01-23 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 23 January 2017 at 11:11:21 UTC, albert-j wrote: I have translated some simulation code from Java into D (a few classes, mostly manipulation of double arrays in small methods). D version runs 10-30% slower than Java (ldc2, dub release build). Profiling did not show any obvious bottle

General performance tips

2017-01-23 Thread albert-j via Digitalmars-d-learn
I have translated some simulation code from Java into D (a few classes, mostly manipulation of double arrays in small methods). D version runs 10-30% slower than Java (ldc2, dub release build). Profiling did not show any obvious bottlenecks. I am wondering whether I missed something, or such pe

Re: Output range and writeln style functions

2017-01-23 Thread Ali Çehreli via Digitalmars-d-learn
On 01/22/2017 01:54 PM, Jon Degenhardt wrote: I've been increasingly using output ranges in my code (the "component programming" model described in several articles on the D site). It works very well, except that it would often be more convenient to use writeln style functions rather than 'put'.