Re: Optimize my code =)

2014-02-18 Thread Stanislav Blinov

On Tuesday, 18 February 2014 at 07:50:23 UTC, bearophile wrote:

Stanislav Blinov:


http://dpaste.dzfl.pl/9d7feeab59f6


Few small things should still be improved, but it's an 
improvement. Perhaps it needs to use a reference counting from 
Phobos.


COW for matrices? Aw, come on... :)


LDC yields roughly the same times.


This is surprising.


To me as well. I haven't yet tried to dig deep though.



Re: Question about CPU caches and D context pointers

2014-02-18 Thread Dicebot
None of your buffers are on stack in both examples. As those are 
dynamic arrays you only get pointer + length as value and data 
itself resides on heap in some unknown location. It can be in 
cache too, of course, if it has been used actively, but it can't 
be verified based on this simple snippet.


To get best cache friendliness one may use dynamic-size structs 
akin to C but, of course, this does not go well with necessity to 
grow the buffer dynamically for given instance.


Also note that your first snippet uses ~= operator which will 
cause new heap allocations invalidating any old cache.


Re: Optimize my code =)

2014-02-18 Thread Stanislav Blinov

On Tuesday, 18 February 2014 at 07:45:18 UTC, bearophile wrote:

Stanislav Blinov:


that explicit ctor
for Dimension is completely unnecessary too.


I like a constructor(s) like that because it catches bugs like:

auto d = Dimension(5);


Hmmm... yeah, ok, not completely unnecessary :)


Importing text file, path not found

2014-02-18 Thread Tolga Cakiroglu (tcak)
I am testing with the import expression. I am using the -J flag 
while compiling.


dmd app.d -J/home/user/include


void main(){
	auto test = json.parseJSON( 
import(/home/user/include/test.json) );

}


1. Because I am giving the full path of that file to be imported. 
But compiler is complaining about that it cannot find the file. 
If I remove the path, and leave the file name only, it works. Am 
I doing something wrong, or bug?


2. Why do I need to tell compiler where to look at if I am going 
to tell where the file is already? Shouldn't it be like Hey 
compiler, if you cannot while the file, look at those places, 
and I shouldn't need to use J flag if not necessary?


Re: foreach/iota countdown

2014-02-18 Thread Sergei Nosov

On Tuesday, 18 February 2014 at 05:21:24 UTC, Brian Schott wrote:

On Monday, 17 February 2014 at 19:22:38 UTC, simendsjo wrote:

Should the following two uses be a compile-time error?
 foreach(i; 10 .. 0) // Never executes

 foreach(i; iota(10, 0)) // .. neither does this

I would like the second to either be a compile-time error or 
automagically use a negative step.


So we need to use a negative step in iota() or use a for loop
 foreach(i; iota(10, 0, -1)) // as expected


I just added this check to DScanner:

-
import std.stdio;

void main(string[] args)
{
auto x = args[3 .. 2];
foreach (i; 20 .. 10)
{
}
}
-
/home/alaran/tmp/test.d(5:16)[warn]: 3 is larger than 2. This 
slice is likely incorrect.
/home/alaran/tmp/test.d(6:22)[warn]: 20 is larger than 10. Did 
you mean to use 'foreach_reverse( ... ; 10 .. 20)'?


Isn't foreach_reverse being deprecated?


Re: Importing text file, path not found

2014-02-18 Thread Tolga Cakiroglu (tcak)
On Tuesday, 18 February 2014 at 08:45:16 UTC, Tolga Cakiroglu 
(tcak) wrote:
I am testing with the import expression. I am using the -J 
flag while compiling.


dmd app.d -J/home/user/include


void main(){
	auto test = json.parseJSON( 
import(/home/user/include/test.json) );

}


1. Because I am giving the full path of that file to be 
imported. But compiler is complaining about that it cannot find 
the file. If I remove the path, and leave the file name only, 
it works. Am I doing something wrong, or bug?


2. Why do I need to tell compiler where to look at if I am 
going to tell where the file is already? Shouldn't it be like 
Hey compiler, if you cannot while the file, look at those 
places, and I shouldn't need to use J flag if not necessary?


- Grammar issues -

1. Because I am giving the full path of that file to be
imported, compiler is complaining about that it cannot find
the file. If I remove the path, and leave the file name only,
it works. Am I doing something wrong, or bug?

2. Why do I need to tell compiler where to look at if I am
going to tell where the file is already? Shouldn't it be like
Hey compiler, if you cannot find the file, look at those
places, and I shouldn't need to use J flag if not necessary?


Re: Optimize my code =)

2014-02-18 Thread bearophile

Stanislav Blinov:


allocationTest ...
Time required: 1 sec, 112 ms, 827 μs, and 3 hnsecs
multiplicationTest ...
Time required: 1 sec, 234 ms, 417 μs, and 8 hnsecs


Physics teaches us that those experimental measures are expressed 
with a excessive precision. For such benchmarks it's more wise to 
write 1.11 seconds.


Bye,
bearophile


Re: Optimize my code =)

2014-02-18 Thread bearophile

Stanislav Blinov:


LDC yields roughly the same times.


This is surprising.


To me as well. I haven't yet tried to dig deep though.


I have compiled your code with (a single module, 32 bit Windows):

dmd -wi -vcolumns -O -release -inline -noboundscheck matrix3.d
ldmd2 -wi -O -release -inline -noboundscheck matrix3.d

DMD:

multiplicationTest ...
Time required: 4 secs, 665 ms, 452 ╬╝s, and 2 hnsecs

LDC2:

multiplicationTest ...
Time required: 2 secs, 522 ms, and 747 ╬╝s

Bye,
bearophile


Re: Optimize my code =)

2014-02-18 Thread Stanislav Blinov

On Tuesday, 18 February 2014 at 08:50:23 UTC, bearophile wrote:

Stanislav Blinov:


LDC yields roughly the same times.


This is surprising.


To me as well. I haven't yet tried to dig deep though.


I have compiled your code with (a single module, 32 bit 
Windows):


dmd -wi -vcolumns -O -release -inline -noboundscheck matrix3.d
ldmd2 -wi -O -release -inline -noboundscheck matrix3.d

DMD:

multiplicationTest ...
Time required: 4 secs, 665 ms, 452 ╬╝s, and 2 hnsecs

LDC2:

multiplicationTest ...
Time required: 2 secs, 522 ms, and 747 ╬╝s


Interesting. For me (on 64 bit) multiplicationTest is in the same 
league for DMD and LDC. (I'm still using dmd 2.064.2 as my main 
dmd install btw).


But what is up with those first and last tests in LDC?..

$ rdmd -wi -O -release -inline -noboundscheck main.d
allocationTest ...
Time required: 1 sec, 165 ms, 766 μs, and 1 hnsec
multiplicationTest ...
Time required: 1 sec, 232 ms, 287 μs, and 4 hnsecs
toStringTest ...
Time required: 997 ms, 217 μs, and 1 hnsec
transposeTest ...
Time required: 859 ms, 152 μs, and 5 hnsecs
scalarMultiplicationTest ...
Time required: 105 ms, 366 μs, and 5 hnsecs
matrixAddSubTest ...
Time required: 241 ms, 705 μs, and 8 hnsecs
matrixEqualsTest ...
Time required: 243 ms, 534 μs, and 8 hnsecs
identityMatrixTest ...
Time required: 260 ms, 411 μs, and 4 hnsec

$ ldmd2 -wi -O -release -inline -noboundscheck main.d 
neolab/core/dimension.d neolab/core/matrix.d -ofmain-ldc  
main-ldc


allocationTest ...
Time required: 2 hnsecs (o_O)
multiplicationTest ...
Time required: 1 sec, 138 ms, 628 μs, and 2 hnsecs
toStringTest ...
Time required: 704 ms, 937 μs, and 5 hnsecs
transposeTest ...
Time required: 859 ms, 413 μs, and 5 hnsecs
scalarMultiplicationTest ...
Time required: 103 ms, 250 μs, and 2 hnsecs
matrixAddSubTest ...
Time required: 226 ms, 955 μs, and 3 hnsecs
matrixEqualsTest ...
Time required: 470 ms and 186 μs
identityMatrixTest ...
Time required: 4 hnsecs (o_O)


Re: Importing text file, path not found

2014-02-18 Thread bearophile

Tolga Cakiroglu (tcak):


1. Because I am giving the full path of that file to be
imported, compiler is complaining about that it cannot find
the file. If I remove the path, and leave the file name only,
it works. Am I doing something wrong, or bug?

2. Why do I need to tell compiler where to look at if I am
going to tell where the file is already? Shouldn't it be like
Hey compiler, if you cannot find the file, look at those
places, and I shouldn't need to use J flag if not necessary?


It seems things are working as designed.

The J flag is meant for security.

Bye,
bearophile


Re: Importing text file, path not found

2014-02-18 Thread Dicebot
On Tuesday, 18 February 2014 at 08:45:16 UTC, Tolga Cakiroglu 
(tcak) wrote:
1. Because I am giving the full path of that file to be 
imported. But compiler is complaining about that it cannot find 
the file. If I remove the path, and leave the file name only, 
it works. Am I doing something wrong, or bug?


2. Why do I need to tell compiler where to look at if I am 
going to tell where the file is already? Shouldn't it be like 
Hey compiler, if you cannot while the file, look at those 
places, and I shouldn't need to use J flag if not necessary?


It is a matter of security I think. By restricting imports to 
only explicitly allowed locations and prohibiting fully-qualified 
paths dmd guarantees you that compiled program won't access 
anything outside of that sandbox. That way compilation process 
stays relatively safe.


Re: std.range.equal or == in isPalindrome

2014-02-18 Thread bearophile

Per Nordlöw:


Why isn't equality == operator used here instead?


In some cases I'd even like to use ~ instead of chain().

Bye,
bearophile


Re: std.range.equal or == in isPalindrome

2014-02-18 Thread Stanislav Blinov

On Tuesday, 18 February 2014 at 09:31:55 UTC, Per Nordlöw wrote:

I'm curious to why we need std.range.equal in cases such as

bool isPalindrome(Range)(in Range range) if 
(isBidirectionalRange!Range)

{
return range.retro.equal(range);
}

Why isn't equality == operator used here instead?

/Per


1) opEquals cannot be a free function
2) there's no telling what opEquals does if Range defines it

IOW, equal() has a defined by-element-comparison semantics, while 
opEquals doesn't.


Re: std.range.equal or == in isPalindrome

2014-02-18 Thread Stanislav Blinov

On Tuesday, 18 February 2014 at 09:34:41 UTC, bearophile wrote:


In some cases I'd even like to use ~ instead of chain().


Range interface should be minimal. Don't forget that user types 
can provide range interface and still benefit from operator 
overloading for different purposes.


Interface file is generated wrong

2014-02-18 Thread Tolga Cakiroglu (tcak)

I have written a module as below:

file: lib.d

import core.sys.posix.dlfcn;

private static this(){}

private static ~this(){}

public shared class Apps{
}


---

This code is compiled with -H flag to generate an interface 
file. Generated interface file is below:



file: lib.di

// D import file generated from 'lib.d'
import core.sys.posix.dlfcn;
private static this();

private
public shared class Apps
{
}

---

Compiler is adding a redundant private keyword before the 
class, and static destructor function is not there any more. Thus 
compiler is giving Redundant protection attribute error.


Bug? (I don't know if I should immediately file a bug when I 
think it is a bug without asking what other people thinks.)


Re: Importing text file, path not found

2014-02-18 Thread Tolga Cakiroglu

On Tuesday, 18 February 2014 at 09:24:50 UTC, Dicebot wrote:
On Tuesday, 18 February 2014 at 08:45:16 UTC, Tolga Cakiroglu 
(tcak) wrote:
1. Because I am giving the full path of that file to be 
imported. But compiler is complaining about that it cannot 
find the file. If I remove the path, and leave the file name 
only, it works. Am I doing something wrong, or bug?


2. Why do I need to tell compiler where to look at if I am 
going to tell where the file is already? Shouldn't it be like 
Hey compiler, if you cannot while the file, look at those 
places, and I shouldn't need to use J flag if not necessary?


It is a matter of security I think. By restricting imports to 
only explicitly allowed locations and prohibiting 
fully-qualified paths dmd guarantees you that compiled program 
won't access anything outside of that sandbox. That way 
compilation process stays relatively safe.


Hmm. Should I understand the sandbox as if I am going to be 
compiling someone else's code, only looking at -J flags will be 
enough to make sure it is not using any of my private files?


Re: Interface file is generated wrong

2014-02-18 Thread Stanislav Blinov
On Tuesday, 18 February 2014 at 10:07:37 UTC, Tolga Cakiroglu 
(tcak) wrote:



Bug?


Yup.

(I don't know if I should immediately file a bug when I think 
it is a bug without asking what other people thinks.)


1) Do a seach in bugzilla
2) If the search doesn't show anything similar, file it
3) If it's not a bug, it'll be closed as such

That's it :)


Re: Importing text file, path not found

2014-02-18 Thread Dicebot
On Tuesday, 18 February 2014 at 10:10:14 UTC, Tolga Cakiroglu 
wrote:
Hmm. Should I understand the sandbox as if I am going to be 
compiling someone else's code, only looking at -J flags will be 
enough to make sure it is not using any of my private files?


It is the intention. I can't guarantee there are no bugs that 
break that assumption though :)


Re: Optimize my code =)

2014-02-18 Thread Stanislav Blinov
...And if I define opEquals as it was made by Robin, i.e. like 
this:



bool opEquals(ref const Matrix other) const pure nothrow {
version (all) {
if (dim != other.dim) return false;
foreach(immutable i, const ref e; data)
if (e != other.data[i])
return false;
return true;
} else {
return (dim == other.dim)  (data[] == other.data[]);
}
}


then the relevant benchmark on LDC flattens near zero time too x.x


Re: foreach/iota countdown

2014-02-18 Thread Ivan Kazmenko
/home/alaran/tmp/test.d(5:16)[warn]: 3 is larger than 2. This 
slice is likely incorrect.
/home/alaran/tmp/test.d(6:22)[warn]: 20 is larger than 10. Did 
you mean to use 'foreach_reverse( ... ; 10 .. 20)'?


Isn't foreach_reverse being deprecated?


Oh.  If so, what would be the right way to iterate backwards?  
The usual for (*;*;*) is too repetitive and error-prone: 
nothing is going to catch some for (int i = 19; i = 10; j--) 
errors or the like.  Using ranges, such as iota and retro, 
currently results in a *massive* slowdown for DMD.


As a crude proof for the last statement, below are my local 
timings for DMD 2.064.2 on Win32 using dmd -O -release -inline 
-noboundscheck to compile.


Example 1 (0.38 sec):
void main () {foreach (i; 0..1_000_000_000) {}}

Example 2 (0.39 sec):
void main () {for (int i = 0; i  1_000_000_000; i++) {}}

Example 3 (2.03 sec):
import std.range;
void main () {foreach (i; iota (1_000_000_000)) {}}

Unless simple things like example 3 run on par with the first 
two, foreach on ranges - or, in that regard, UFCS 
functional-style range chains without even a foreach - are just 
plain unacceptable in bottlenecks.  LDC is able to handle simple 
cases like this, but introducing a compiler dependency just 
because of this?  That would also be unfortunate.


Ivan Kazmenko.


Re: foreach/iota countdown

2014-02-18 Thread bearophile

Sergei Nosov:


Isn't foreach_reverse being deprecated?


The idea was discussed a little, but it's not deprecated, and 
probably it will not be deprecated.


Bye,
bearophile


Re: Interface file is generated wrong

2014-02-18 Thread Tolga Cakiroglu
On Tuesday, 18 February 2014 at 10:15:51 UTC, Stanislav Blinov 
wrote:
On Tuesday, 18 February 2014 at 10:07:37 UTC, Tolga Cakiroglu 
(tcak) wrote:



Bug?


Yup.

(I don't know if I should immediately file a bug when I think 
it is a bug without asking what other people thinks.)


1) Do a seach in bugzilla
2) If the search doesn't show anything similar, file it
3) If it's not a bug, it'll be closed as such

That's it :)


Thanks. Well, by putting that destructor to the end of lib.d, dmd 
has ended with segmentation error.


dmd -c lib.d -H -fPIC -release -inline
gcc --shared lib.o -o lib.so
dmd app.d -L-ldl -release -O -inline
lib.di(83): Error: declaration expected following attribute, not 
EOF

make: *** [app] Segmentation fault (core dumped)


It looks like a big bug.


Re: std.range.equal or == in isPalindrome

2014-02-18 Thread bearophile

Stanislav Blinov:


Range interface should be minimal.


I agree. But I didn't mean to ask for that operator in the Range 
protocol. I think some ranges should define a ~ operator. It's 
easy to write a chainable trait. I did that for my nonstandard 
D1 library.


Bye,
bearophile


Re: 64 bit size_t

2014-02-18 Thread Steve Teale
Rather than change it to int/ulong, just change it to 'size_t 
len = parent.children.length+1' (or auto instead of size_t). 
This way it's proper for both 32-bit and 64-bit and you don't 
need to worry about architecture. If you do need a signed 
version, you can use ptrdiff_t.


Yup, that's what I did when my head returned to its usual postion 
;=)





Re: std.range.equal or == in isPalindrome

2014-02-18 Thread Per Nordlöw

On Tuesday, 18 February 2014 at 10:47:33 UTC, bearophile wrote:

Stanislav Blinov:


Range interface should be minimal.


I agree. But I didn't mean to ask for that operator in the 
Range protocol. I think some ranges should define a ~ operator. 
It's easy to write a chainable trait. I did that for my 
nonstandard D1 library.


Bye,
bearophile


Could you post the isChainable trait?

I'm curious :)

/Per


Re: std.range.equal or == in isPalindrome

2014-02-18 Thread Per Nordlöw

On Tuesday, 18 February 2014 at 11:39:12 UTC, Per Nordlöw wrote:

On Tuesday, 18 February 2014 at 10:47:33 UTC, bearophile wrote:

Stanislav Blinov:


Range interface should be minimal.


I agree. But I didn't mean to ask for that operator in the 
Range protocol. I think some ranges should define a ~ 
operator. It's easy to write a chainable trait. I did that 
for my nonstandard D1 library.


Bye,
bearophile


Could you post the isChainable trait?

I'm curious :)

/Per


Ahh, I guess you mean

http://forum.dlang.org/thread/bug-604...@http.d.puremagic.com%2Fissues%2F

/Per


[video tutorial] Refactoring the number guessing game

2014-02-18 Thread simendsjo

http://youtu.be/yhK7zvnWmiU


Re: [video tutorial] Implementing a simple number guessing game

2014-02-18 Thread John Colvin

On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote:

On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote:

http://youtu.be/2Co65Ftxfdo


Thanks! But could you use bigger fonts and more contrast color 
scheme for better view in next videos?


I'll increase the font size, but I think  30 lines on the 
screen would be too big (it's almost there in that video).


The contrast is another issue.. I have tweaked urxvt, tmux and 
vim in order to get these colors. Trying to change just the 
colorscheme in vim doesn't give the expected results I'm afraid.


You could always just alter the contrast/color-balance in the 
video.


Re: [video tutorial] Implementing a simple number guessing game

2014-02-18 Thread Mengu

On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote:

http://youtu.be/2Co65Ftxfdo


did i mention i loved your tutorials? keep up the great work.


Re: [video tutorial] Implementing a simple number guessing game

2014-02-18 Thread simendsjo

On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin wrote:

On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote:

On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote:

http://youtu.be/2Co65Ftxfdo


Thanks! But could you use bigger fonts and more contrast 
color scheme for better view in next videos?


I'll increase the font size, but I think  30 lines on the 
screen would be too big (it's almost there in that video).


The contrast is another issue.. I have tweaked urxvt, tmux and 
vim in order to get these colors. Trying to change just the 
colorscheme in vim doesn't give the expected results I'm 
afraid.


You could always just alter the contrast/color-balance in the 
video.


I've never done any video editing, so I have no idea how.
I tried pressing around on the YouTube enhance video settings, 
but it looks like an LSD trip no matter what I do.


Re: [video tutorial] Implementing a simple number guessing game

2014-02-18 Thread simendsjo

On Tuesday, 18 February 2014 at 13:46:11 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin wrote:

On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote:

On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo wrote:

http://youtu.be/2Co65Ftxfdo


Thanks! But could you use bigger fonts and more contrast 
color scheme for better view in next videos?


I'll increase the font size, but I think  30 lines on the 
screen would be too big (it's almost there in that video).


The contrast is another issue.. I have tweaked urxvt, tmux 
and vim in order to get these colors. Trying to change just 
the colorscheme in vim doesn't give the expected results I'm 
afraid.


You could always just alter the contrast/color-balance in the 
video.


I've never done any video editing, so I have no idea how.
I tried pressing around on the YouTube enhance video settings, 
but it looks like an LSD trip no matter what I do.


But is the contrast really that bad? I find my settings easy on 
the eyes. Clown colors makes me dizzy.


Re: [video tutorial] Implementing a simple number guessing game

2014-02-18 Thread John Colvin

On Tuesday, 18 February 2014 at 13:47:22 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 13:46:11 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin 
wrote:

On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote:
On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo 
wrote:

http://youtu.be/2Co65Ftxfdo


Thanks! But could you use bigger fonts and more contrast 
color scheme for better view in next videos?


I'll increase the font size, but I think  30 lines on the 
screen would be too big (it's almost there in that video).


The contrast is another issue.. I have tweaked urxvt, tmux 
and vim in order to get these colors. Trying to change just 
the colorscheme in vim doesn't give the expected results I'm 
afraid.


You could always just alter the contrast/color-balance in the 
video.


I've never done any video editing, so I have no idea how.
I tried pressing around on the YouTube enhance video settings, 
but it looks like an LSD trip no matter what I do.


But is the contrast really that bad? I find my settings easy on 
the eyes. Clown colors makes me dizzy.


It's fine in my opinion, but it's a matter of taste.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread Rikki Cattermole

On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote:

http://youtu.be/yhK7zvnWmiU


Would you be interested in doing a Lets make series on 
ApplyYourDLang? As this falls under this heading.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread simendsjo
On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote:

http://youtu.be/yhK7zvnWmiU


Would you be interested in doing a Lets make series on 
ApplyYourDLang? As this falls under this heading.


Combining efforts is always good, but I'm not sure if creating 
video tutorials can keep my interest for very long.


It also sounds like you have plans to make this a lot more 
professional: planning content and editing videos. I just press 
record and upload :/


Re: [video tutorial] Implementing a simple number guessing game

2014-02-18 Thread simendsjo

On Tuesday, 18 February 2014 at 14:04:50 UTC, John Colvin wrote:

On Tuesday, 18 February 2014 at 13:47:22 UTC, simendsjo wrote:

On Tuesday, 18 February 2014 at 13:46:11 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 13:39:38 UTC, John Colvin 
wrote:
On Tuesday, 18 February 2014 at 07:19:05 UTC, simendsjo 
wrote:

On Tuesday, 18 February 2014 at 07:06:11 UTC, Suliman wrote:
On Monday, 17 February 2014 at 13:35:34 UTC, simendsjo 
wrote:

http://youtu.be/2Co65Ftxfdo


Thanks! But could you use bigger fonts and more contrast 
color scheme for better view in next videos?


I'll increase the font size, but I think  30 lines on the 
screen would be too big (it's almost there in that video).


The contrast is another issue.. I have tweaked urxvt, tmux 
and vim in order to get these colors. Trying to change just 
the colorscheme in vim doesn't give the expected results 
I'm afraid.


You could always just alter the contrast/color-balance in 
the video.


I've never done any video editing, so I have no idea how.
I tried pressing around on the YouTube enhance video 
settings, but it looks like an LSD trip no matter what I do.


But is the contrast really that bad? I find my settings easy 
on the eyes. Clown colors makes me dizzy.


It's fine in my opinion, but it's a matter of taste.


I'll leave it as-is. If more people complain, I'll google around 
and try to fix them.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread Rikki Cattermole

On Tuesday, 18 February 2014 at 14:19:47 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote:

http://youtu.be/yhK7zvnWmiU


Would you be interested in doing a Lets make series on 
ApplyYourDLang? As this falls under this heading.


Combining efforts is always good, but I'm not sure if creating 
video tutorials can keep my interest for very long.


It also sounds like you have plans to make this a lot more 
professional: planning content and editing videos. I just press 
record and upload :/


Don't worry about that. We can sort out making things higher 
quality as series goes :)


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread simendsjo
On Tuesday, 18 February 2014 at 14:20:44 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 14:19:47 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo wrote:

http://youtu.be/yhK7zvnWmiU


Would you be interested in doing a Lets make series on 
ApplyYourDLang? As this falls under this heading.


Combining efforts is always good, but I'm not sure if creating 
video tutorials can keep my interest for very long.


It also sounds like you have plans to make this a lot more 
professional: planning content and editing videos. I just 
press record and upload :/


Don't worry about that. We can sort out making things higher 
quality as series goes :)


Have you written a plan/schedule for the videos somewhere?
And I cannot see a way to move the videos to other users in 
YouTube.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread Rikki Cattermole

On Tuesday, 18 February 2014 at 14:25:33 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:20:44 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 14:19:47 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki 
Cattermole wrote:
On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo 
wrote:

http://youtu.be/yhK7zvnWmiU


Would you be interested in doing a Lets make series on 
ApplyYourDLang? As this falls under this heading.


Combining efforts is always good, but I'm not sure if 
creating video tutorials can keep my interest for very long.


It also sounds like you have plans to make this a lot more 
professional: planning content and editing videos. I just 
press record and upload :/


Don't worry about that. We can sort out making things higher 
quality as series goes :)


Have you written a plan/schedule for the videos somewhere?
And I cannot see a way to move the videos to other users in 
YouTube.


I haven't yet made a plan. Its mostly in my head at the current 
point in time. However we can do something, perhaps on a repo.


You don't need to move them. You can add any video to a playlist, 
given a url.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread simendsjo

On Tuesday, 18 February 2014 at 14:36:17 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:27:19 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 14:25:33 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:20:44 UTC, Rikki 
Cattermole wrote:
On Tuesday, 18 February 2014 at 14:19:47 UTC, simendsjo 
wrote:
On Tuesday, 18 February 2014 at 14:16:27 UTC, Rikki 
Cattermole wrote:
On Tuesday, 18 February 2014 at 13:00:09 UTC, simendsjo 
wrote:

http://youtu.be/yhK7zvnWmiU


Would you be interested in doing a Lets make series on 
ApplyYourDLang? As this falls under this heading.


Combining efforts is always good, but I'm not sure if 
creating video tutorials can keep my interest for very long.


It also sounds like you have plans to make this a lot more 
professional: planning content and editing videos. I just 
press record and upload :/


Don't worry about that. We can sort out making things higher 
quality as series goes :)


Have you written a plan/schedule for the videos somewhere?
And I cannot see a way to move the videos to other users in 
YouTube.


I haven't yet made a plan. Its mostly in my head at the 
current point in time. However we can do something, perhaps on 
a repo.


You don't need to move them. You can add any video to a 
playlist, given a url.


I'll be more than happy to place the videos elsewhere, but I 
don't want to commit to a large ongoing project as I'm pretty 
busy with school too.

Posting your ideas somewhere would be nice though.

I've posted the code so far on bitbucket, but moving to another 
repo (github?) and changing links in the videos is trivial if 
you think my videos would fit your playlist - even though 
they're nothing more than live coding videos :)


Oh, and I thought of making perhaps 3 more videos: std.getopt, 
splitting a project into subprojects with dub, and another vibe.d 
demo. All just as extensions to the simple number guessing game.

We'll see if I ever get this far.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread Rikki Cattermole

On Tuesday, 18 February 2014 at 14:36:17 UTC, simendsjo wrote:
I'll be more than happy to place the videos elsewhere, but I 
don't want to commit to a large ongoing project as I'm pretty 
busy with school too.

Posting your ideas somewhere would be nice though.


What I was thinking was, for a smaller set of projects grouped 
together. In one series. This way you're not committed.


I've posted the code so far on bitbucket, but moving to another 
repo (github?) and changing links in the videos is trivial if 
you think my videos would fit your playlist - even though 
they're nothing more than live coding videos :)


Seeing how others develop while learning is a very important 
thing while learning. So yes it very much fits.


I've sent you an invite to manage it. You'll be able to do e.g. 
upload video or add playlists ext. As well as work on the Google+ 
page [0].


[0] https://plus.google.com/u/0/b/115883286620259563734/


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread simendsjo
On Tuesday, 18 February 2014 at 14:42:22 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 14:36:17 UTC, simendsjo wrote:
I'll be more than happy to place the videos elsewhere, but I 
don't want to commit to a large ongoing project as I'm pretty 
busy with school too.

Posting your ideas somewhere would be nice though.


What I was thinking was, for a smaller set of projects grouped 
together. In one series. This way you're not committed.


I've posted the code so far on bitbucket, but moving to 
another repo (github?) and changing links in the videos is 
trivial if you think my videos would fit your playlist - even 
though they're nothing more than live coding videos :)


Seeing how others develop while learning is a very important 
thing while learning. So yes it very much fits.


I've sent you an invite to manage it. You'll be able to do e.g. 
upload video or add playlists ext. As well as work on the 
Google+ page [0].


[0] https://plus.google.com/u/0/b/115883286620259563734/


Not sure I'm able to connect.. When pressing the link, it turns 
up for my G+ user. If I log in as the YouTube user and go to that 
link, I still turn up as the G+ user. Why on earth won't Google 
let me merge the accounts?...


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread Rikki Cattermole

On Tuesday, 18 February 2014 at 14:48:53 UTC, simendsjo wrote:
Not sure I'm able to connect.. When pressing the link, it turns 
up for my G+ user. If I log in as the YouTube user and go to 
that link, I still turn up as the G+ user. Why on earth won't 
Google let me merge the accounts?...


I don't know.
But you do need to accept the manager invite. I sent it to the 
one you subscribed to the channel as. From there you can switch 
to it if you want.


Re: Interface file is generated wrong

2014-02-18 Thread Steven Schveighoffer

On Tue, 18 Feb 2014 05:47:41 -0500, Tolga Cakiroglu t...@pcak.com wrote:


On Tuesday, 18 February 2014 at 10:15:51 UTC, Stanislav Blinov wrote:
On Tuesday, 18 February 2014 at 10:07:37 UTC, Tolga Cakiroglu (tcak)  
wrote:



Bug?


Yup.

(I don't know if I should immediately file a bug when I think it is a  
bug without asking what other people thinks.)


1) Do a seach in bugzilla
2) If the search doesn't show anything similar, file it
3) If it's not a bug, it'll be closed as such

That's it :)


Thanks. Well, by putting that destructor to the end of lib.d, dmd has  
ended with segmentation error.


dmd -c lib.d -H -fPIC -release -inline
gcc --shared lib.o -o lib.so
dmd app.d -L-ldl -release -O -inline
lib.di(83): Error: declaration expected following attribute, not EOF
make: *** [app] Segmentation fault (core dumped)


It looks like a big bug.


Please mark said bug with the tag ice. This marks it as a bug which  
crashes the compiler, and it will get a higher priority.


-Steve


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread simendsjo
On Tuesday, 18 February 2014 at 14:51:28 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 14:48:53 UTC, simendsjo wrote:
Not sure I'm able to connect.. When pressing the link, it 
turns up for my G+ user. If I log in as the YouTube user and 
go to that link, I still turn up as the G+ user. Why on earth 
won't Google let me merge the accounts?...


I don't know.
But you do need to accept the manager invite. I sent it to the 
one you subscribed to the channel as. From there you can switch 
to it if you want.


Ah, I'm in. You'll have to dictate what to do next. Maybe we 
should continue this by mail? My gmail is simendsjo.


Re: [video tutorial] Refactoring the number guessing game

2014-02-18 Thread Rikki Cattermole

On Tuesday, 18 February 2014 at 15:14:09 UTC, simendsjo wrote:
On Tuesday, 18 February 2014 at 14:51:28 UTC, Rikki Cattermole 
wrote:

On Tuesday, 18 February 2014 at 14:48:53 UTC, simendsjo wrote:
Not sure I'm able to connect.. When pressing the link, it 
turns up for my G+ user. If I log in as the YouTube user and 
go to that link, I still turn up as the G+ user. Why on earth 
won't Google let me merge the accounts?...


I don't know.
But you do need to accept the manager invite. I sent it to the 
one you subscribed to the channel as. From there you can 
switch to it if you want.


Ah, I'm in. You'll have to dictate what to do next. Maybe we 
should continue this by mail? My gmail is simendsjo.


Just sent you a message via hangouts on G+. Will be easier as its 
IM.

If anybody wants to join in, give us a yell.


Re: Optimize my code =)

2014-02-18 Thread Kapps

On Tuesday, 18 February 2014 at 09:05:33 UTC, Stanislav Blinov
wrote:


allocationTest ...
Time required: 2 hnsecs (o_O)
identityMatrixTest ...
Time required: 4 hnsecs (o_O)


LDC is probably detecting that you're never actually using the
results of the operation and that none of the steps have
side-effects, so it's optimizing the call out. One way of
avoiding this is to do something like writeln the result of an
operation.


Re: std.range.chunk without length

2014-02-18 Thread Stephan Schiffels
On Thursday, 13 February 2014 at 17:41:37 UTC, monarch_dodra 
wrote:

On Thursday, 13 February 2014 at 14:45:44 UTC, bearophile wrote:

Stephan Schiffels:

It would be actually easy to implement chunks without the 
save function, by using an internal buffer, which would 
however make this algorithm's memory burden linear in the 
chunk size. Would that be acceptable?


I think it's acceptable. But perhaps you need to add one more 
optional argument for the buffer :-)


Bye,
bearophile


Users andralex:
https://github.com/D-Programming-Language/phobos/pull/1186

And quickfur:
https://github.com/D-Programming-Language/phobos/pull/1453

Have submitted different algorithms for a similar problem: 
Basically, bu being 2-dimensional lazy (each subrange is 
itself a lazy range). However, both come with their own 
pitfalls.


Andrei's still requires forward ranges. quickfur's doesn't, 
and, arguably, has a simpler design. However, if I remember 
correctly, it is also less efficient (it does double work). 
Implementing Quickfur's solution in Chunks for input ranges 
only could be a good idea.


It *is* extra work, more code, more code to cover (that is 
difficult to cover). I'm not sure we have the man power to 
support such complexity: I was able to make chunks work with 
forward ranges, but I still haven't even fixed Splitter yet! I 
think that should take precedence.


Yeah, nevermind, I won't do it. I realised that you had good 
reasons to require a ForwardRange. Chunking really needs some 
sort of save implemented. And what I had in mind to make it 
work on File.byLine with a buffer is actually a hack that 
effectively adds save functionality to the InputRange… so I 
agree it's logically not reasonable to do it here.


Thanks anyway.
Stephan


Re: Interface file is generated wrong

2014-02-18 Thread Tolga Cakiroglu
On Tuesday, 18 February 2014 at 15:02:38 UTC, Steven 
Schveighoffer wrote:
On Tue, 18 Feb 2014 05:47:41 -0500, Tolga Cakiroglu 
t...@pcak.com wrote:


On Tuesday, 18 February 2014 at 10:15:51 UTC, Stanislav Blinov 
wrote:
On Tuesday, 18 February 2014 at 10:07:37 UTC, Tolga Cakiroglu 
(tcak) wrote:



Bug?


Yup.

(I don't know if I should immediately file a bug when I 
think it is a bug without asking what other people thinks.)


1) Do a seach in bugzilla
2) If the search doesn't show anything similar, file it
3) If it's not a bug, it'll be closed as such

That's it :)


Thanks. Well, by putting that destructor to the end of lib.d, 
dmd has ended with segmentation error.


dmd -c lib.d -H -fPIC -release -inline
gcc --shared lib.o -o lib.so
dmd app.d -L-ldl -release -O -inline
lib.di(83): Error: declaration expected following attribute, 
not EOF

make: *** [app] Segmentation fault (core dumped)


It looks like a big bug.


Please mark said bug with the tag ice. This marks it as a bug 
which crashes the compiler, and it will get a higher priority.


-Steve


Okay. Done.

Issue 12192 - Wrong interface file content generated that crashes 
compiler


trace GC work

2014-02-18 Thread Ruslan Mullakhmetov


Hi,

Is it possible to trace GC allocation calls to determine times of 
program death and have some stats?


So i want the following information:
  - garbage collection starts at {time}
  - garbage collection stops at {time}
  - (optionally) gc took {time}, collected {size} bytes

thanks.


Re: Question about CPU caches and D context pointers

2014-02-18 Thread Casper Færgemand

On Tuesday, 18 February 2014 at 08:11:04 UTC, Dicebot wrote:
None of your buffers are on stack in both examples. As those 
are dynamic arrays you only get pointer + length as value and 
data itself resides on heap in some unknown location.


That.

struct S {}
class C {}

S[] s1; // fat pointer to an array of structs
S[2] s2; // array of two structs, plus a length?

C[] c1; // fat pointer to an array of pointers
C[2] c2; // array of two pointers, plus a length?


I tested some prime sieves both in C++ and D. They worked fastest 
with dynamic arrays with a size matching the L1 cache. I presume 
the instructions are located elsewhere in the CPU.


Re: Question about CPU caches and D context pointers

2014-02-18 Thread Dicebot
On Tuesday, 18 February 2014 at 18:13:24 UTC, Casper Færgemand 
wrote:

S[2] s2; // array of two structs, plus a length?


Storing length is not needed for static arrays because it is 
known, well, statically.


I tested some prime sieves both in C++ and D. They worked 
fastest with dynamic arrays with a size matching the L1 cache. 
I presume the instructions are located elsewhere in the CPU.


Yes, instruction cache is completely separated from data cache.


What learning resources are available?

2014-02-18 Thread Mark Isaacson
Hi everyone - I'm a D newbie with a very strong C++ background 
looking to get started. I've read The D Programming Language a 
couple of times now, but I've heard rumblings at several points 
in time from several people that some if its contents are now out 
of date or no longer reflect best practices.


What would be the best way to bridge the learning gap between 
TDPL's publication and now?


What other resources would be most useful in establishing a 
working knowledge of idiomatic D?


What's the best way to stay informed about such changes in the 
future? (Is there a mailing list, or should I just be reading dmd 
changelogs?)


Thanks in advance!


Re: What learning resources are available?

2014-02-18 Thread simendsjo

On Tuesday, 18 February 2014 at 19:17:55 UTC, Mark Isaacson wrote:
Hi everyone - I'm a D newbie with a very strong C++ background 
looking to get started. I've read The D Programming Language 
a couple of times now, but I've heard rumblings at several 
points in time from several people that some if its contents 
are now out of date or no longer reflect best practices.


What would be the best way to bridge the learning gap between 
TDPL's publication and now?


What other resources would be most useful in establishing a 
working knowledge of idiomatic D?


What's the best way to stay informed about such changes in the 
future? (Is there a mailing list, or should I just be reading 
dmd changelogs?)


Thanks in advance!


I can just speak for myself, but I've been learning D by 
following the newsgroups and reading the phobos and druntime 
code. Not sure if there are quicker ways to get up to date.




Re: What learning resources are available?

2014-02-18 Thread H. S. Teoh
On Tue, Feb 18, 2014 at 07:17:53PM +, Mark Isaacson wrote:
 Hi everyone - I'm a D newbie with a very strong C++ background
 looking to get started. I've read The D Programming Language a
 couple of times now, but I've heard rumblings at several points in
 time from several people that some if its contents are now out of
 date or no longer reflect best practices.

I would say that most of TDPL is still applicable today. The parts that
are out-of-date are mostly confined to the more advanced features. There
has been some new syntax added since, but they have mostly been
syntactic sugar, not fundamental changes, so you should notice very few
discrepancies there.

Another great resource is Ali Cehreli's introductory book to D:

http://ddili.org/ders/d.en/

It takes a different approach from TDPL, and is more recent, so you may
find it helpful.


 What would be the best way to bridge the learning gap between TDPL's
 publication and now?

Honestly, there's not that much of a gap. I'd wager at least 80% (if not
more) of TDPL is still relevant today.


 What other resources would be most useful in establishing a working
 knowledge of idiomatic D?

Read Phobos source code, perhaps? :)  I'm quite serious, actually.
Phobos source code is actually very readable as far as standard
libraries go (compared to, say, glibc, which is not only an eyesore but
will give you a headache for weeks). I've found it a pleasure to read,
for the most part.  (There are some dark corners in Phobos code, but you
don't have to go there to pick up the latest D practices!)


 What's the best way to stay informed about such changes in the
 future? (Is there a mailing list, or should I just be reading dmd
 changelogs?)
[...]

This forum should keep you pretty up-to-date. ;-)


T

-- 
One disk to rule them all, One disk to find them. One disk to bring them
all and in the darkness grind them. In the Land of Redmond where the
shadows lie. -- The Silicon Valley Tarot


Re: Question about CPU caches and D context pointers

2014-02-18 Thread Etienne

On 2014-02-18 1:13 PM, Casper Færgemand shortt...@hotmail.com wrote:

On Tuesday, 18 February 2014 at 08:11:04 UTC, Dicebot wrote:
I tested some prime sieves both in C++ and D. They worked fastest with
dynamic arrays with a size matching the L1 cache. I presume the
instructions are located elsewhere in the CPU.


Does that mean ubyte[] = new ubyte[4092] is more likely to end up in the 
CPU cache than ubyte[4092] or the inverse ?


Re: Question about CPU caches and D context pointers

2014-02-18 Thread Dicebot

On Tuesday, 18 February 2014 at 19:55:20 UTC, Etienne wrote:
On 2014-02-18 1:13 PM, Casper Færgemand 
shortt...@hotmail.com wrote:

On Tuesday, 18 February 2014 at 08:11:04 UTC, Dicebot wrote:
I tested some prime sieves both in C++ and D. They worked 
fastest with

dynamic arrays with a size matching the L1 cache. I presume the
instructions are located elsewhere in the CPU.


Does that mean ubyte[] = new ubyte[4092] is more likely to end 
up in the CPU cache than ubyte[4092] or the inverse ?


It is irrelevant. If data is used continiously it will end up in 
cache anyway (assuming it fits), location does not matter. What 
is important is if it is already prefetched upon first access, 
which is more likely for static arrays as they reside in the same 
memory page as their aggregator. Then it will save you from cache 
miss upon changing the buffer context frequently.


But if you use the same buffer all the time during continious 
code flow it shouldn't impact where exactly it is located as it 
simply won't be removed from cache by newer data.


Re: What learning resources are available?

2014-02-18 Thread John Colvin

On Tuesday, 18 February 2014 at 19:17:55 UTC, Mark Isaacson wrote:
Hi everyone - I'm a D newbie with a very strong C++ background 
looking to get started. I've read The D Programming Language 
a couple of times now, but I've heard rumblings at several 
points in time from several people that some if its contents 
are now out of date or no longer reflect best practices.


What would be the best way to bridge the learning gap between 
TDPL's publication and now?


What other resources would be most useful in establishing a 
working knowledge of idiomatic D?


What's the best way to stay informed about such changes in the 
future? (Is there a mailing list, or should I just be reading 
dmd changelogs?)


Thanks in advance!


Combining other posts with my opinion of each item:

A combination of:

TDPL: overview of the language with justifications, should be 
very well targeted for an experienced C++ programmer


http://ddili.org/ders/d.en/ for a few more up to date details and 
good basic introductions to anything you get confused by.


Phobos code: Judicious use of the power of D. Not all good, but 
if you look at the more frequently updated modules you should get 
a nice picture.


http://rosettacode.org/wiki/Category:D for lots of D solutions to 
common problems etc. Mostly by bearophile (I think?), stretching 
the limits of terse range-based D code.


Re: trace GC work

2014-02-18 Thread Ali Çehreli

On 02/18/2014 10:10 AM, Ruslan Mullakhmetov wrote:


Hi,

Is it possible to trace GC allocation calls to determine times of
program death and have some stats?

So i want the following information:
   - garbage collection starts at {time}
   - garbage collection stops at {time}
   - (optionally) gc took {time}, collected {size} bytes

thanks.


I may be totally off but I vaguely remember that it is possible to plug 
in one's own garbage collector. It should be possible to write a garbage 
collector that collects some statistics before calling back the default 
GC functions.


Ali



Re: What learning resources are available?

2014-02-18 Thread Tobias Pankrath

On Tuesday, 18 February 2014 at 19:17:55 UTC, Mark Isaacson wrote:
Hi everyone - I'm a D newbie with a very strong C++ background 
looking to get started. I've read The D Programming Language 
a couple of times now, but I've heard rumblings at several 
points in time from several people that some if its contents 
are now out of date or no longer reflect best practices.


What would be the best way to bridge the learning gap between 
TDPL's publication and now?


What other resources would be most useful in establishing a 
working knowledge of idiomatic D?


What's the best way to stay informed about such changes in the 
future? (Is there a mailing list, or should I just be reading 
dmd changelogs?)


Thanks in advance!


This one is quite cool: 
https://github.com/PhilippeSigaud/D-templates-tutorial


Cannot get frame pointer to sort

2014-02-18 Thread Tobias Pankrath

--
struct Set(alias less = a  b, T)
{
import std.algorithm;
import std.functional;
alias lessFun = binaryFun!(less);

int[] someContents;
this(R)(R r)
{
sort!(lessFun)(someContents);
}
}

unittest {
auto as2 = Set!((x,y) = x  y , int)([2, 1, 3]);
}
-- http://dpaste.dzfl.pl/af6cb1a8d8ab

It works, if I provide a normal function or a string lambda as 
'less'. However the code above results in the following error:


/d923/f233.d(11): Error: constructor 
f233.__unittestL15_3.Set!((x, y) = x  y, 
int).Set.__ctor!(int[]).this cannot get frame pointer to sort


What's wrong?


Re: trace GC work

2014-02-18 Thread Mike
On Tuesday, 18 February 2014 at 18:10:40 UTC, Ruslan Mullakhmetov 
wrote:


Hi,

Is it possible to trace GC allocation calls to determine times 
of program death and have some stats?


So i want the following information:
  - garbage collection starts at {time}
  - garbage collection stops at {time}
  - (optionally) gc took {time}, collected {size} bytes

thanks.


I believe you'll have to modify the runtime to achieve this.  See 
the gc folder[1]. An example of a custom garbage collector is 
in the gcstub folder[2].


Mike


[1] 
https://github.com/D-Programming-Language/druntime/tree/e47a00bff935c3f079bb567a6ec97663ba384487/src/gc
[2] 
https://github.com/D-Programming-Language/druntime/blob/e47a00bff935c3f079bb567a6ec97663ba384487/src/gcstub/gc.d


Re: Cannot get frame pointer to sort

2014-02-18 Thread Stanislav Blinov
On Tuesday, 18 February 2014 at 22:28:08 UTC, Tobias Pankrath 
wrote:



What's wrong?


This looks like a bug to me, seeing as string predicate works. 
Although I don't get how you supply default template parameter 
for Set before explicit one :)


Re: Optimize my code =)

2014-02-18 Thread Robin

Hiho,

I am happy to see that I could encourage so many people to 
discuss about this topic to not only give me interesting answer 
to my questions but also to analyse and evaluate features and 
performance of D.


I have fixed the allocation performance problem via a custom 
destructor method which manually notifies the GC that its data is 
garbage so that the GC can free it in the next cycle and no 
longer have to determine if it is no longer used. This extremely 
speeded up the allocation tests but increased overall runtime 
performance by a very slight amount of time because memory is now 
freed contigeously.


@Nick Sabalausky:
Why should I remove .dub from the copy constructor? In my opinion 
this is important to keep both matrices (source and copy) 
independent from each other. The suggested COW feature for 
matrices sound interesting but also weird. I have to read more 
about that.
Move semantics in D a needed and existing, however, I think that 
the D compiler isn't as good as the C++ compiler in determining 
what is moveable and what not.


Another thing which is hopefully a bug in the current language 
implementation of D is the strange behaviour of the transpose 
method with the only line of code:


return Matrix(this).transposeAssign();

In C++ for example this compiles without any problems and results 
in correct transposed matrix copies - this works due to the 
existance of move semantics in C++ and is one of the coolest 
features since C++11 which increased and simplified codes in many 
cases enormously for value types just as structs in D.


I have ran several tests in order to test when the move assign or 
the move constructors are called in D and whenever I expected 
them to be called the copy-constructor or the postblit was called 
instead which was frustating imo.
Perhaps I still haven't quite understood the things behind the 
scenes in D but it can't be the solution to always copy the whole 
data whenever I could instead have a move of the whole data on 
the heap.


Besides that on suggestion which came up was that I could insert 
the Dimension module into the Matrix module as their are 
semantically working together. However, I find it better to have 
many smaller code snippets instead of fewer bigger ones and 
that's why I keep them both separated.


I also gave scoped imports a try and hoped that they were able to 
reduce my executable file and perhaps increase the performance of 
my program, none of which was true - confused. Instead I now 
have more lines of code and do not see instantly what 
dependencies the module as itself has. So what is the point in 
scoped imports?


The mixin keyword is also nice to have but it feels similar to a 
dirty C-macro to me where text replacement with lower abstraction 
(unlike templates) takes place. Of course I am wrong and you will 
teach me why but atm I have strange feelings about implementing 
codes with mixins. In this special case: perhaps it isn't a wise 
decision to merge addition with subtraction and perhaps I can 
find faster ways to do that which invole more differences in both 
actions which requires to split both methods up again. 
(theoretical, but it could be)


Another weird thing is that the result ~= text(tabStr, this[r, 
c]) in the toString method is much slower than the two following 
lines of code:


result ~= tabStr;
result ~= to!string(this[r, c]);

Does anybody have an answer to this?

I am now thinking that I know the most important things about how 
to write ordinary (not super) efficient D code - laugh at me if 
you want :D - and will continue extending this benchmarking 
library and whenever I feel bad about a certain algorithm's 
performance I will knock here in this thread again, you know. :P


In the end of my post I just want to summarize the benchmark 
history for the matrix multiplication as I think that it is 
funny: (All tests for two 1000x1000 matrices!)


- The bloody first implementation of the matrix implementation 
(which worked) required about 39 seconds to finish.
- Then I have finally found out the optimizing commands for the 
DMD and the multiplication performance double roughly to about 14 
seconds.
- I created an account here and due to your massive help the 
matrix multiplication required only about 5 seconds shortly after 
due to better const, pure and nothrow usage.
- Through the shift from class to struct and some optimizations 
in memory layout and further usage improvements of const, pure 
and nothrow as well as several array feature usages and foreach 
loop the algorithm performance raised once again and required 
about 3,7 seconds.
- The last notifiable optimization was the implemenatation based 
on pointer arithmentics which again improved the performance from 
3,7 seconds to roughly about 2 seconds.


Due to this development I see that there is still a possibility 
that we could beat the 1,5 seconds from Java or even the 1,3 
seconds from C++! (based on my machine: 64bit-archlinux, 

UDA initialize a user defined type attribute field

2014-02-18 Thread Arjan

When a user defined type is used as an attribute like this:
// the attribute
struct MyAttrib
{
immutable string name;
imuttable int sz;
immutable string defaultvalue;
}

// using the attribute
class Data
{
// field 'id' has attribute MyAttrib with name and sz set to 
'fancy name'

// and 10 resp.
@MyAttrib( fancy name, 10 )
long id;
...
}


But how do I only set the MyAttrib.defaultvalue?

class OtherData
{
//@MyAttrib( ??defaultvalue = null ?? )
//@MyAttrib( string.init, int.init, null ) //seems to work?
long id;
...
}

MyAttrib instances may be initialized like this:

auto myattrib = { defaultvalue:null };

But this seems not possible when using MyAttrib as attribute.


Re: UDA initialize a user defined type attribute field

2014-02-18 Thread Adam D. Ruppe

On Tuesday, 18 February 2014 at 23:43:56 UTC, Arjan wrote:

But how do I only set the MyAttrib.defaultvalue?


You could do it by adding a constructor to MyAttrib that only 
takes one string and fills it in that way.


Re: Optimize my code =)

2014-02-18 Thread bearophile

Robin:

the existance of move semantics in C++ and is one of the 
coolest features since C++11 which increased and simplified 
codes in many cases enormously for value types just as structs 
in D.


I guess Andrei doesn't agree with you (and move semantics in 
C++11 is quite hard to understand).



I also gave scoped imports a try and hoped that they were able 
to reduce my executable file and perhaps increase the 
performance of my program, none of which was true - confused. 
Instead I now have more lines of code and do not see instantly 
what dependencies the module as itself has. So what is the 
point in scoped imports?


Scoped imports in general can't increase performance. Their main 
point is to avoid importing modules that are needed only by 
templated code. So if you don't instantiate the template, the 
liker works less and the binary is usually smaller (no 
moduleinfo, etc).



Another weird thing is that the result ~= text(tabStr, this[r, 
c]) in the toString method is much slower than the two 
following lines of code:


result ~= tabStr;
result ~= to!string(this[r, c]);

Does anybody have an answer to this?


It doesn't look too much weird. In the first case you are 
allocating and creating larger strings. But I don't think matrix 
printing is a bottleneck in a program.



- Then I have finally found out the optimizing commands for the 
DMD


This is a small but common problem. Perhaps worth fixing.


There are still many ways to further improve the performance. 
For examply by using LDC


Latest stable and unstable versions of LDC2, try it:
https://github.com/ldc-developers/ldc/releases/tag/v0.12.1
https://github.com/ldc-developers/ldc/releases/tag/v0.13.0-alpha1


on certain hardwares, paralellism and perhaps by implementing 
COW with no GC dependencies. And of course I may miss many 
other possible optimization features of D.


Matrix multiplication can be improved a lot tiling the matrix (or 
better using a cache oblivious algorithm), using SSE/AVX2, using 
multiple cores, etc. As starting point you can try to use 
std.parallelism. It could speed up your code on 4 cores with a 
very limited amount of added code.


Bye,
bearophile


Re: UDA initialize a user defined type attribute field

2014-02-18 Thread Arjan

On Tuesday, 18 February 2014 at 23:46:28 UTC, Adam D. Ruppe wrote:

On Tuesday, 18 February 2014 at 23:43:56 UTC, Arjan wrote:

But how do I only set the MyAttrib.defaultvalue?


You could do it by adding a constructor to MyAttrib that only 
takes one string and fills it in that way.


But what happens than when only the first field 'name' is used in 
MyAttrib like this:


class OtherData
{
@MyAttrib( fancy name )
long id;
...
}

I guess the field MyAttrib.defaultvalue will be assigned the 
value fancy name?




Re: UDA initialize a user defined type attribute field

2014-02-18 Thread bearophile

Arjan:


MyAttrib instances may be initialized like this:

auto myattrib = { defaultvalue:null };

But this seems not possible when using MyAttrib as attribute.


This could become a D enhancement request.


I guess the field MyAttrib.defaultvalue will be assigned the 
value fancy name?


Unfortunately D doesn't have named arguments.

You can use chains, returning this from some methods:

MyAttrib().setName(Foo).setSz(10).setDefaultValue(Bar)

Bye,
bearophile


Re: UDA initialize a user defined type attribute field

2014-02-18 Thread Ali Çehreli

On 02/18/2014 03:43 PM, Arjan wrote:

When a user defined type is used as an attribute like this:
// the attribute
struct MyAttrib
{
 immutable string name;
 imuttable int sz;
 immutable string defaultvalue;
}

// using the attribute
class Data
{
 // field 'id' has attribute MyAttrib with name and sz set to 'fancy
name'
 // and 10 resp.
 @MyAttrib( fancy name, 10 )
 long id;
 ...
}


But how do I only set the MyAttrib.defaultvalue?

class OtherData
{
 //@MyAttrib( ??defaultvalue = null ?? )
 //@MyAttrib( string.init, int.init, null ) //seems to work?
 long id;
 ...
}

MyAttrib instances may be initialized like this:

auto myattrib = { defaultvalue:null };

But this seems not possible when using MyAttrib as attribute.


This problem has nothing to do with UDAs and can be solved similar to 
regular cases, e.g. by using a factory function:


// the attribute
struct MyAttrib
{
immutable string name;
immutable int sz;
immutable string defaultvalue;
}

MyAttrib makeMyAttribWithDefaultValue(string defaultValue)
{
return MyAttrib(MyAttrib.name.init, MyAttrib.sz.init, defaultValue);
}

// using the attribute
class Data
{
// field 'id' has attribute MyAttrib with name and sz set to 'fancy 
name'

// and 10 resp.
@MyAttrib( fancy name, 10 )
long id;

@makeMyAttribWithDefaultValue(hello)
int i;
}

void main()
{
pragma(msg, __traits(getAttributes, Data.id));
pragma(msg, __traits(getAttributes, Data.i));
}

Ali





Re: Optimize my code =)

2014-02-18 Thread Stanislav Blinov

On Tuesday, 18 February 2014 at 23:36:12 UTC, Robin wrote:

Another thing which is hopefully a bug in the current language 
implementation of D is the strange behaviour of the transpose 
method with the only line of code:


return Matrix(this).transposeAssign();


Matrix(this) not compiling when 'this' is const is a bug. That's 
why I had to replace it with assignment. Postblit still has some 
unresolved problems.


However, you should note that you have a bigger bug in that 
transposeAssign() returns a reference :) So unless transpose() 
returns Matrix (instead of ref Matrix), that's a problem.


In C++ for example this compiles without any problems and 
results in correct transposed matrix copies - this works due to 
the existance of move semantics in C++ and is one of the 
coolest features since C++11 which increased and simplified 
codes in many cases enormously for value types just as structs 
in D.


The fact that it compiles in C++ is a problem (this illustrates 
your initial implementation of transpose() translated into C++):


struct Matrix
{
// ref Matrix transpose() const;
S transpose() const { return 
Matrix(*this).transposeAssign(); }


// ref Matrix transposeAssign();
S transposeAssign() { return *this; }
};

int main(int argc, char** argv)
{
Matrix m1;
Matrix m2 = m1.transpose(); // ooops!
}

I have ran several tests in order to test when the move assign 
or the move constructors are called in D and whenever I 
expected them to be called the copy-constructor or the postblit 
was called instead which was frustating imo.


I've posted a complete illustration on how D moves rvalues, 
browse this thread back a bit.


I also gave scoped imports a try and hoped that they were able 
to reduce my executable file and perhaps increase the 
performance of my program, none of which was true - confused. 
Instead I now have more lines of code and do not see instantly 
what dependencies the module as itself has. So what is the 
point in scoped imports?


They don't pollute outer scope with symbols. If you just need to 
call a couple of functions from std.random inside *one* function, 
there's no need to pull names from std.random into the whole 
module.


The mixin keyword is also nice to have but it feels similar to 
a dirty C-macro to me where text replacement with lower 
abstraction (unlike templates) takes place. Of course I am wrong


Yes you are :) It's not dirty and it's certainly not a macro. 
It's a great feature for generating code at compile time. For 
examples just browse through Phobos (e.g. std.functional), or 
take a look at the code in this thread:


http://forum.dlang.org/thread/mailman.158.1391156715.13884.digitalmar...@puremagic.com

Maybe it's your syntax highlighting that throws you off? Then use 
q{} insead of  :)


Another weird thing is that the result ~= text(tabStr, this[r, 
c]) in the toString method is much slower than the two 
following lines of code:


result ~= tabStr;
result ~= to!string(this[r, c]);

Does anybody have an answer to this?


Probably due to extra allocation in text(tabStr, this[r,c]) since 
it will perform ~ under the hood, while appender already has 
storage.