Re: Solution to problems:

2015-03-26 Thread ketmar via Digitalmars-d
On Wed, 25 Mar 2015 03:30:17 +, Jake The Baker wrote:

> Lets suppose if 30 coders that come to this forum were on board. Suppose
> one year was spend developing such an app that make it very effective to
> not only develop in D but also help develop D. Suppose it was just a
> super awesome and efficient IDE that solved all the programmers
> problems.

and the only problem with that IDE is that nobody uses it. 'cause people 
comes with their habits, and they used to their existing environments. so 
that brilliant IDE is a wasted time, 'cause it will never have a big 
userbase.

signature.asc
Description: PGP signature


Re: Solution to problems:

2015-03-26 Thread ketmar via Digitalmars-d
On Wed, 25 Mar 2015 16:56:32 +, Jake The Baker wrote:

> Do *you know what progress is?

one important part of "progress" is not wasting time on useless things.

signature.asc
Description: PGP signature


Re: Solution to problems:

2015-03-26 Thread rumbu via Digitalmars-d

On Tuesday, 24 March 2015 at 17:44:55 UTC, CraigDillabaugh wrote:



Just curious to know which major open source programming 
languages support the sort of development environment you are 
suggesting for their core language/libraries.  I just checked 
Python (the most popular Open Source language of all)  and they 
use ./config make  and hg for version control .. seems pretty 
bare bones to me.




https://github.com/dotnet





Re: [Phobos] You're crippled by your orthodoxism

2015-03-26 Thread bearophile via Digitalmars-d

Jean pierre:

This is a problem, you, the D core has: you're crippled by your 
orthodoxism.

Nothing will be added because of this:  **rules**.


The current level of acceptance of Phobos patches seems roughly 
correct to me.


Bye,
bearophile


Unittests and windows application

2015-03-26 Thread Stefan via Digitalmars-d
I am currently porting a D1 application to D2. I am trying to 
take advantage of new language features but mostly of the "new" 
standard library features.
The old application has several unit tests and I would like to 
have them executed to secure that everything works as expected.


The problem with the unit tests is that they will be executed but 
I can not see the results because errors will be written to 
console output which is not available in a windows application.


I did a little bit of research and found this two similar threads:
- 
http://stackoverflow.com/questions/27580107/why-is-unit-testing-not-working-in-this-d-program
- 
http://forum.dlang.org/thread/joiglupanlvejarms...@forum.dlang.org


But they just explain why that does not work.
Interestingly enough, the hint in the first thread to use the 
standard D main method instead of a WinMain 
(http://wiki.dlang.org/D_for_Win32) works for me. I just specify 
a *.def with SUBSYSTEM WINDOWS.


Class runtime.d seems to contain the code that performs the unit 
tests: bool runModuleUnitTests()
Runtime has a @property moduleUnitTester which can be set to a 
function that runs the unit test of a given module. If this is 
property is set it will be used otherwise a default test runner 
will be executed. This default test runner will report any error 
with the internal function void printErr(in char[] buf).


The question is where should the error output go in a windows 
application. Possible solutions maybe:

- write that to file similar to the code coverage *.lst
- write it to windows debug view with win32: void 
OutputDebugStringA( LPCTSTR lpOutputString )


I will try set the modultUnitTester property and use 
OutputDebugView. Although, not very nice because a lot of code 
has to be copied.


Are there any other options?


Re: Unittests and windows application

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d

On Thursday, 26 March 2015 at 10:23:58 UTC, Stefan wrote:
I am currently porting a D1 application to D2. I am trying to 
take advantage of new language features but mostly of the "new" 
standard library features.
The old application has several unit tests and I would like to 
have them executed to secure that everything works as expected.


The problem with the unit tests is that they will be executed 
but I can not see the results because errors will be written to 
console output which is not available in a windows application.


That's a bug. You'll notice that if an exception is thrown in 
main() (or anything called from it), you'll get a MessageBox for 
GUI applications. That this doesn't also occur with unittest 
failures is a bug.


For now, you can work around this by writing your own WinMain, 
which calls rt_runModuleUnitTests explicitly, inside a try/catch 
block which will then display a MessageBox.


Feature idea: scope (failure, ExceptionSpecification) for catching exceptions

2015-03-26 Thread Andrej Mitrovic via Digitalmars-d
One idea I'd like to see is to enhance scope(failure) to allow it to
catch a specific type of exception which would allow us to e.g. log
the exception message and potentially re-throw the exception. All of
this without having to nest our code in try/catch statements.

So instead of having code such as the following:

-
void test ( )
{
try
{
prepare();
foo();
finish();

try
{
prepare();
bar();
finish();
}
catch (MyException ex)
{
logger.log("bar() failed with: " ~ ex.msg);
throw ex;
}
}
catch (MyException ex)
{
logger.log("foo() failed with: " ~ ex.msg);
throw ex;
}
}
-

-
void test ( )
{
scope (failure, MyException ex)
{
logger.log("foo() failed with: " ~ ex.msg);
throw ex;
}

prepare();
foo();
finish();

scope (failure, MyException ex)
{
logger.log("bar() failed with: " ~ ex.msg);
throw ex;
}

prepare();
bar();
finish();
}
-

Granted it's not the best example out there, but I think it has
potential. Thoughts?


Re: Unittests and windows application

2015-03-26 Thread Stefan via Digitalmars-d
On Thursday, 26 March 2015 at 10:50:06 UTC, Vladimir Panteleev 
wrote:

On Thursday, 26 March 2015 at 10:23:58 UTC, Stefan wrote:

..


That's a bug. You'll notice that if an exception is thrown in 
main() (or anything called from it), you'll get a MessageBox 
for GUI applications. That this doesn't also occur with 
unittest failures is a bug.


Do you have the bug/issue number for that?



For now, you can work around this by writing your own WinMain, 
which calls rt_runModuleUnitTests explicitly, inside a 
try/catch block which will then display a MessageBox.


Hmm, that is what i tried to do, but the code in 
Runtime.runModuleUnitTests() catches already all exceptions and 
writes that to the console.
I have not found rt_runModuleUnitTests in the current D runtime 
(2.067.0).


However, I was successful in setting the moduleUnitTester 
property of Runtime. Inside my main module I do:


static this()  {
Runtime.moduleUnitTester = &unitTestRunner;
}
bool unitTestRunner() {

string line = "";

void printErr(in char[] buf) {
string message = to!string(buf);
if ( message == "\n" ) {
Logger.send( line );
line = "";
} else {
line ~= message;
}
}

size_t failed = 0;
foreach( m; ModuleInfo ) {
if( m ) {
auto fp = m.unitTest;

if( fp ) {
try {
fp();
} catch( Throwable e ) {
e.toString(&printErr); printErr("\n");
failed++;
}
}
}
}
return failed == 0;
}

where the Logger.send() delegates to OutputDebugStringA().


Re: Did D will try to get the vulkan opportunity?

2015-03-26 Thread ZombineDev via Digitalmars-d

On Wednesday, 25 March 2015 at 18:46:51 UTC, bioinfornatics wrote:

Dear,

I would like to know if D dev have a plan with vulkan : 
https://www.khronos.org/vulkan/ ?


D lang will be at same level than others language, nothing 
exists !


D could try to provide API and an environment around vulkan. To 
become a language  "need to be used" in this field.


Regards


I'm very excited about the movement in the graphics API space to 
provide a better abstraction over the modern GPUs.
I was planning to make a Mantle binding when the SDK was to be 
released (because it would be at least 90% the same as Vulkan, 
minus the SPIR-V), and I also wanted to get my hands dirty 
earlier), but unfortunately AMD announced that they will be 
releasing only the spec.


Well they've now released[1] the spec and I couldn't resist 
reading it.
I was very (pleasantly) surprised with how little AMD specific 
stuff it has in it. Actually it is divided into core Mantle and 
AMD extentions and the core part is pretty generic because it has 
to support different GPUs, different OSes and different driver 
versions. For example you need to query the API at runtime for 
the size of the objects, their alignment requirements, their 
preferred placement in one of the (possibly several) memory heaps 
and so on. At the initialization of the API you can provide your 
custom allocation and deallocation functions.


Since it is pure C API the obvious things that a D binding can do 
better are:

+ use slices were the API expects a pointer and size
+ functions like grGetObjectInfo[2] can be templated on the 
GR_INFO_TYPE enum, so you won't have to manually provide the 
value of pDataSize and and the D binding will automatically 
assert/enforce that pDataSize bytes has been written.

+ various other CTFE automation of the quite verbose C API.
+ overall the API is UFCS friendly - for example [3] can be 
written in D as [4].
+ the one thing that can be potentially higher impact is to able 
to compile D code to SPIR-V (maybe doable via CTFE DSL, but it 
probably better if we can use the LLVM or GCC backends). There is 
a C++14 subset that you can use in OpenCl 2.1 C++. We can do 
probably something similar with D.


The moment a working Vulkan SDK is released I will try to make a 
D binding. I expect that other people from the D community are 
also interested in this, so you can sure there will be at least a 
DerelictVulkan ;)



[1]: 
http://www.amd.com/en-us/innovations/software-technologies/technologies-gaming/mantle#downloads


[2]: GR_RESULT grGetObjectInfo(
GR_BASE_OBJECT object,
GR_ENUM infoType,
GR_SIZE* pDataSize,
GR_VOID* pData);

[3]:
// This is C code
#include //mantle or vulkan

result = grCreateCommandBuffer(device, &cmdBufInfo, &cmdBuffer);

// Start building command buffer, optimize fo single time 
submittion

result = grBeginCommandBuffer(
  cmdBuffer,
  GR_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT);

// Record command buffer commands
grCmdSetEvent(cmdBuffer, event);

// Finish recording
grEndCommandBuffer(cmdBuffer);


[4]:
// This is D code
import gr; // this our Mantle or Vulkan wrapper module

// Return a new CmdBuffer instance by value, since it is 
(probably)

// not much larger than a handle.
// Pass a CmdBufInfo by ref, or expand the members
// of the struct as parameters to
// device "method" (in semi-OOP terminology).
// The wrapper function asserts that the GR_RESULT is GR_SUCCESS
// since it is probably a logic error that we have provided
// invalid arguments, and we are not Go fanboys obsessed with
// checking error codes :-D
auto cmdBuffer = device.createCommandBuffer(cmdBufInfo);

// The rest is UFCS + scope statement + style
// changes (to make it more friendly-looking).
{
cmdBuffer.beginRecording(CmdBufUsage.oneTimeSubmit);
scope(exit) cmdBuffer.endRecording();

cmdBuffer.setEvent(event);
}



Linkage runaround

2015-03-26 Thread Steve Teale via Digitalmars-d
If I link my DMD 2.066.1/ GtkD (latest version) app with static 
Phobos2 I get


Linking executable: ../bin/Debug/compo
../objdir/mainwin.o: In function 
`_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
/usr/include/dmd/druntime/import/core/runtime.d:233: undefined 
reference to `rt_loadLibrary'

collect2: ld returned 1 exit status

If I change the link spec to use libphobos2.so, then the app 
links, and runs, but it crashes the first time I try to read 
something from a file with stream.File.readString.


Does this ring a bell with anyone.


Re: Linkage runaround

2015-03-26 Thread Steven Schveighoffer via Digitalmars-d

On 3/26/15 8:37 AM, Steve Teale wrote:

If I link my DMD 2.066.1/ GtkD (latest version) app with static Phobos2
I get

Linking executable: ../bin/Debug/compo
.../objdir/mainwin.o: In function
`_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
/usr/include/dmd/druntime/import/core/runtime.d:233: undefined reference
to `rt_loadLibrary'
collect2: ld returned 1 exit status

If I change the link spec to use libphobos2.so, then the app links, and
runs, but it crashes the first time I try to read something from a file
with stream.File.readString.

Does this ring a bell with anyone.


It looks like you are missing a required library. Are you linking with 
ld? If so, make sure you run dmd with -v to see the link line it uses.


-Steve


Re: Unittests and windows application

2015-03-26 Thread Kagamin via Digitalmars-d

Maybe, it's possible to redirect output explicitly?
myapp.exe >output.txt 2>errors.txt


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Jesse Phillips via Digitalmars-d
On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu 
wrote:

On 12/16/13 12:38 PM, Andrei Alexandrescu wrote:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
{
return v >= lo && v <= hi;
}

uint among(T, Us...)(T v, Us vals)
{
foreach (i, U; Us)
{
if (v == vals[i]) return i + 1;
}
return 0;
}

Add?


Looks like among() has proven its worth since we introduced it. 
Now I somehow forgot between() didn't make it, and reviewed 
some code at work assuming it exists! Here's the original and 
proposed in a couple of snippets:


return (path.asPath.logicalLength() <= asPathLengths_[1] &&
path.asPath.logicalLength() >= asPathLengths_[0]);

=>

return path.asPath.logicalLength.between(asPathLengths_[0], 
asPathLengths_[1]);




if (prefix.prefixLen > prefixLenRange_[1] ||
prefix.prefixLen < prefixLenRange_[0]) {

=>

if (!prefix.prefixLen.between(prefixLenRange_[0], 
prefixLenRange_[1])) {




Well?


Andrei


I think it would be a good addition. Would we want to allow 
specifying the inclusion like below:


auto between(string inclusion = "[]")(int v, int a, int b) {
static if(inclusion == "(]")
return (v <= b && v > a);
else static if(inclusion == "[)")
return (v < b && v >= a);
else static if(inclusion == "()")
return (v < b && v > a);
else static if(inclusion == "[]")
return (v <= b && v >= a);
else
static assert(false, "unknown inclusion parameter");
} unittest {
static assert(4.between(3,5));
static assert(4.between(4,5));
static assert(4.between(3,4));

static assert(!4.between!"(]"(4,5));
static assert(!4.between!"[)"(3,4));
}


Re: Feature idea: scope (failure, ExceptionSpecification) for catching exceptions

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d

On Thursday, 26 March 2015 at 11:23:34 UTC, Andrej Mitrovic wrote:

Granted it's not the best example out there, but I think it has
potential. Thoughts?


Your example will print the exception message 2 (or 3) times. Is 
this really necessary?


I've found that

scope(failure) log("Failure while transmogrifying " ~ victim ~ 
":");


is often sufficient. Assuming the exception will be caught and 
logged to the same output as the log line above, it'll show up 
right before the exception details, thus giving the needed 
context.


What is your use case for only logging specific exception types?

It would be nice if we could add arbitrary information to 
in-flight exceptions themselves. E.g. a nicer way to do something 
like this:


 try
   transmogrify(victim);
 catch (Exception x)
 {
   x.msg = "Failure while transmogrifying " ~ victim ~ ":\n" ~ 
msg;

   throw x;
 }

I've also tried a different approach, using chained exceptions:

https://github.com/CyberShadow/ae/blob/master/utils/exception.d#L68-L91


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Tobias Pankrath via Digitalmars-d




I think it would be a good addition. Would we want to allow 
specifying the inclusion like below:


auto between(string inclusion = "[]")(int v, int a, int b) {


+1


Re: Did D will try to get the vulkan opportunity?

2015-03-26 Thread Vlad Levenfeld via Digitalmars-d

On Wednesday, 25 March 2015 at 18:46:51 UTC, bioinfornatics wrote:

Dear,

I would like to know if D dev have a plan with vulkan : 
https://www.khronos.org/vulkan/ ?


D lang will be at same level than others language, nothing 
exists !


D could try to provide API and an environment around vulkan. To 
become a language  "need to be used" in this field.


Regards


I'm not one of the D devs, but I'm working on a lib that builds 
shaders from composable templates (in a very pre-alpha stage 
still, but this is a tough thing to get right).
I was going to do GPGPU through openGL compute shaders, but as 
soon as there are actual details on the Vulkan API, I will 
probably go after that instead.


Maybe not what you were looking for, but if it works out, D will 
be the only language that I know of with something like this.


What I mean by "composable templates":

  alias affine_transform = vertex_shader!(
`translation`, `rotation`, `scale`, q{
  gl_Position.x = gl_Position.x * cos (rotation) - 
gl_Position.y * sin (rotation);
  gl_Position.y = gl_Position.x * sin (rotation) + 
gl_Position.y * cos (rotation);

  gl_Position.xy *= scale;
  gl_Position.xy += translation;
}
  );

and basically you tack stuff like that together using UFCS,

  auto boxes = Lifetime.Shared!Texture (resolution)
.fill (transparent);

  auto sq = square (1f).VertexBuffer;

  borrow (sq).basic_shader (green (0.5))
.affine_transform (fvec (0, 0), 0, 
(resolution[1]*1.5f/resolution[0])*vector (1f, 1f/3))

.line_loop.render_to (boxes);

and once you attach the shader to a canvas, it'll deduce the 
argument types, generate the rest of the shader code, compile, 
link, upload uniforms and attributes, and save the shader in a 
global AA for recall in case you're visiting it in a loop. It's 
designed to be as much like calling r.map!(x => ...) and friends 
as possible; functional programming with the GPU.


Still working out how to get it to play nicely with compute 
shaders (IO works differently than for regular shaders) but maybe 
the Vulkan spec will reveal an easier way to unify them.


So, there you go; someday, it could be D's own ArrayFire + 
graphics (with a good bit more work).


I've been incubating it as a private repo since its still so raw, 
and I don't want to unveil before its ready and have it get a 
reputation as being half-baked, but if there's legitimate 
interest from people who have a good idea of what they would like 
to see from a graphics/compute API of this nature, I can open it 
up publicly. Or I can send invites, if anyone wants to help 
incubate it by tossing use-cases my way, I'll gladly take them 
and do my best to build this thing out to meet the needs.


Class Hierarchy Graphs

2015-03-26 Thread w0rp via Digitalmars-d
Hello everyone. I was talking in the IRC channel today and I 
mentioned something small I wrote a couple of years ago which 
generates a Graphviz DOT file based on ModuleInfo, so you can see 
a visual class hierarchy with interfaces included. There was some 
interest in this in the channel at the time.


The code doesn't do much more than that at the moment, it could 
offer a few more options including outputing the hierarchy in 
other formats, and the graph it generates could perhaps look 
better. I'm just wondering if anyone here is interested in having 
a tool like this.


If enough people are interested and have a few suggestions for 
some features they like which aren't crazy massive feature lists, 
I'd be willing to expand it a bit, add some documentation, and 
offer it as a DUB package.


Re: Class Hierarchy Graphs

2015-03-26 Thread w0rp via Digitalmars-d

On Thursday, 26 March 2015 at 17:41:58 UTC, w0rp wrote:
Hello everyone. I was talking in the IRC channel today and I 
mentioned something small I wrote a couple of years ago which 
generates a Graphviz DOT file based on ModuleInfo, so you can 
see a visual class hierarchy with interfaces included. There 
was some interest in this in the channel at the time.


The code doesn't do much more than that at the moment, it could 
offer a few more options including outputing the hierarchy in 
other formats, and the graph it generates could perhaps look 
better. I'm just wondering if anyone here is interested in 
having a tool like this.


If enough people are interested and have a few suggestions for 
some features they like which aren't crazy massive feature 
lists, I'd be willing to expand it a bit, add some 
documentation, and offer it as a DUB package.


I forgot to link the GitHub repository. Here it is.

https://github.com/w0rp/dhier


Re: Class Hierarchy Graphs

2015-03-26 Thread Vlad Levenfeld via Digitalmars-d

On Thursday, 26 March 2015 at 17:41:58 UTC, w0rp wrote:
Hello everyone. I was talking in the IRC channel today and I 
mentioned something small I wrote a couple of years ago which 
generates a Graphviz DOT file based on ModuleInfo, so you can 
see a visual class hierarchy with interfaces included. There 
was some interest in this in the channel at the time.


The code doesn't do much more than that at the moment, it could 
offer a few more options including outputing the hierarchy in 
other formats, and the graph it generates could perhaps look 
better. I'm just wondering if anyone here is interested in 
having a tool like this.


If enough people are interested and have a few suggestions for 
some features they like which aren't crazy massive feature 
lists, I'd be willing to expand it a bit, add some 
documentation, and offer it as a DUB package.


+1

How much of a stretch would it be to extend the dependency graph 
to compositional types?


struct Foo {
  mixin Bar!(a,b,c);
}

alias Qux = Baz!Foo;

and so on?


Re: Class Hierarchy Graphs

2015-03-26 Thread w0rp via Digitalmars-d

On Thursday, 26 March 2015 at 17:43:46 UTC, Vlad Levenfeld wrote:

+1

How much of a stretch would it be to extend the dependency 
graph to compositional types?


struct Foo {
  mixin Bar!(a,b,c);
}

alias Qux = Baz!Foo;

and so on?


I'm not sure about that. I'd have to think about it a bit. 
Templates are probably trickier.


Someone else has also suggested module dependency graphs. I could 
maybe offer something for that too.


Re: Linkage runaround

2015-03-26 Thread Steve Teale via Digitalmars-d
On Thursday, 26 March 2015 at 13:17:04 UTC, Steven Schveighoffer 
wrote:

On 3/26/15 8:37 AM, Steve Teale wrote:
If I link my DMD 2.066.1/ GtkD (latest version) app with 
static Phobos2

I get

Linking executable: ../bin/Debug/compo
.../objdir/mainwin.o: In function
`_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
/usr/include/dmd/druntime/import/core/runtime.d:233: undefined 
reference

to `rt_loadLibrary'
collect2: ld returned 1 exit status

If I change the link spec to use libphobos2.so, then the app 
links, and
runs, but it crashes the first time I try to read something 
from a file

with stream.File.readString.

Does this ring a bell with anyone.


It looks like you are missing a required library. Are you 
linking with ld? If so, make sure you run dmd with -v to see 
the link line it uses.


Telling the linker to use the dynamic linking so - on Ubuntu, 
that appears to be /lib/i386-linux-gnu/ld-linux.so.2 - makes no 
difference.

-Steve




Re: Feature idea: scope (failure, ExceptionSpecification) for catching exceptions

2015-03-26 Thread w0rp via Digitalmars-d
I think I'd tend towards not adding this feature. It seems like 
it's just a logging problem, and try-catch is probably enough for 
that.


Re: A reason to choose D over Go

2015-03-26 Thread Jesse Phillips via Digitalmars-d
On Saturday, 21 March 2015 at 23:14:58 UTC, Ola Fosheim Grøstad 
wrote:

This is a funny workaround:

http://bouk.co/blog/idiomatic-generics-in-go/


And someone found a hole to implement it:

https://www.reddit.com/r/golang/comments/2hw356/idiomatic_generics_in_go/ckwpfms

"The interpretation of the ImportPath is implementation-dependent 
but it is typically a substring of the full file name of the 
compiled package and may be relative to a repository of installed 
packages." -- Go Spec



import (
"templates.Map{int, string}"
)

Hahahaha.


Re: Linkage runaround

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d

On Thursday, 26 March 2015 at 12:37:32 UTC, Steve Teale wrote:
If I link my DMD 2.066.1/ GtkD (latest version) app with static 
Phobos2 I get


Linking executable: ../bin/Debug/compo
../objdir/mainwin.o: In function 
`_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
/usr/include/dmd/druntime/import/core/runtime.d:233: undefined 
reference to `rt_loadLibrary'

collect2: ld returned 1 exit status

If I change the link spec to use libphobos2.so, then the app 
links, and runs, but it crashes the first time I try to read 
something from a file with stream.File.readString.


Does this ring a bell with anyone.


Does your code call Runtime.loadLibrary anywhere?

It looks like rt_loadLibrary is only implemented when on Windows 
or with version(Shared).


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu 
wrote:

On 12/16/13 12:38 PM, Andrei Alexandrescu wrote:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
{
return v >= lo && v <= hi;
}

Add?


Looks like among() has proven its worth since we introduced it. 
Now I somehow forgot between() didn't make it, and reviewed 
some code at work assuming it exists!


I don't know if it's been mentioned yet, but there exists an 
optimization for between with integer arguments:


bool between(T, U1, U2)(T v, U1 lo, U2 hi)
if (is(T:long) && is(U1:long) && is(U2:long))
{
return cast(Unsigned!T )v  - cast(Unsigned!U1)lo
<= cast(Unsigned!U2)hi - cast(Unsigned!U1)lo;
}

For this reason, I think this makes "between" non-trivial, so it 
is worth adding.


Re: A reason to choose D over Go

2015-03-26 Thread via Digitalmars-d

On Thursday, 26 March 2015 at 18:33:17 UTC, Jesse Phillips wrote:

import (
"templates.Map{int, string}"
)

Hahahaha.


It is crazy stuff like that that makes fringe languages more fun 
to read about than the big serious ones. ;)


Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread Idan Arye via Digitalmars-d
There is a discussion about D vs Go going on in several 
threads(yey for multithreading!), and one thread is about an 
article by Gary Willoughby that claims that Go is not suitable 
for sophisticated 
programmers(http://forum.dlang.org/thread/mev7ll$mqr$1...@digitalmars.com). 
What's interesting about this one is the reddit comments, which 
turned into an argument between simple languages that average 
programmers can use and complex languages that only the top 1% of 
intelligent programmers can use, but they can extract more out of 
them.


But the thing is - the world of the top programmers is not really 
separate from that of average programmers. Professional 
development teams can have a few top programmers and many average 
one, all be working on the same project. Open source projects can 
have top programmers working on the core while allowing average 
programmers to contribute some simple features. Top programmers 
can write libraries that can be used by average programmers.


To allow these things, top programmers and average programmers 
should be able to work on the same language. Of course, any 
language that average programmers can master should be easy for a 
top programmer to master - but the thing is, we also want the top 
programmer to be able to bring more out of the language, without 
limiting them by it's over-simplicity. This will also benefit the 
average programmers, since they also improve the quality of the 
libraries and modules they are using.


This idea is nothing new, and was mentioned in the main(=biggest) 
current D vs Go 
thread(http://forum.dlang.org/thread/mdtago$em9$1...@digitalmars.com?page=3#post-jeuhtlocousxtezoaqqh:40forum.dlang.org). 
What I want to talk about here is the seams. The hurdles that in 
practice make this duality harder.


Let's compare it to another duality that D(and many other 
languages, mainly modern systems languages) promotes - the 
duality between high-level and low-level. Between write-code-fast 
and write-fast-code.


The transition between high-level and low-level code in D 
consists by a change of the things uses - which language 
constructs, which idioms, which functions. But there aren't any 
visible seams. You don't need to use FFI or to dynamically load a 
library file written in another language or anything like that - 
you simply write the high-level parts like you would write 
high-level code and the low-level parts like you would write 
low-level code, and they just work together.


The duality between high-level D and low-level D is seamless. The 
duality between simple D and complex D - not so much.


The seams here exist mainly in understanding how to use complex 
code from simple code. Let's take std.algorithm(.*) for example. 
The algorithms' implementations there are complex and use 
advanced D features, but using them is very simple. Provided, of 
course, that you know how to use them(and no - not everything 
that you know becomes simple. I know how to solve regular 
differential equations, but it's still very complex to do so).


The problem, as Andrei Alexandrescu pointed 
out(http://forum.dlang.org/thread/mdtago$em9$1...@digitalmars.com?page=6#post-mduv1i:242169:241:40digitalmars.com), 
is learning how to use them. Ideally you'd want to be able to 
look at a function's signature and learn from that how to use it. 
It's name and return type should tell you what it does and it's 
argument names and types should tell you what to send to it. The 
documentation only there for a more through description and to 
warn you about pitfalls and edge cases.


But when it comes to heavily templated functions - understanding 
the signature is HARD. It's hard enough for the top programmers 
that can handle the complex D features - it's much harder for the 
average programmers that could have easily used these functions 
if they could just understand the documentation.


Compare it, for example, to Jave. Even if a library doesn't 
contain a single documentation comment, the auto-generated 
javadoc that contains just the class tree and method signatures 
is usually enough to get an idea of what's going where. In D, 
unless the author has provided some actual examples, you are 
going to have a hard time trying to sort out these complex 
templated signatures...


That's quite an hurdle to go though when wanting to use complex 
code from simple code(or even from other complex code). That's 
the ugly seam I'm talking about.


Now, if you are working on a big project(be it commercial or 
open-source), you can find lot's of examples how to use these 
complex functions, and that's probably how you'd tackle the 
problem. When you are using some library you usually don't have 
that luxury - but these libraries usually have the generated ddoc 
at their website. Of course - that generated ddoc is full with 
complex templated signatures, so that's not very helpful...


So, what can be done? Maybe the ddoc generator, instead of 
writing the whole signatu

How does the D compiler get updated on travis-ci.org?

2015-03-26 Thread Gary Willoughby via Digitalmars-d
Now that we have a new D compiler version released how does the D 
compiler on travis-ci.org get updated?


I've recently fixed some issues (in my code) that were hampered 
by a bug in the last version. Now that it's fixed the older 
version on travis-ci.org is crashing because of it.


I've raised an issue here:
https://github.com/travis-ci/travis-ci/issues/3472


Re: How does the D compiler get updated on travis-ci.org?

2015-03-26 Thread extrawurst via Digitalmars-d

On Thursday, 26 March 2015 at 19:31:44 UTC, Gary Willoughby wrote:
Now that we have a new D compiler version released how does the 
D compiler on travis-ci.org get updated?


I've recently fixed some issues (in my code) that were hampered 
by a bug in the last version. Now that it's fixed the older 
version on travis-ci.org is crashing because of it.


I've raised an issue here:
https://github.com/travis-ci/travis-ci/issues/3472


i think it is already available on travis. this it what works for 
me:

https://github.com/Extrawurst/unecht/blob/master/.travis.yml

```
language: d

d:
  - dmd-2.067.0
```


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread Alex Parrill via Digitalmars-d

On Thursday, 26 March 2015 at 19:32:53 UTC, Idan Arye wrote:

...snip...


So tl;dr; make the template constraints in ddoc less prominent?

The "new library reference preview" under Resources seems to 
already have this (example: 
http://dlang.org/library/std/algorithm/searching/starts_with.html)


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread Steven Schveighoffer via Digitalmars-d

On 3/26/15 3:45 PM, Alex Parrill wrote:

On Thursday, 26 March 2015 at 19:32:53 UTC, Idan Arye wrote:

...snip...


So tl;dr; make the template constraints in ddoc less prominent?

The "new library reference preview" under Resources seems to already
have this (example:
http://dlang.org/library/std/algorithm/searching/starts_with.html)


Yes, it's so unprominent, I can't find it :)

I don't think this was intentional...

-Steve


Re: Class Hierarchy Graphs

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 10:41 AM, w0rp wrote:

Hello everyone. I was talking in the IRC channel today and I mentioned
something small I wrote a couple of years ago which generates a Graphviz
DOT file based on ModuleInfo, so you can see a visual class hierarchy
with interfaces included. There was some interest in this in the channel
at the time.

The code doesn't do much more than that at the moment, it could offer a
few more options including outputing the hierarchy in other formats, and
the graph it generates could perhaps look better. I'm just wondering if
anyone here is interested in having a tool like this.

If enough people are interested and have a few suggestions for some
features they like which aren't crazy massive feature lists, I'd be
willing to expand it a bit, add some documentation, and offer it as a
DUB package.


That would definitely be of interest. Also, if some of that can be 
reused to show inter-module dependencies that would be even better. 
Thanks! -- Andrei


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 11:41 AM, Vladimir Panteleev wrote:

On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu wrote:

On 12/16/13 12:38 PM, Andrei Alexandrescu wrote:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
{
return v >= lo && v <= hi;
}

Add?


Looks like among() has proven its worth since we introduced it. Now I
somehow forgot between() didn't make it, and reviewed some code at
work assuming it exists!


I don't know if it's been mentioned yet, but there exists an
optimization for between with integer arguments:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
 if (is(T:long) && is(U1:long) && is(U2:long))
{
 return cast(Unsigned!T )v  - cast(Unsigned!U1)lo
 <= cast(Unsigned!U2)hi - cast(Unsigned!U1)lo;
}

For this reason, I think this makes "between" non-trivial, so it is
worth adding.


Hmmm... so we have two subtractions and one comparisons vs. two 
comparisons and a jump in between. I think you're right! -- Andrei


Re: How does the D compiler get updated on travis-ci.org?

2015-03-26 Thread Gary Willoughby via Digitalmars-d

On Thursday, 26 March 2015 at 19:37:06 UTC, extrawurst wrote:
i think it is already available on travis. this it what works 
for me:

https://github.com/Extrawurst/unecht/blob/master/.travis.yml

```
language: d

d:
  - dmd-2.067.0
```


I'm just using:

language: d

I hoped this would pick up the latest version.


Re: How does the D compiler get updated on travis-ci.org?

2015-03-26 Thread Alex Parrill via Digitalmars-d

On Thursday, 26 March 2015 at 20:40:50 UTC, Gary Willoughby wrote:

On Thursday, 26 March 2015 at 19:37:06 UTC, extrawurst wrote:
i think it is already available on travis. this it what works 
for me:

https://github.com/Extrawurst/unecht/blob/master/.travis.yml

```
language: d

d:
 - dmd-2.067.0
```


I'm just using:

language: d

I hoped this would pick up the latest version.


From the source [1], looks like its harcoded to default to 
2.066.1.


[1] 
https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/script/d.rb


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 11:41 AM, Vladimir Panteleev wrote:

On Sunday, 15 March 2015 at 01:48:53 UTC, Andrei Alexandrescu wrote:

On 12/16/13 12:38 PM, Andrei Alexandrescu wrote:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
{
return v >= lo && v <= hi;
}

Add?


Looks like among() has proven its worth since we introduced it. Now I
somehow forgot between() didn't make it, and reviewed some code at
work assuming it exists!


I don't know if it's been mentioned yet, but there exists an
optimization for between with integer arguments:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
 if (is(T:long) && is(U1:long) && is(U2:long))
{
 return cast(Unsigned!T )v  - cast(Unsigned!U1)lo
 <= cast(Unsigned!U2)hi - cast(Unsigned!U1)lo;
}

For this reason, I think this makes "between" non-trivial, so it is
worth adding.


Wait, that doesn't work. 5.between(4, 3) returns true, should return 
false. -- Andrei


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Thu, Mar 26, 2015 at 07:32:51PM +, Idan Arye via Digitalmars-d wrote:
[...]
> uint startsWith(alias pred = "a == b")(Range doesThisStart, Needles...
> withOneOfThese);
>   where:
> Range is an inferred template argument
> Needles is a variadic inferred template argument
> isInputRange!Range
> Needles.length > 1
> is(typeof(.startsWith!pred(doesThisStart, withOneOfThese[0])) : bool)
> is(typeof(.startsWith!pred(doesThisStart, withOneOfThese[1..$])) : uint)
> 
> We've broken the signature into the parts required to use the function
> and the parts required to FULLY understand the previous parts. The
> motivation is that the second group of parts is also important, so it
> needs to be there, but it creates a lot of unneeded noise so it
> shouldn't be a direct part of the signature(at least not in the doc).
> It's similar to the docs of other types used in the signature - it's
> important to have these docs somewhere accessible, but you don't want
> to add them in the middle of the signature because it'll make it
> unreadable.

This is not a new idea:

https://issues.dlang.org/show_bug.cgi?id=13676

The question is, who's gonna implement it?


T

-- 
If you want to solve a problem, you need to address its root cause, not just 
its symptoms. Otherwise it's like treating cancer with Tylenol...


Re: Solution to problems:

2015-03-26 Thread Jake The Baker via Digitalmars-d

On Wednesday, 25 March 2015 at 20:05:37 UTC, bitwise wrote:

Do *you know what progress is?

http://arsdnet.net/this-week-in-d/mar-22.html

Author say's it's been a slow week, but you can watch these to 
get a better feel for the pace of D.


Seriously, do you believe that just because Qt, Xcode, VS, etc 
do not have such features that such features are useless or

simply not possible?


Maybe you should ask "If none of these large well funded 
companies have set out to create such features, should it 
really be expected of a free open source project like D?"



So, although I don't speak for the D community, I suspect that 
things are the same as in any open source/free project: "Step 
Up or Shut Up".


At the last DConf though, I remember it being said that what 
the D language really needs is corporate backing/funding. Until 
that happens, I would think it foolhardy to expect any large 
scale changes in how things work here..


That may be the case. Maybe that is the first step. But until
people stop acting like little children and think seriously about
the problems, goals, and solutions then who the heck knows what
to do?


Re: Solution to problems:

2015-03-26 Thread Jake The Baker via Digitalmars-d

On Thursday, 26 March 2015 at 07:06:50 UTC, ketmar wrote:

On Wed, 25 Mar 2015 16:56:32 +, Jake The Baker wrote:


Do *you know what progress is?


one important part of "progress" is not wasting time on useless 
things.


And yet you seem to think D's progress is efficient. What you 
determine to be waste is not the absolute almighty law. Only when 
people discuss honestly the problems and possible solutions can a 
real overarching plan come together. You are not interested in 
that because you simply go with the quo. [I generally call this 
the lemming mentality. Look ahead, don't speak out. Repeat what 
everyone else says. Always conform, priority one. Sound familiar? 
I didn't think so!]





Re: Solution to problems:

2015-03-26 Thread deadalnix via Digitalmars-d

On Thursday, 26 March 2015 at 07:06:50 UTC, ketmar wrote:

On Wed, 25 Mar 2015 16:56:32 +, Jake The Baker wrote:


Do *you know what progress is?


one important part of "progress" is not wasting time on useless 
things.


It is efficiency, not progress.

Progress is the variation of some metric over time. This metric 
can be efficiency or anything else.


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread rumbu via Digitalmars-d

On Thursday, 26 March 2015 at 19:45:19 UTC, Alex Parrill wrote:

On Thursday, 26 March 2015 at 19:32:53 UTC, Idan Arye wrote:

...snip...


So tl;dr; make the template constraints in ddoc less prominent?

The "new library reference preview" under Resources seems to 
already have this (example: 
http://dlang.org/library/std/algorithm/searching/starts_with.html)


This will not solve the readability problem:

- what is a range?
- what is a needle?
- what is a predicate?

Phobos is reinventing the OOP encapsulation without providing the 
minimal tools. IMHO, something similar to "interface" is 
mandatory to define constraints for "range" and the relationship 
between "needle" and "range". In another topic, someone proposed 
the keyword "constraint" - or - extend the concept of "interface" 
to other kind of types than classes and this will allow some 
compile-time interface implementation. Therefore, when I write:


void foo(IInputRange range) { ... }, range can be a class 
implementing IInputRange or any other type which supports the 
same calls described by IInputRange.


Another approach is to provide enough overloads for most used 
scenarios, like testing for prefixes in a string with case 
sensivity or not.










Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d

On Thursday, 26 March 2015 at 21:51:54 UTC, Vladimir Panteleev
wrote:
Oh yeah, this assumes hi <= lo. I thought this was part of the 
function contract.


I meant lo <= hi


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Thursday, 26 March 2015 at 21:09:16 UTC, Andrei Alexandrescu 
wrote:

On 3/26/15 11:41 AM, Vladimir Panteleev wrote:

I don't know if it's been mentioned yet, but there exists an
optimization for between with integer arguments:

bool between(T, U1, U2)(T v, U1 lo, U2 hi)
if (is(T:long) && is(U1:long) && is(U2:long))
{
return cast(Unsigned!T )v  - cast(Unsigned!U1)lo
<= cast(Unsigned!U2)hi - cast(Unsigned!U1)lo;
}

For this reason, I think this makes "between" non-trivial, so 
it is

worth adding.


Wait, that doesn't work. 5.between(4, 3) returns true, should 
return false. -- Andrei


Oh yeah, this assumes hi <= lo. I thought this was part of the 
function contract.


Re: Solution to problems:

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 2:23 PM, Jake The Baker wrote:

But until
people stop acting like little children and think seriously about
the problems, goals, and solutions then who the heck knows what
to do?


http://wiki.dlang.org/Vision/2015H1 -- Andrei


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 2:52 PM, Vladimir Panteleev wrote:

On Thursday, 26 March 2015 at 21:51:54 UTC, Vladimir Panteleev
wrote:

Oh yeah, this assumes hi <= lo. I thought this was part of the
function contract.


I meant lo <= hi


New idea:

bool ordered(pred = "a < b")(T...)(T values)
{
foreach (i, _; T[1 .. $])
{
if (binaryFun!pred(values[i], values[i - 1]) return false;
}
return true;
}

Instead of x.between(a, b) one would write ordered(a, x, b).

Cons: can't use the UFCS nicely. Doesn't generalize to all combinations 
of < and <=.


Pros: Consistent with isSorted so easy to grasp. Does generalize to 
testing multiple values.


Destroy!


Andrei



Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Thu, Mar 26, 2015 at 03:23:12PM -0700, Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 3/26/15 2:52 PM, Vladimir Panteleev wrote:
> >On Thursday, 26 March 2015 at 21:51:54 UTC, Vladimir Panteleev
> >wrote:
> >>Oh yeah, this assumes hi <= lo. I thought this was part of the
> >>function contract.
> >
> >I meant lo <= hi
> 
> New idea:
> 
> bool ordered(pred = "a < b")(T...)(T values)
> {
> foreach (i, _; T[1 .. $])
> {
> if (binaryFun!pred(values[i], values[i - 1]) return false;
> }
> return true;
> }
> 
> Instead of x.between(a, b) one would write ordered(a, x, b).
> 
> Cons: can't use the UFCS nicely. Doesn't generalize to all
> combinations of < and <=.
> 
> Pros: Consistent with isSorted so easy to grasp. Does generalize to
> testing multiple values.
> 
> Destroy!
[...]

Neat idea! This would let us translate mathematical statements of the
form "1 < x < 2 < y < 3" to ordered(1, x, 2, y, 3), and various other
combinations.

Don't like the name, though. Prefer 'isOrdered', otherwise it sounds
like some kind of sorting algorithm (as in, returns an ordered sequence
of its arguments).

As for combinations of < and <=, what about taking multiple template
arguments? E.g.:

if (isOrdered!("<", "<=")(0, x, 10)) { ... }


T

-- 
If it tastes good, it's probably bad for you.


Re: Solution to problems:

2015-03-26 Thread weaselcat via Digitalmars-d

On Thursday, 26 March 2015 at 21:28:14 UTC, Jake The Baker wrote:

On Thursday, 26 March 2015 at 07:06:50 UTC, ketmar wrote:

On Wed, 25 Mar 2015 16:56:32 +, Jake The Baker wrote:


Do *you know what progress is?


one important part of "progress" is not wasting time on 
useless things.


And yet you seem to think D's progress is efficient. What you 
determine to be waste is not the absolute almighty law. Only 
when people discuss honestly the problems and possible 
solutions can a real overarching plan come together. You are 
not interested in that because you simply go with the quo. [I 
generally call this the lemming mentality. Look ahead, don't 
speak out. Repeat what everyone else says. Always conform, 
priority one. Sound familiar? I didn't think so!]


I'm glad you decided to step up and begin working on the project 
you suggested in the OP, I can't wait for you to release it.


Re: Solution to problems:

2015-03-26 Thread ketmar via Digitalmars-d
On Thu, 26 Mar 2015 21:28:13 +, Jake The Baker wrote:

> On Thursday, 26 March 2015 at 07:06:50 UTC, ketmar wrote:
>> On Wed, 25 Mar 2015 16:56:32 +, Jake The Baker wrote:
>>
>>> Do *you know what progress is?
>>
>> one important part of "progress" is not wasting time on useless things.
> 
> And yet you seem to think D's progress is efficient.

sorry, but your mind-reading abilities are weak. i believe that using IDEs 
greatly weakens telepathy trait.

signature.asc
Description: PGP signature


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Jakob Ovrum via Digitalmars-d

On Thursday, 26 March 2015 at 22:30:54 UTC, H. S. Teoh wrote:
As for combinations of < and <=, what about taking multiple 
template

arguments? E.g.:

if (isOrdered!("<", "<=")(0, x, 10)) { ... }




In that case, wouldn't it be more readable to just do:

if (0 < x <= 10) { ... }

?


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 3:28 PM, H. S. Teoh via Digitalmars-d wrote:

Don't like the name, though. Prefer 'isOrdered', otherwise it sounds
like some kind of sorting algorithm (as in, returns an ordered sequence
of its arguments).


Must be single-word name or nothing per Andrei's Hierarchy Of Naming 
Abstractions (AHONA). From low-level to high-level abstractions:


* If a realization is too simple and frequent, no abstraction should 
replace it.


* If a realization has high frequency but low complexity, it can only be 
replaced by an abstraction that is one simple word with no change of 
case. E.g. "among" is okay, "isAmong" is not.


* If a realization has high frequency and high complexity, it may be 
replaced by an abstraction with a multi-word name, little or no nesting, 
and few or no type parameters.


* If a realization has low frequency and high complexity, it may be 
replaced by an abstraction with a multi-word name, nesting, and type 
parameters.



Andrei



Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Thu, Mar 26, 2015 at 03:48:26PM -0700, Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 3/26/15 3:28 PM, H. S. Teoh via Digitalmars-d wrote:
> >Don't like the name, though. Prefer 'isOrdered', otherwise it sounds
> >like some kind of sorting algorithm (as in, returns an ordered
> >sequence of its arguments).
> 
> Must be single-word name or nothing per Andrei's Hierarchy Of Naming
> Abstractions (AHONA). From low-level to high-level abstractions:
> 
> * If a realization is too simple and frequent, no abstraction should
> replace it.
> 
> * If a realization has high frequency but low complexity, it can only
> be replaced by an abstraction that is one simple word with no change
> of case.  E.g. "among" is okay, "isAmong" is not.
> 
> * If a realization has high frequency and high complexity, it may be
> replaced by an abstraction with a multi-word name, little or no
> nesting, and few or no type parameters.
> 
> * If a realization has low frequency and high complexity, it may be
> replaced by an abstraction with a multi-word name, nesting, and type
> parameters.
[...]

If the bar is this high, then I vote against adding this function.

Writing `if (0 <= x && x < 10)` is far easier and has a clear meaning,
whereas hiding it behind a poorly-named one-word abstraction actually
hurts readability and therefore maintainability. IMO this falls under
the first rule you listed above.


T

-- 
There are 10 kinds of people in the world: those who can count in binary, and 
those who can't.


Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread Israel via Digitalmars-d

On Thursday, 26 March 2015 at 21:36:56 UTC, rumbu wrote:

On Thursday, 26 March 2015 at 19:45:19 UTC, Alex Parrill wrote:

On Thursday, 26 March 2015 at 19:32:53 UTC, Idan Arye wrote:

...snip...


So tl;dr; make the template constraints in ddoc less prominent?

The "new library reference preview" under Resources seems to 
already have this (example: 
http://dlang.org/library/std/algorithm/searching/starts_with.html)


This will not solve the readability problem:

- what is a range?
- what is a needle?
- what is a predicate?


Wouldnt that just be "Further documentation" for advanced 
programming concepts?

Only simple easy to understand examples are needed to begin with.

It should flow like a tree.



Re: Human unreadable documentation - the ugly seam between simple D and complex D

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Thu, Mar 26, 2015 at 11:05:28PM +, Israel via Digitalmars-d wrote:
> On Thursday, 26 March 2015 at 21:36:56 UTC, rumbu wrote:
> >On Thursday, 26 March 2015 at 19:45:19 UTC, Alex Parrill wrote:
> >>On Thursday, 26 March 2015 at 19:32:53 UTC, Idan Arye wrote:
> >>>...snip...
> >>
> >>So tl;dr; make the template constraints in ddoc less prominent?
> >>
> >>The "new library reference preview" under Resources seems to already
> >>have this (example:
> >>http://dlang.org/library/std/algorithm/searching/starts_with.html)
> >
> >This will not solve the readability problem:
> >
> >- what is a range?
> >- what is a needle?
> >- what is a predicate?
> 
> Wouldnt that just be "Further documentation" for advanced programming
> concepts?
> Only simple easy to understand examples are needed to begin with.
> 
> It should flow like a tree.

There has already been a recent push to add hyperlinks in Phobos docs
whenever "input range", "output range", etc., are mentioned, to the
definitions of these terms. Well, currently they point to the
isInputRange, isOutputRange, etc., templates in std.range.primitives,
which may not be the best introduction to the concept of ranges, but at
least it will tell you which methods must be supported by these ranges.

Perhaps there should be a glossary page on dlang.org where these terms
can link to, instead.


T

-- 
The richest man is not he who has the most, but he who needs the least.


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Andrei Alexandrescu via Digitalmars-d

On 3/26/15 4:03 PM, H. S. Teoh via Digitalmars-d wrote:

On Thu, Mar 26, 2015 at 03:48:26PM -0700, Andrei Alexandrescu via Digitalmars-d 
wrote:

On 3/26/15 3:28 PM, H. S. Teoh via Digitalmars-d wrote:

Don't like the name, though. Prefer 'isOrdered', otherwise it sounds
like some kind of sorting algorithm (as in, returns an ordered
sequence of its arguments).


Must be single-word name or nothing per Andrei's Hierarchy Of Naming
Abstractions (AHONA). From low-level to high-level abstractions:

* If a realization is too simple and frequent, no abstraction should
replace it.

* If a realization has high frequency but low complexity, it can only
be replaced by an abstraction that is one simple word with no change
of case.  E.g. "among" is okay, "isAmong" is not.

* If a realization has high frequency and high complexity, it may be
replaced by an abstraction with a multi-word name, little or no
nesting, and few or no type parameters.

* If a realization has low frequency and high complexity, it may be
replaced by an abstraction with a multi-word name, nesting, and type
parameters.

[...]

If the bar is this high, then I vote against adding this function.

Writing `if (0 <= x && x < 10)` is far easier and has a clear meaning,
whereas hiding it behind a poorly-named one-word abstraction actually
hurts readability and therefore maintainability. IMO this falls under
the first rule you listed above.


https://github.com/D-Programming-Language/phobos/pull/3112 -- Andrei




Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread Vladimir Panteleev via Digitalmars-d
On Thursday, 26 March 2015 at 22:23:12 UTC, Andrei Alexandrescu 
wrote:

New idea:

bool ordered(pred = "a < b")(T...)(T values)


So... isSorted for tuples?


Re: between and among: worth Phobosization? (reprise)

2015-03-26 Thread H. S. Teoh via Digitalmars-d
On Fri, Mar 27, 2015 at 01:37:45AM +, Vladimir Panteleev via Digitalmars-d 
wrote:
> On Thursday, 26 March 2015 at 22:23:12 UTC, Andrei Alexandrescu wrote:
> >New idea:
> >
> >bool ordered(pred = "a < b")(T...)(T values)
> 
> So... isSorted for tuples?

That's pretty much what it is, and I'm wondering why use a completely
different name rather than overload isSorted.


T

-- 
Не дорог подарок, дорога любовь.


Why dont dlang check NullPointer?

2015-03-26 Thread zhmt via Digitalmars-d

class A
{
void test()
{
writeln("test");
}
}

try
{
A a = null;
a.test();
}catch(Throwable t)
{
writeln(t.msg);
}


The code above will not print a exception message, but crashes 
instead.



I dont think this a good choice for most scenes. For example,I 
developed many modules in my server, and add a new module now. If 
null exception happens, I hope the server continue running, not 
crash. If the server continue running, the functions offered by 
old modules can be used by users, only the new module stop 
serving.




In short words, I want to catch something like 
NullPointerException.


Is this possible?



Re: Why dont dlang check NullPointer?

2015-03-26 Thread Adam D. Ruppe via Digitalmars-d

On Friday, 27 March 2015 at 03:46:49 UTC, zhmt wrote:
The code above will not print a exception message, but crashes 
instead.


It actually will throw on Windows and can be tricked into it on 
Linux; it is an operating system thing more than a language thing.


But...

If null exception happens, I hope the server continue running, 
not crash. If the server continue running, the functions 
offered by old modules can be used by users, only the new 
module stop serving.


The best way to do that is to separate the server modules into 
independent processes. Then if one crashes, the others keep 
running without fear of corruption.


So instead of server modules, try doing mini servers that 
communicate with the main server. This is how a lot of newer 
programs are written because of the reliability and security 
benefits it offers.


Re: Why dont dlang check NullPointer?

2015-03-26 Thread zhmt via Digitalmars-d


The best way to do that is to separate the server modules into 
independent processes. Then if one crashes, the others keep 
running without fear of corruption.


So instead of server modules, try doing mini servers that 
communicate with the main server. This is how a lot of newer 
programs are written because of the reliability and security 
benefits it offers.


But this will make the developement more difficult for me, or not 
acceptable.


Is there any other ways?


Re: Why dont dlang check NullPointer?

2015-03-26 Thread deadalnix via Digitalmars-d

On Friday, 27 March 2015 at 03:59:30 UTC, zhmt wrote:


The best way to do that is to separate the server modules into 
independent processes. Then if one crashes, the others keep 
running without fear of corruption.


So instead of server modules, try doing mini servers that 
communicate with the main server. This is how a lot of newer 
programs are written because of the reliability and security 
benefits it offers.


But this will make the developement more difficult for me, or 
not acceptable.


Is there any other ways?


http://www.deadalnix.me/2012/03/24/get-an-exception-from-a-segfault-on-linux-x86-and-x86_64-using-some-black-magic/

There is a hook in the runtime to enable this if you want.

BUT, null pointer exception or not, Adam is right. Have your 
stuff run in multiple process that you can restart. This is more 
reliable, this is more secure, this is easier to update without 
downtime, and so on... This is far superior solution for server 
stuff.


readln() doesn't stop to read the input.

2015-03-26 Thread jonaspm via Digitalmars-d

Please, i need your help, I tried this:

write("Write p: ");
readln(p);
p = chomp(p);
writeln("Write q: ");
readln(q);
q = chomp(q);

but the result is:
Write p: Write q:

and doesn't pause to read keyboard input... what's wrong?

Thanks in advance!


Re: readln() doesn't stop to read the input.

2015-03-26 Thread tcak via Digitalmars-d

On Friday, 27 March 2015 at 04:37:34 UTC, jonaspm wrote:

Please, i need your help, I tried this:

write("Write p: ");
readln(p);
p = chomp(p);
writeln("Write q: ");
readln(q);
q = chomp(q);

but the result is:
Write p: Write q:

and doesn't pause to read keyboard input... what's wrong?

Thanks in advance!


http://dlang.org/phobos/std_stdio.html#.readln

Check the example, and you will see the problem. readln(p) 
doesn't read what was typed into p.


Re: readln() doesn't stop to read the input.

2015-03-26 Thread jonaspm via Digitalmars-d

but readln(p); isn't supposed to read input and store it into p?


Re: Why dont dlang check NullPointer?

2015-03-26 Thread zhmt via Digitalmars-d

On Friday, 27 March 2015 at 04:13:01 UTC, deadalnix wrote:

On Friday, 27 March 2015 at 03:59:30 UTC, zhmt wrote:


The best way to do that is to separate the server modules 
into independent processes. Then if one crashes, the others 
keep running without fear of corruption.


So instead of server modules, try doing mini servers that 
communicate with the main server. This is how a lot of newer 
programs are written because of the reliability and security 
benefits it offers.


But this will make the developement more difficult for me, or 
not acceptable.


Is there any other ways?


http://www.deadalnix.me/2012/03/24/get-an-exception-from-a-segfault-on-linux-x86-and-x86_64-using-some-black-magic/

There is a hook in the runtime to enable this if you want.

BUT, null pointer exception or not, Adam is right. Have your 
stuff run in multiple process that you can restart. This is 
more reliable, this is more secure, this is easier to update 
without downtime, and so on... This is far superior solution 
for server stuff.


multi-process means crashes are isolated by process, but isolated 
by thread may be more handy.


For example , this feature is suported by java c# lua, ie.

This can make dlang app developed by most developers more 
reliable.


Re: Why dont dlang check NullPointer?

2015-03-26 Thread zhmt via Digitalmars-d



Is there any other ways?


http://www.deadalnix.me/2012/03/24/get-an-exception-from-a-segfault-on-linux-x86-and-x86_64-using-some-black-magic/

There is a hook in the runtime to enable this if you want.


I will try this black magic,Thanks.


Re: Unittests and windows application

2015-03-26 Thread Stefan via Digitalmars-d

On Thursday, 26 March 2015 at 13:57:31 UTC, Kagamin wrote:

Maybe, it's possible to redirect output explicitly?
myapp.exe >output.txt 2>errors.txt


Unbelievable, it is really as simple as this.


Re: readln() doesn't stop to read the input.

2015-03-26 Thread lobo via Digitalmars-d

On Friday, 27 March 2015 at 04:37:34 UTC, jonaspm wrote:

Please, i need your help, I tried this:

write("Write p: ");
readln(p);
p = chomp(p);
writeln("Write q: ");
readln(q);
q = chomp(q);

but the result is:
Write p: Write q:

and doesn't pause to read keyboard input... what's wrong?

Thanks in advance!


This works for me on Linux:
---

import std.stdio;
import std.string;
void main()
{
char[] p, q;
p.length=1024;
q.length=1024;

write("Write p: ");
readln(p);
p=p.chomp;

write("Write q: ");
readln(q);
q=q.chomp;

writeln; writefln("p=%s, q=%s", p,q);
}
---

bye,
lobo