Re: Help optimizing code?

2018-01-01 Thread Uknown via Digitalmars-d-learn

On Tuesday, 2 January 2018 at 07:17:23 UTC, Uknown wrote:

[snip]
0. Use LDC. It is significantly faster.
1. Utilize the fact that the Mandelbrot  set is symmetric about 
the X axis.You can half the time taken.

2. Use std.parallelism for using multiple cores on the CPU
3. Use @fastmath of LDC
4. imageData.reserve(width * height * 3) before the loop
5. [1] is a great article on this specific topic
[snip]


Forgot to mention that since you already know some of the edges, 
you can avoid unnecessarily looping through some regions. That 
saves a lot of time


Re: Help optimizing code?

2018-01-01 Thread Uknown via Digitalmars-d-learn

On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote:
I started learning D a few days ago, coming from some very 
basic C++ knowledge, and I'd like some help getting a program 
to run faster. The code is here: 
https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d


Right now it runs slower than my JavaScript Mandelbrot renderer 
on the same quality settings, which is clearly ridiculous, but 
I don't know what to do to fix it. Sorry for the lack of 
comments, but I can never tell what will and won't be obvious 
to other people.


Hey! I happened to also write a Mandelbrot generator in D. It was 
based of the version given on rossetacode for C[0].

Some of the optimizations I used were:

0. Use LDC. It is significantly faster.
1. Utilize the fact that the Mandelbrot  set is symmetric about 
the X axis.You can half the time taken.

2. Use std.parallelism for using multiple cores on the CPU
3. Use @fastmath of LDC
4. imageData.reserve(width * height * 3) before the loop
5. [1] is a great article on this specific topic

For reference, on my 28W 2 core i5, a 2560x1600 image took about 
2 minutes to

render, with 500,000 iterations per pixel.
[2] is my own version.

[0]: 
https://rosettacode.org/wiki/Mandelbrot_set#PPM_non_interactive
[1]: 
https://randomascii.wordpress.com/2011/08/13/faster-fractals-through-algebra/
[2]: 
https://github.com/Sirsireesh/Khoj-2017/blob/master/Mandelbrot-set/mandlebrot.d


Re: Is there a way to call scope guard without throw exception?

2018-01-01 Thread ChangLong via Digitalmars-d

On Monday, 1 January 2018 at 03:06:42 UTC, David Nadlinger wrote:

On Saturday, 30 December 2017 at 13:48:16 UTC, ChangLong wrote:
After fiber yield, the spoke guard is not able to execute,  
unless I throw a exception in Fiber.  I am look if there is 
some hack method to make the fiber Interrupted at any time with

 scope(exit) code executed.


There isn't. In fact, ensuring that the scope isn't left is the 
whole point of fibre context switches – how else would 
execution continue after the fibre is returned to? (How would 
objects be "un-destroyed"?)


However, there is nothing stopping you from creating a registry 
of resources yourself, and then wrapping the Fiber.yield() call 
into something like:


void myYield() {
  registry.releaseResources();
  Fiber.yield();
  registry.reacquireResources();
}

You could have the resource handles be structs that register 
themselves with the registry to integrate with fibre 
scheduling, and that also have a destructor to execute the 
cleanup when the scope is left (like `scope(exit)`).


 — David



I was looking for some thing like yieldAndThrow,  and destroy or 
reset the fiber same time, without throw exception but call the 
scope(exit).  I guess It maybe can be done with some ASM jump 
code.  (or I am wrong.)


I already ask from Learn board few days ago,  no answer yet so I 
paste it here.





[Issue 18146] A case expression of final switch allows to pass wrong enum value

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18146

ARAI Kohei  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #2 from ARAI Kohei  ---
I updated dmd to version 2.078.0(beta), the issue is resolved.

--


Re: Maybe D is right about GC after all !

2018-01-01 Thread codephantom via Digitalmars-d

On Tuesday, 2 January 2018 at 00:34:57 UTC, Nerve wrote:


I would simply add that the strongest vocalizations come from 
those with objections. The silent majority that is perfectly 
okay with GC and gets huge development complexity reductions 
thanks to it rarely spare the energy to argue againts the 
constant GC complaints.


Well, consider the silent 'minority' too, who still think that 
increasing performance, and reducing demands on resources, still 
matter, a lot, and that we shouldn't just surrender this just to 
make programmers more 'productive' (i.e so they can ship slower 
GC code, more quickly).


Or are you saying there is no overhead associated with GC?
Or if there is, are you saying it never matters..ever?

Or are you saying GC does not impose extra demand on resources?
Or if it does, are you saying it never matters..ever?

What it really comes down to though, is language designers 
ensuring that any language that defines itself as a 'modern 
systems programming language', gives control 'to the programmer', 
and not the other way around.


We've had over a decade of this crazy unconstrained growth in 
bloat (slower code, and more of it), in the world of software 
developement. So, perhaps we should start paying more attention 
to the vocal minority.




[Issue 17630] selective imports find symbols in private imports of other modules

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17630

--- Comment #4 from Seb  ---
There is/was an open PR to fix this by Kenji:
https://github.com/dlang/dmd/pull/3416

--


Re: structs inheriting from and implementing interfaces

2018-01-01 Thread rjframe via Digitalmars-d-learn
On Tue, 02 Jan 2018 00:54:13 +, Laeeth Isharc wrote:

> On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote:
>> On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote:
>>
>> I've actually thought about doing this to get rid of a bunch of if
>> qualifiers in my function declarations. `static interface {}` compiles
>> but doesn't [currently] seem to mean anything to the compiler, but
>> could be a hint to the programmer that nothing will directly implement
>> it; it's a compile-time interface. This would provide a more generic
>> way of doing stuff like `isInputRange`, etc.
> 
> Atila does something like this
> 
> https://code.dlang.org/packages/concepts

Thanks; I actually started skimming through his repositories a couple of 
days ago, but didn't see this.

--Ryan


Re: Super Simple GUI Library

2018-01-01 Thread Martin Nowak via Digitalmars-d-announce

On Tuesday, 2 January 2018 at 02:06:00 UTC, Ivan Trombley wrote:
For now, app.d has an example in the doc comments. I'll be 
adding more examples to the doc comments.


Generating documentation is as simple as `dub build -b ddox` btw.
See https://github.com/MartinNowak/bloom for an example on how to 
publish them to gh-pages during CI.


Note that the default ddox filter arguments exclude undocumented 
modules.

So you either need to add ddoc comments on the module declarations

```d
/// app module
module ssgl.app;
```

or change `"-ddoxFilterArgs"` to sth. non-default 
https://github.com/dlang/dub/blob/bf095d8018d34ec0bf3d7459f722b67d7ddb804f/source/dub/dub.d#L1142.


Re: Super Simple GUI Library

2018-01-01 Thread Ivan Trombley via Digitalmars-d-announce

On Monday, 1 January 2018 at 23:38:45 UTC, Anton Pastukhov wrote:
Hi, it would be nice to see some more info. Screenshots, docs 
etc. Right now there is just another github repo without single 
example.


For now, app.d has an example in the doc comments. I'll be adding 
more examples to the doc comments.





Re: D downloads

2018-01-01 Thread Laeeth Isharc via Digitalmars-d

On Saturday, 30 December 2017 at 00:14:45 UTC, codephantom wrote:
On Saturday, 23 December 2017 at 21:04:52 UTC, Laeeth Isharc 
wrote:

http://erdani.com/d/downloads.daily.png

Bad data, one off spike, or something else?



https://successfulsoftware.net/2015/05/14/the-mystery-of-the-chinese-downloads/


Maybe we should produce two charts, one filtering out Chinese IPs



Re: D downloads

2018-01-01 Thread Laeeth Isharc via Digitalmars-d
On Thursday, 28 December 2017 at 22:02:16 UTC, Walter Bright 
wrote:

On 12/24/2017 7:33 AM, Laeeth Isharc wrote:

(The first person to receive
Bitcoin was Hal Finney, a prominent member of both the 
extropians and cypherpunks lists).
Hal was in the dorm room next to mine when I was a freshman. He 
was one of the smartest people I've ever known, by a wide 
margin. Also one of the nicest.


I've always suspected Hal of being Satoshi :-) A grand joke 
like that is something he'd do.


Some people reasonably well placed to have an idea think he was 
part of the group mind that Satoshi became...


I dug out the archives recently for both mailing lists.  Amazing 
the high level of discussion back then, and how those fringe 
ideas became mainstream.  It took a while though!





Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Meta via Digitalmars-d-learn

On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote:

In C#, structs can inherit from and implement interfaces.


using System;

interface IPrint
{
void Print();
}

struct MyStruct : IPrint
{
public void Print()
{
Console.WriteLine(ToString());
}
}

public class Program
{
public static void Main()
{
MyStruct s = new MyStruct();
s.Print();
}
}

https://dotnetfiddle.net/lpXR1O

But in D it doesn't appear possible.

import std.stdio;

interface IPrint
{
void print();
}

// Error: base classes are not allowed for struct, did you mean 
;?
struct MyStruct : IPrint   // Error: base classes are not 
allowed for struct, did you mean ;?

{
void print()
{
writeln("MyStruct");
}
}

void main()
{
MyStruct s;
s.Print();
}

https://run.dlang.io/is/j4xwla

Is that simply because it hasn't been implemented or suggested 
yet for D, or was there a deliberate design decision?


Thanks for your insight,

Mike


You want wrap: https://dlang.org/phobos/std_typecons.html#wrap


Re: Maybe D is right about GC after all !

2018-01-01 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, January 02, 2018 00:34:57 Nerve via Digitalmars-d wrote:
> On Tuesday, 19 December 2017 at 09:54:05 UTC, Walter Bright wrote:
> > "C, Python, Go, and the Generalized Greenspun Law"
> >
> > http://esr.ibiblio.org/?p=7804
>
> I would simply add that the strongest vocalizations come from
> those with objections. The silent majority that is perfectly okay
> with GC and gets huge development complexity reductions thanks to
> it rarely spare the energy to argue againts the constant GC
> complaints.

+1

- Jonathan M Davis



[Issue 14660] std.range.choose() is not CTFE'able

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=14660

--- Comment #4 from Ali Ak  ---
Sweet! Thanks!

--


Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Laeeth Isharc via Digitalmars-d-learn

On Friday, 29 December 2017 at 12:59:21 UTC, rjframe wrote:

On Fri, 29 Dec 2017 12:39:25 +, Nicholas Wilson wrote:

On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin 
wrote:


The problem is that interfaces are a runtime thing (e.g. you 
can cast a

class to an interface)
structs implement compile time interfaces via template duck 
typing

(usually enforced via an if()).
you could probably write a wrapper that introspected an 
interface and

enforced that all members were implemented.


I've actually thought about doing this to get rid of a bunch of 
if qualifiers in my function declarations. `static interface 
{}` compiles but doesn't [currently] seem to mean anything to 
the compiler, but could be a hint to the programmer that 
nothing will directly implement it; it's a compile-time 
interface. This would provide a more generic way of doing stuff 
like `isInputRange`, etc.


Atila does something like this

https://code.dlang.org/packages/concepts




Re: Maybe D is right about GC after all !

2018-01-01 Thread Nerve via Digitalmars-d

On Tuesday, 19 December 2017 at 09:54:05 UTC, Walter Bright wrote:

"C, Python, Go, and the Generalized Greenspun Law"

http://esr.ibiblio.org/?p=7804


I would simply add that the strongest vocalizations come from 
those with objections. The silent majority that is perfectly okay 
with GC and gets huge development complexity reductions thanks to 
it rarely spare the energy to argue againts the constant GC 
complaints.


Re: Super Simple GUI Library

2018-01-01 Thread Anton Pastukhov via Digitalmars-d-announce

On Monday, 1 January 2018 at 01:57:13 UTC, Ivan Trombley wrote:
I started a new GUI library project (for various reasons) base 
on SDL2. It's pretty basic at the moment but I created a github 
repository so that I can hopefully get some feedback on it. 
What is currently present:


- App: an application struct housing the main loop.
- Handle: a RAII struct for conveneint handling of SDL pointers.
- Area: an abstract rectangular base class for UI items.
- BlankArea: a non-visible area that can have children.
- RenderArea: an area with children and a render delegate for 
custom drawing.

- VisibleArea: a basic visible area.
- TextArea: an area for displaying a single line of text.

The github repository is here:
https://github.com/Barugon/ssgl

Please let me know what you think.


Hi, it would be nice to see some more info. Screenshots, docs 
etc. Right now there is just another github repo without single 
example.


[Issue 14660] std.range.choose() is not CTFE'able

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=14660

Seb  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||greensunn...@gmail.com
 Resolution|--- |FIXED

--- Comment #3 from Seb  ---
No workaround needed, just use dmd-nightly or the upcoming 2.078 release (will
be released in the next hours or tomorrow).


Example: https://run.dlang.io/is/ss9U1c


This was fixed in https://github.com/dlang/phobos/pull/5677, but wasn't
referenced (hence no changelog nor auto-closing of this issue).

--


[Issue 14660] std.range.choose() is not CTFE'able

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=14660

Ali Ak  changed:

   What|Removed |Added

 CC||ali.akhtarz...@gmail.com

--- Comment #2 from Ali Ak  ---
Is there a workaround for this hidden in someone's head? I.e. anyway around the
void[] buffer, or is it viable to allow casts in CTFE to make this succeed?

--


Re: Lazily parse a JSON text file using stdx.data.json?

2018-01-01 Thread David Gileadi via Digitalmars-d

On 12/30/17 8:16 PM, Marco Leise wrote:

There is also the JSON parser from
https://github.com/mleise/fast
if you need to parse 2x faster than RapidJSON ;)


Nice, I'll take a look.

My original post was mainly to express how surprised I was that one of 
D's front-page features was, for me, impossible to get working in this 
context. I posted in hopes that more experienced folks might consider 
making fixes to help smooth future attempts by others.


I realize that compile-time ranges are not runtime interfaces like many 
languages provide for iteration, but right now ranges seem too hard to 
get right when it feels like they should just work.


Re: Cannot confirm that a DigitalMars order has been received

2018-01-01 Thread Walter Bright via Digitalmars-d

On 1/1/2018 6:42 AM, Dennis wrote:

On Friday, 24 November 2017 at 22:34:53 UTC, Walter Bright wrote:
It should be in your email inbox by now. I review purchases manually, because 
of occasional attempts to manipulate the shopping cart. Sorry about the delay.


I don't like bumping this topic, but I have the same issue. I ordered the 
Extended Utility Package on December 23 2017, got an e-mail from Paypal 
confirming the transaction but nothing else. I sent an e-mail to "wgmars7 at 
domainname" but I have not recieved a reply yet. Can you please check the order?


I just sent it to you. Sometimes these things end up in peoples' spam folders or 
get "quarantined" because of the attachment. If you still do not receive it, 
please let me know and maybe you have another email address you can use.


Re: static if and early exit from function doesn't seem to work?

2018-01-01 Thread aliak via Digitalmars-d-learn

On Sunday, 31 December 2017 at 13:47:32 UTC, Adam D. Ruppe wrote:

On Sunday, 31 December 2017 at 13:32:03 UTC, aliak wrote:
So it seems it tries to compile the statements below the check 
on V.length even though it's guaranteed to be true and there's 
a return statement inside the if.


Yeah, static if includes or excludes code independently at 
compile time.


So what you wrote there would be like, assuming the first to 
static ifs pass:


auto concat(R, V...)(R range, V values) if (isInputRange!R) {
import std.range: chain, ElementType;
return range;
return range.chain(values[0]).concat(values[1..$]);
}


The code is still there, even if it isn't reached due to an 
early return, and thus still must compile.


Using else static if means it won't be generated.


Ah ok, thanks! So it is intended behavior. I wonder if treating a 
return like a static else would be a good idea though. I at least 
can't see how it would break anything at this time.





Re: How do you safely deal with range.front?

2018-01-01 Thread aliak via Digitalmars-d-learn

On Monday, 1 January 2018 at 02:18:36 UTC, Jonathan M Davis wrote:
Except that the reason for arrays throwing RangeErrors when you 
try and index them out-of-bounds is to avoid memory safety 
issues, which is not necessarily the case at all when you're 
talking about ranges. Having ranges in general be checking 
empty in front, popFront, back, etc. would add unnecessary 
overhead - especially when you consider that ranges often wrap 
other ranges. You'd be layering on check after check when the 
calling code is already supposed to be checking empty when 
necessary to make sure that the range isn't empty. You'd even 
be layering checks on top of the checks that arrays already do, 
since many ranges are ultimately wrapped around a dynamic array 
at their core.


[...]


Makes sense. Especially after pointing out that ranges are mostly 
arrays at the end. Thanks!




Re: What don't you switch to GitHub issues

2018-01-01 Thread Pjotr Prins via Digitalmars-d

On Monday, 1 January 2018 at 02:02:03 UTC, rjframe wrote:

That's probably not the best method of effecting change.


It killed off the discussion nicely, indeed.

I am just going to share my thoughts a little. Github, in my 
opinion, is hype and even though I depend on it today, I am 
trying to decrease that dependency. We should build a world that 
is not dependent on single companies. I am not downplaying what 
github has done for us (I am one of the early users) - but they 
have just become a little too important for free software to be 
comfortable. The github issue tracker is wanting anyway.


D is a great language. I just spent 6 months in C++ and the last 
month worked on a D multi-threaded project again. I'll blog about 
this soon, but the short of it is that I am very grateful to 
Walter, Andrei, Kai, Ian, Johan and others for creating a 
language that fits our needs so well! D software is doing 
critical work around the world every second. D is probably not a 
language for the hype community - let them have Go and Rust. I 
honestly don't care. And D should not care. Great programmers 
gyrate to powerful languages and toolboxes. I love I can read the 
source code of Phobos and understand it. I love I get low level 
access to stack variables. I love I can manipulate the heap in 
any way I want. I love we can target GPU and KNL. I love we have 
Maybe even though it is called Nullable...


A great programmer can handle D fine. As it is. Let's not try to 
be the next hype. Let's keep writing great software.


Pj.


Re: How do you safely deal with range.front?

2018-01-01 Thread aliak via Digitalmars-d-learn

On Monday, 1 January 2018 at 04:18:29 UTC, Ali Çehreli wrote:
If you're fine with specifying the function as a template 
argument, the following works. (As seen with 's => s.foo()' 
below, you have to use a lambda for member functions anyway.)


Ali


Nice! Thanks :) And I think your usage for something named 
"ifFront" actually makes more sense than using it to return 
"saferef" functionality.


I've basically implemented an optional type for now and the 
"iffront" implementation looks like this:


import std.range: isInputRange;

auto iffront(Range)(Range r) if (isInputRange!Range) {
import std.range: ElementType, empty, front;
import optional: no, some;
return r.empty ? no!(ElementType!Range) : some(r.front);
}

unittest {
import std.algorithm: filter;
assert([false].filter!"a".iffront.empty); // because optional 
is a range

}

unittest {
import std.algorithm: filter;
import optional: some, none;
struct A {
int f() {
return 7;
}
}

assert([A()].filter!"false".iffront.f == none);
assert([A()].filter!"true".iffront.f == some(7));
}

And thanks everyone for the input. I'll play around with some of 
the ideas and see what comes of it.





Re: What do you want to see for a mature DLang?

2018-01-01 Thread IM via Digitalmars-d

On Sunday, 31 December 2017 at 21:16:35 UTC, Walter Bright wrote:

On 12/31/2017 8:18 AM, IM wrote:

What do you think? Do you agree that a process is needed?


We've tried adding process before. It does not work, for the 
simple reason that it requires a dedicated group of people to 
dedicate time to it.


Something should work. It just needs to be found. People are 
already dedicating time to D by contributing fixes and filing 
issues, responding on the forums, ... etc. Organizing work and 
priorities is not an exception. It doesn't take that long by the 
way, only 30 ~ 60 minutes per week max should be more than 
enough. I hope you could take the upcoming DConf as an 
opportunity to discuss with others ways to enhance the process 
and minimize friction.




Are you willing to do that?



I'd be happy to do it, but I'm not the right person for it. This 
needs someone who knows D very well, knows the bigger picture, 
and is familiar with the contributors and who mostly works on 
what to be able to adjust priorities and ownership appropriately. 
I've been learning and experimenting with D only for a few 
months. Also, I'm worried about - though unlikely - to put myself 
in a conflict-of-interest situation; we don't use D at work, and 
as far as I know there are neither interest nor plans to do so. I 
hope this will change one day, and that's why I started this 
post, because quality and maturity are very important.


We have added process when someone has stepped up to do the 
thankless job of administering it.


I think it is thankful and as important as submitting PRs and 
DIPs. Shaping, organizing, and directing human effort are just as 
important as the human effort itself.





Re: std.file and non-English filename in Windows

2018-01-01 Thread tipdbmp via Digitalmars-d-learn

I think you have to decode your input to UTF-8.

stdin
.byLineCopy(No.keepTerminator)
.each!((string file_name_raw) {

// change Latin1String to the code page of your console;
// use the 'chcp' command to see the current code page of 
your console

//
import std.encoding;
auto raw = cast(immutable( Latin1String)[]) file_name_raw;
string file_name_utf8;
transcode(raw, file_name_utf8);

writefln("%s --> %s", file_name_utf8, file_name_utf8.exists);
});



Does UDA not work for enums?

2018-01-01 Thread Marc via Digitalmars-d-learn

I got compilers errors from this:


enum E {
@("foo")
A,
@("baa")
B
}


I got:


Error: basic type expected, not @
Error: no identifier for declarator _error_
Error: type only allowed if anonymous enum and no enum type
Error: if type, there must be an initializer
Error: found @ when expecting ,

[...]



Re: Does UDA not work for enums?

2018-01-01 Thread Seb via Digitalmars-d-learn

On Monday, 1 January 2018 at 17:15:24 UTC, Marc wrote:

I got compilers errors from this:


enum E {
@("foo")
A,
@("baa")
B
}


I got:


Error: basic type expected, not @
Error: no identifier for declarator _error_
Error: type only allowed if anonymous enum and no enum type
Error: if type, there must be an initializer
Error: found @ when expecting ,

[...]


Vote for and help/improve this DIP: 
https://github.com/dlang/DIPs/pull/105


Re: std.file and non-English filename in Windows

2018-01-01 Thread Domain via Digitalmars-d-learn

On Monday, 1 January 2018 at 16:13:06 UTC, Domain wrote:

On Monday, 1 January 2018 at 12:33:27 UTC, John Chapman wrote:

On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote:
In Windows, exists, rename, copy will report file not exists 
when you input non-English filename, such as Chinese 中文.txt


Works for me. I created a file with the name "中文.txt" and 
std.file.exists returned true.


Is your D source file saved in ASCII by any chance? Try saving 
it with a different encoding, such as UTF8.


Yes, "中文.txt".exists return true. But when then filename read 
from stdin,

it return false

stdin
.byLineCopy(No.keepTerminator)
.each!((a) { writefln("%s --> %s", a, a.exists); });

dir *.txt /b | test.exe

English.txt --> true
中文.txt --> false


Problem solved! I change the properties of cmd from "Raster 
Fonts" to "Consolas" and all work well. But I don't know why.


Re: Help optimizing code?

2018-01-01 Thread Muld via Digitalmars-d-learn

On Monday, 1 January 2018 at 16:47:40 UTC, Adam D. Ruppe wrote:

On Monday, 1 January 2018 at 16:13:37 UTC, Muld wrote:
If you use .ptr then you get zero detection, even in debug 
builds.


It is limited to the one expression where you wrote it, instead 
of on the ENTIRE program like the build switches do.


It is a lot easier to check correctness in an individual 
expression than it is to check the entire program, including 
stuff you didn't even realize might have been a problem.


With the .ptr pattern, it is correct by default and you 
individually change ones you (should) look carefully at. With 
-boundscheck, it is wrong by default and most people don't even 
look at it - people suggest it to newbies as an optimization 
without mentioning how nasty it is.


It won't be just one line though. When you pretty much have to 
use it EVERYWHERE to get the optimization you want. It makes more 
sense to just turn off the check for the entire program and use 
your own asserts() where they are actually needed. That way you 
still get the checks in debug builds and have asserts where they 
are actually necessary.


I'd rather there be a potential bug than the program running 
to slow to be usable


That's a ridiculous exaggeration. In this program, I saw a < 1% 
time difference using those flags. -O -inline make a 50x bigger 
difference!


Read the sentence right before this.. Jesus. People only read 
what they want.



or have zero debugging for indices in debug builds.


You shouldn't be using .ptr until after you've carefully 
checked and debugged the line of code where you are writing it. 
That's the beauty of the pattern: it only affects one line of 
code, so you can test it before you use it without affecting 
the rest of the program.


It won't just be one line, and that's not beautiful. What happens 
when code gets refactored? You are constantly going to be 
flip-flopping the source code rather than a compiler flag or 
using multiple build configurations? How long are you even going 
to test for? The error that might happen for the code is probably 
difficult to detect, if it wasn't then having bounds checking at 
all wouldn't be necessary. Just test your code, that's the beauty 
of testing!




Re: Help optimizing code?

2018-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 1 January 2018 at 16:13:37 UTC, Muld wrote:
If you use .ptr then you get zero detection, even in debug 
builds.


It is limited to the one expression where you wrote it, instead 
of on the ENTIRE program like the build switches do.


It is a lot easier to check correctness in an individual 
expression than it is to check the entire program, including 
stuff you didn't even realize might have been a problem.


With the .ptr pattern, it is correct by default and you 
individually change ones you (should) look carefully at. With 
-boundscheck, it is wrong by default and most people don't even 
look at it - people suggest it to newbies as an optimization 
without mentioning how nasty it is.


I'd rather there be a potential bug than the program running to 
slow to be usable


That's a ridiculous exaggeration. In this program, I saw a < 1% 
time difference using those flags. -O -inline make a 50x bigger 
difference!



or have zero debugging for indices in debug builds.


You shouldn't be using .ptr until after you've carefully checked 
and debugged the line of code where you are writing it. That's 
the beauty of the pattern: it only affects one line of code, so 
you can test it before you use it without affecting the rest of 
the program.


Re: std.file and non-English filename in Windows

2018-01-01 Thread Domain via Digitalmars-d-learn

On Monday, 1 January 2018 at 12:33:27 UTC, John Chapman wrote:

On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote:
In Windows, exists, rename, copy will report file not exists 
when you input non-English filename, such as Chinese 中文.txt


Works for me. I created a file with the name "中文.txt" and 
std.file.exists returned true.


Is your D source file saved in ASCII by any chance? Try saving 
it with a different encoding, such as UTF8.


Yes, "中文.txt".exists return true. But when then filename read 
from stdin,

it return false

stdin
.byLineCopy(No.keepTerminator)
.each!((a) { writefln("%s --> %s", a, a.exists); });

dir *.txt /b | test.exe

English.txt --> true
中文.txt --> false


Re: Help optimizing code?

2018-01-01 Thread Muld via Digitalmars-d-learn

On Monday, 1 January 2018 at 15:54:33 UTC, Adam D. Ruppe wrote:

On Monday, 1 January 2018 at 15:29:28 UTC, user1234 wrote:

dmd mandelbrot.d -O -release -inline -boundscheck=off


-O and -inline are OK, but -release and -boundscheck are 
harmful and shouldn't be used. Yeah, you can squeeze a bit of 
speed out of them, but there's another way to do it - `.ptr` on 
the individual accesses or versioning out unwanted `assert` 
statements - and those avoid major bug and security baggage 
that -release and -boundscheck=off bring.


If you use .ptr then you get zero detection, even in debug builds.

In this program, I didn't see a major improvement with the 
boundscheck skipping... and in this program, it seems to be 
written without the bugs, but still, I am against that switch 
on principle. It is so so so easy to break things with them.


In this program, it's relatively small and doesn't look like it 
does its calculations in realtime. I'd rather there be a 
potential bug than the program running to slow to be usable, or 
have zero debugging for indices in debug builds.







Re: Help optimizing code?

2018-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 1 January 2018 at 15:29:28 UTC, user1234 wrote:

dmd mandelbrot.d -O -release -inline -boundscheck=off


-O and -inline are OK, but -release and -boundscheck are harmful 
and shouldn't be used. Yeah, you can squeeze a bit of speed out 
of them, but there's another way to do it - `.ptr` on the 
individual accesses or versioning out unwanted `assert` 
statements - and those avoid major bug and security baggage that 
-release and -boundscheck=off bring.


In this program, I didn't see a major improvement with the 
boundscheck skipping... and in this program, it seems to be 
written without the bugs, but still, I am against that switch on 
principle. It is so so so easy to break things with them.



- I'd use "double" instead of "real".


On my computer at least, float gave 2x speed compared to double. 
You could try both though and see which works better.


[Issue 18150] dmd segfault on classinfo.create

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18150

Basile B.  changed:

   What|Removed |Added

 CC||b2.t...@gmx.com
   Hardware|x86_64  |All
 OS|Windows |All

--- Comment #1 from Basile B.  ---
It's like "typeid(C).create" except that in this case there's a valid error
message. There's a single static "TypeInfo_Class" by class. "TypeInfo_Class"es
are not designed to be created.

--


Re: Help optimizing code?

2018-01-01 Thread user1234 via Digitalmars-d-learn

On Monday, 1 January 2018 at 15:23:19 UTC, Adam D. Ruppe wrote:

On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote:
I started learning D a few days ago, coming from some very 
basic C++ knowledge, and I'd like some help getting a program 
to run faster.


So a few easy things you can do:

1) use `float` instead of `real`. real sucks, it is really slow 
and weird. Making that one switch doubled the speed on my 
computer.


Yes I've also adviced double. Double is better if the target arch 
is X86_64 since part of the operations will be made with SSE. 
With "real" the OP was **sure** to get 100% of the maths done in 
the FPU (although for all the trigo stuff there's no choice)




2) preallocate the imageData. before the loop, 
`imageData.reserve(width*height*3)`. Small savings on my 
computer but an easy one.


3) make sure you use the compiler optimization options like 
`-O` and `-inline` on dmd (or use the gdc and ldc compilers 
both of which generally optimize better than dmd out of the 
box).



And if that isn't enough we can look into smaller things, but 
these overall brought the time down to about 1/3 what it 
started on my box.





Re: Help optimizing code?

2018-01-01 Thread user1234 via Digitalmars-d-learn

On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote:
I started learning D a few days ago, coming from some very 
basic C++ knowledge, and I'd like some help getting a program 
to run faster. The code is here: 
https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d


Right now it runs slower than my JavaScript Mandelbrot renderer 
on the same quality settings, which is clearly ridiculous, but 
I don't know what to do to fix it. Sorry for the lack of 
comments, but I can never tell what will and won't be obvious 
to other people.


- The first thing is to compile with the best options:

dmd mandelbrot.d -O -release -inline -boundscheck=off

- You append a lot, which can cause reallocs for imageData; Try

   import std.array;
   Appender!(ubyte[]) imageData;

   The code will not have to be changed for "~=" since Appender 
overloads this operator.


- I'd use "double" instead of "real".


[Issue 18150] New: dmd segfault on classinfo.create

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18150

  Issue ID: 18150
   Summary: dmd segfault on classinfo.create
   Product: D
   Version: D2
  Hardware: x86_64
OS: Windows
Status: NEW
  Severity: minor
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: cauter...@gmail.com

tested on DMD32 D Compiler v2.077.1:

class C {}
pragma(msg, C.classinfo.create());

compile -> "object.Error@(0): Access Violation"

--


Re: Help optimizing code?

2018-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote:
I started learning D a few days ago, coming from some very 
basic C++ knowledge, and I'd like some help getting a program 
to run faster.


So a few easy things you can do:

1) use `float` instead of `real`. real sucks, it is really slow 
and weird. Making that one switch doubled the speed on my 
computer.


2) preallocate the imageData. before the loop, 
`imageData.reserve(width*height*3)`. Small savings on my computer 
but an easy one.


3) make sure you use the compiler optimization options like `-O` 
and `-inline` on dmd (or use the gdc and ldc compilers both of 
which generally optimize better than dmd out of the box).



And if that isn't enough we can look into smaller things, but 
these overall brought the time down to about 1/3 what it started 
on my box.


Help optimizing code?

2018-01-01 Thread Lily via Digitalmars-d-learn
I started learning D a few days ago, coming from some very basic 
C++ knowledge, and I'd like some help getting a program to run 
faster. The code is here: 
https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d


Right now it runs slower than my JavaScript Mandelbrot renderer 
on the same quality settings, which is clearly ridiculous, but I 
don't know what to do to fix it. Sorry for the lack of comments, 
but I can never tell what will and won't be obvious to other 
people.


Re: Developing blockchain software with D, not C++

2018-01-01 Thread Ola Fosheim Grøstad via Digitalmars-d

On Monday, 1 January 2018 at 13:34:39 UTC, aberba wrote:
On Monday, 1 January 2018 at 12:24:29 UTC, Ola Fosheim Grøstad 
wrote:
On Monday, 1 January 2018 at 11:24:45 UTC, Ola Fosheim Grøstad 
wrote:

[...]


Btw, I think one should be very sceptical of such 
presentations in general:


[...]


Come on! Ada?


Ada was designed for DoD projects…

https://www.adacore.com/sparkpro




Re: Cannot confirm that a DigitalMars order has been received

2018-01-01 Thread Dennis via Digitalmars-d

On Friday, 24 November 2017 at 22:34:53 UTC, Walter Bright wrote:
It should be in your email inbox by now. I review purchases 
manually, because of occasional attempts to manipulate the 
shopping cart. Sorry about the delay.


I don't like bumping this topic, but I have the same issue. I 
ordered the Extended Utility Package on December 23 2017, got an 
e-mail from Paypal confirming the transaction but nothing else. I 
sent an e-mail to "wgmars7 at domainname" but I have not recieved 
a reply yet. Can you please check the order?


Re: Developing blockchain software with D, not C++

2018-01-01 Thread aberba via Digitalmars-d
On Monday, 1 January 2018 at 12:24:29 UTC, Ola Fosheim Grøstad 
wrote:
On Monday, 1 January 2018 at 11:24:45 UTC, Ola Fosheim Grøstad 
wrote:

[...]


Btw, I think one should be very sceptical of such presentations 
in general:


[...]


Come on! Ada?


Re: Finding unsafe line of code

2018-01-01 Thread Vino via Digitalmars-d-learn

On Friday, 29 December 2017 at 10:33:16 UTC, Johan Engelen wrote:

On Friday, 29 December 2017 at 10:23:24 UTC, codephantom wrote:

On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote:


  Let me re-frame the question with an example, as the Dsafe 
the below line of code is considered as unsafe(Pointer 
arithmetic),

...


ini[10] a;
int* p = [0];
for (size_t i=0; i <= 10; i++)
p[i] = ...;

From,
Vino.B


Is this what you're looking for?

https://dlang.org/spec/function.html#safe-functions

Just annotate your functions with @safe (as @system is the 
default).


Or if that's not possible, you can add runtime checks with 
ASan: 
http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html


-Johan


Hi,

  Tried to install LDC on Windows 7, but getting the below errors 
while compiling


Installed s/w
.Net 4.7.1
.Net Core Runtime 2.0.4
.Net SDK 2.1.3
Windows SDK 10.0.16299.15

Environment Variables Set:

NETFXSDKDir = C:\Program Files (x86)\Windows 
Kits\10\Lib\10.0.16299.0\um\x86(System/User)
LDC_VSDIR = C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Community(System)


Error:
C:\Users\bheev1\Desktop\Current\Script\Complied-64>ldc2 
-fsanitize=address -g nscleaner.d

LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'
Error: C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\HostX64\x64\link.exe failed with status: 1181


From,
Vino.B


Re: D as a betterC a game changer ?

2018-01-01 Thread Russel Winder via Digitalmars-d
On Sun, 2017-12-31 at 17:32 +, Ola Fosheim Grøstad via Digitalmars-
d wrote:
> 
[…]
> I'd love to, but I haven't found the specific paper. She seems to 
> work on many different things related to software design and 
> visual tooling.

I'll email her and get the best start point citation for you.

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk


signature.asc
Description: This is a digitally signed message part


Re: std.file and non-English filename in Windows

2018-01-01 Thread John Chapman via Digitalmars-d-learn

On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote:
In Windows, exists, rename, copy will report file not exists 
when you input non-English filename, such as Chinese 中文.txt


Works for me. I created a file with the name "中文.txt" and 
std.file.exists returned true.


Is your D source file saved in ASCII by any chance? Try saving it 
with a different encoding, such as UTF8.


Re: Developing blockchain software with D, not C++

2018-01-01 Thread Ola Fosheim Grøstad via Digitalmars-d
On Monday, 1 January 2018 at 11:24:45 UTC, Ola Fosheim Grøstad 
wrote:
I am not arguing with their choice, but it was for a C++ 
conference, so obviously they would praise C++…


Btw, I think one should be very sceptical of such presentations 
in general:


1.  They are there to market their project, so they have a strong 
incentive to appeal to the audience.  Offending the audience 
would be a bad strategy.


2.  Developers often have technological preferences in advance 
and will create arguments to defend their choice on rather 
subjective terms using "objective" claims.


3. The design and scope of a project tend to grow in the 
direction that the chosen platform is most suited for.


FWIW, I think the best technical choice for security related 
infrastructure would be to write a library in C or Ada or some 
other toolset where proven verification capabilities are 
available, then tie it together using whatever is most convenient 
on the platform you target.




[Issue 17508] optlink 8.00.17 crash at EIP=0040F60A

2018-01-01 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=17508

computermatro...@gmail.com  changed:

   What|Removed |Added

 CC||computermatro...@gmail.com

--- Comment #1 from computermatro...@gmail.com  ---
Also happens when trying to build seemingly any dub project dependent on vibe.d
0.8.2

--


Re: std.file and non-English filename in Windows

2018-01-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 01, 2018 10:47:51 Patrick Schluter via Digitalmars-d-
learn wrote:
> On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote:
> > In Windows, exists, rename, copy will report file not exists
> > when you input non-English filename, such as Chinese 中文.txt
>
> It's unclear what your problem is but here a wild guess.
>
> Windows API's for Unicode use UTF-16 as far as I know. Strings in
> D are utf-8. So before calling win32 API function, they have to
> be transformed to wstring i.e. utf-16 strings.

std.file abstracts all of that away for you, and it does have at least some
tests that use Unicode characters, though I think that most of the functions
don't have tests that use Unicode characters. I would not have expected a
Unicode bug like this to be in std.file, but it's certainly possible.

It's also possible that the console needs to be set to UTF-8 or UTF-16 or
something, since the default often seems to cause problems for folks -
though unless the file names are coming from the command-line, I wouldn't
have expected that to be an issue. I do almost nothing with Windows though,
so I'm not very familiar with the ins and outs of that mess.

- Jonathan M Davis




Re: Developing blockchain software with D, not C++

2018-01-01 Thread Ola Fosheim Grøstad via Digitalmars-d

On Monday, 1 January 2018 at 10:46:23 UTC, aberba wrote:
On Sunday, 31 December 2017 at 09:45:52 UTC, Ola Fosheim 
Grøstad wrote:

On Saturday, 30 December 2017 at 16:59:41 UTC, aberba wrote:
Besides, D maturity (which I can't confirm or deny), what 
else does D miss to be considered a better alternative for 
blockchain in 2018?


You can write blockchain software in any language you want. 
The reference implementation for OpenChain seems to be written 
in C#.
That's not the point. JavaScript can also be used 
(technically), but you don't want to use it (for their use 
case). Seems you haven't watched the video so you are speaking 
out of context.


Well, the video seems to be mostly about building a large 
key-value store without caching… So whatever language has been 
used for that before would be suitable, basically any language 
that can interface well with C/Posix…


But you want static typing or verification when security is an 
issue, so Javascript is obviously out.


There is is better when you consider things in context. The 
talk was focused on a particular context.


Then you need to be a bit more clear on what you mean. You can 
make a lot of assumptions to shoehorn a project to something 
specific, e.g. database will not fit in main memory, but that 
might not hold if you control the nodes and can afford large 
amounts of memory etc. "Blockchain software" is a very vague 
requirement… What kind of load do you expect, what are the 
real-time requirements (nanoseconds vs minutes).


Remember that even Javascript can run at close to 25-50% of the 
performance of portable C… So it really depends on what you do, 
what architecture you design and what the long term development 
process looks like. Mixing languages is often the better choice 
for many projects.


I am not arguing with their choice, but it was for a C++ 
conference, so obviously they would praise C++…





Re: Slices and Dynamic Arrays

2018-01-01 Thread Seb via Digitalmars-d-learn

On Monday, 1 January 2018 at 02:10:14 UTC, Jonathan M Davis wrote:
On Sunday, December 31, 2017 14:49:40 Tony via 
Digitalmars-d-learn wrote:

On Sunday, 31 December 2017 at 14:24:40 UTC, Jonathan M Davis

wrote:
> [...]

The DLang Tour also uses the term slice to refer to T[].

"The type of arr is int[], which is also called a slice."

"A slice consists of two members - a pointer to the starting 
element and the length of the slice:"


Presumably, because whoever wrote that preferred the 
terminology used in the D Slices article. Regardless, it's not 
wrong to call them slices. It's just less precise, since the 
term slice refers to more than dynamic arrays.


The DLang Tour should probably be fixed to use the term dynamic 
array though.


- Jonathan M Davis


Editing a page is just one click away - there is an edit button 
on the top. Any improvements are always welcome!


Re: Developing blockchain software with D, not C++

2018-01-01 Thread aberba via Digitalmars-d

On Sunday, 31 December 2017 at 10:58:09 UTC, Joakim wrote:

On Saturday, 30 December 2017 at 16:59:41 UTC, aberba wrote:
In this video[1] from 2016, developer talks about C++ memory 
safety features, meta-programming, maturity and few others as 
main reasons they choose it for developing their blockchain 
software (the way I got it from a quick view).


Besides, D maturity (which I can't confirm or deny), what else 
does D miss to be considered a better alternative for 
blockchain in 2018?


D is also more productive, has safety and unittest built-in.


1. https://www.youtube.com/watch?v=w4jq4frE5v4


The better question is whether blockchain is worth implementing 
in D? ;) It wastes a ton of energy with the most common 
proof-of-work approach and, as I've pointed out here before, 
there are better ways to do it:
Maybe, maybe not. Let the developer decide for none of us know 
the future of such technology with certainty.


https://arstechnica.com/tech-policy/2017/12/bitcoins-insane-energy-consumption-explained/
http://forum.dlang.org/post/xzuzvykrqouqlsjmk...@forum.dlang.org

But some decentralized approach, if not blockchain, is 
undoubtedly going to be a huge winner, and of course D would be 
a great language with which to build it.  The lead developer of 
Bitcoin Cash, currently the fourth-most valuable cryptocurrency 
(https://coinmarketcap.com), gave a talk on doing crypto in D 
at the last DConf:


http://dconf.org/2017/talks/sechet.html

That talk was more about cryptography/performance/security IMO. I 
don't recall him talking about blockchain software with D. Seems 
he is in a good position to give such a talk now that 
blockchain/cryptocurrency is getting loud.


I don't think he's using D since they forked the Bitcoin source 
though.





Re: Developing blockchain software with D, not C++

2018-01-01 Thread aberba via Digitalmars-d
On Sunday, 31 December 2017 at 09:45:52 UTC, Ola Fosheim Grøstad 
wrote:

On Saturday, 30 December 2017 at 16:59:41 UTC, aberba wrote:
Besides, D maturity (which I can't confirm or deny), what else 
does D miss to be considered a better alternative for 
blockchain in 2018?


You can write blockchain software in any language you want. The 
reference implementation for OpenChain seems to be written in 
C#.
That's not the point. JavaScript can also be used (technically), 
but you don't want to use it (for their use case). Seems you 
haven't watched the video so you are speaking out of context.

what else does D miss




I don't think "better" in this context is a technical issue, 
more of a cultural one. Well, portability could be an issue.
There is is better when you consider things in context. The talk 
was focused on a particular context.




Re: std.file and non-English filename in Windows

2018-01-01 Thread Patrick Schluter via Digitalmars-d-learn

On Sunday, 31 December 2017 at 18:21:29 UTC, Domain wrote:
In Windows, exists, rename, copy will report file not exists 
when you input non-English filename, such as Chinese 中文.txt


It's unclear what your problem is but here a wild guess.

Windows API's for Unicode use UTF-16 as far as I know. Strings in 
D are utf-8. So before calling win32 API function, they have to 
be transformed to wstring i.e. utf-16 strings.




Re: Maybe D is right about GC after all !

2018-01-01 Thread lobo via Digitalmars-d

On Monday, 1 January 2018 at 05:29:06 UTC, Ali wrote:
On Tuesday, 19 December 2017 at 09:54:05 UTC, Walter Bright 
wrote:

"C, Python, Go, and the Generalized Greenspun Law"

http://esr.ibiblio.org/?p=7804


So .. and this is more of a question, to the maintainers and 
creators of D, what does this mean for D, what is the road map 
for D


- More support for GC free programming or
- More commitment to the GC
- Something else

It would be nice to hear from the creators of D, what is their 
vision for future development and enhancement


https://wiki.dlang.org/Vision/2017H2