Re: Empty VS null array?

2013-10-25 Thread ProgrammingGhost
As the OP of this thread I want to say that I think nullable is 
the solution http://dlang.org/phobos/std_typecons.html but I 
dislike how I cant pass 5 or null to a parameter that is 
nullable!int, nullable!string


Re: Empty VS null array?

2013-10-18 Thread ProgrammingGhost

You could use T[]* and pass a null pointer as default?


Yet this answer wasn't on the first page.

I see I can't write fn([1,2]) anymore so I'm unsure how this
solution compares to using Nullable (I can't write fn([1,2]) with
nullable either).


Re: Safe mode in D?

2013-10-18 Thread ProgrammingGhost

On Friday, 18 October 2013 at 22:29:45 UTC, Max Samukha wrote:

On Friday, 18 October 2013 at 20:03:22 UTC, Maxim Fomin wrote:


(By the way, I don't see why the code above provoked you to C#
talks).


Because you:

1) Mentioned C# as a safer alternative to D.
2) Are using reflection to demonstrate D's unsafety.

Try this:

using System;
using System.Reflection;

namespace test
{
class A
{
public int x;
public A()
{   
x += 1;
}
}

class App
{
public static void Main (string[] args)
{
var a = new A();
var ctor = a.GetType().GetConstructor(new Type[] {});
ctor.Invoke(a, new object[] {});
ctor.Invoke(a, new object[] {});
Console.Write(a.x);
}
}
}


I'm not sure why this is entirely bad. It looks like you're 
asking it to call the constructor a few times. If it allocates 
memory the GC should clean it up. Whats 'wrong' with this code?


Re: Empty VS null array?

2013-10-18 Thread ProgrammingGhost

On Friday, 18 October 2013 at 21:15:32 UTC, H. S. Teoh wrote:

On Fri, Oct 18, 2013 at 10:04:52PM +0200, Meta wrote:

On Friday, 18 October 2013 at 19:59:26 UTC, H. S. Teoh wrote:
>...because it eliminates an unnecessary distinction between an
>empty sequence and a non-existent sequence (which then leads 
>to

>similar issues one encounters with null pointers).

That just seems silly. Surely we all recognize that there's a
difference between the empty set and having no set at all, and 
that
it's valuable to be able to distinguish between the two. The 
empty

set is still a set, while nothing is... nothing.


Yes, but if you declare a variable to contain a set, then by 
definition

there is *something*, even if it's an empty set. For there to be
nothing, there shouldn't even be a variable in the first place. 
The fact
that the variable exists and has an identifer means that there 
is

*something*. So your argument is moot.


T


I was simply thinking about sdl where you pass in a rect for the 
coords to blt one surface to the other. Null/0 means copy the 
whole thing. Rect is an object but I was thinking what about 
arrays (empty VS pull a default somewhere). Thats how I came up 
with this question and the point is I WANT to NOT specify a value 
so a DYNAMIC SUITABLE default value can be used.


Re: Empty VS null array?

2013-10-18 Thread ProgrammingGhost

On Friday, 18 October 2013 at 20:09:37 UTC, Blake Anderton wrote:
I agree a null value and empty array are separate concepts, but 
from my very anecdotal/non rigorous point of view I really 
appreciate D's ability to treat them as equivalent.


My day job mostly involves C# and array code almost always 
follows the pattern if(arr == null || arr.Length == 0) ...


In D just doing if(arr.length) feels much nicer and less error 
prone. I'm all for correctness but would hate to throw the baby 
out with the bathwater.


Really? I NEVER write that pattern. I may check if an array is 
null or don't because the function shouldnt be receiving nulls 
(maybe its bad but idc). I just write linq and never bother to 
see if something is empty


Re: Empty VS null array?

2013-10-17 Thread ProgrammingGhost

On Thursday, 17 October 2013 at 23:14:51 UTC, anonymous wrote:
On Thursday, 17 October 2013 at 22:50:22 UTC, ProgrammingGhost 
wrote:
How do I find out if null was passed in? As you can guess I 
wasn't happy with the current behavior.


Code:

import std.stdio;

void main() {

fn([1,2]);
fn(null);
fn([]);
}
void fn(int[] v) {
writeln("-");
if(v==null)
writeln("Use default");
foreach(e; v)
writeln(e);
}

Output

-
1
2
-
Use default
-
Use default


On Thursday, 17 October 2013 at 22:51:24 UTC, ProgrammingGhost 
wrote:
Sorry I misspoke. I meant to say empty array or not null 
passed in. The 3rd call to fn is what I didn't like.


null implicitly converts to []. You can't distinguish them in 
fn.


You could add an overload for typeof(null), but that only 
catches the literal null, probably not what you'd expect:


import std.stdio;
void fn(typeof(null) v) {
writeln("-");
writeln("Use default");
}
void fn(int[] v) {
writeln("-");
foreach(e; v)
writeln(e);
}
void main() {
fn([1,2]);
fn(null);
fn([]);
int[] x = null;
fn(x);
}

-
1
2
-
Use default
-
-


Overloads are acceptable. But that behavior is odd although I do 
understand its being passed as value. I guess I have to suck it 
up and hope this behavior doesn't give me problems.


Re: Empty VS null array?

2013-10-17 Thread ProgrammingGhost

On Thursday, 17 October 2013 at 23:00:12 UTC, Adam D. Ruppe wrote:
On Thursday, 17 October 2013 at 22:50:22 UTC, ProgrammingGhost 
wrote:

How do I find out if null was passed in?


try if(v is null) { use default }

if all you care about is if there's contents, I like to use 
if(v.length) {}


is null still treats [] as null. I tried && !is [] for fun and it 
didnt worth either (null is [])


Re: Empty VS null array?

2013-10-17 Thread ProgrammingGhost
Sorry I misspoke. I meant to say empty array or not null passed 
in. The 3rd call to fn is what I didn't like.


Empty VS null array?

2013-10-17 Thread ProgrammingGhost
How do I find out if null was passed in? As you can guess I 
wasn't happy with the current behavior.


Code:

import std.stdio;

void main() {

fn([1,2]);
fn(null);
fn([]);
}
void fn(int[] v) {
writeln("-");
if(v==null)
writeln("Use default");
foreach(e; v)
writeln(e);
}

Output

-
1
2
-
Use default
-
Use default


Fastest way to learn D?

2013-10-15 Thread ProgrammingGhost
What is the fastest way for me to learn D? I think what I want is 
a syntax reference manual and a good tutorial to learn how to 
find and use libs.


Re: A question for Mr Bright

2013-10-04 Thread ProgrammingGhost

On Friday, 4 October 2013 at 20:54:07 UTC, Walter Bright wrote:

On 10/4/2013 1:23 PM, ProgrammingGhost wrote:
Walter Bright: Did you have a beard during anytime of the the 
design or

development of D? and if not do you regret it?


No. I had a beard in my early 20's, and it never stopped 
itching. I don't want one again.


Besides, I work with power tools and have no interest in having 
my face pulled into the drill press because my beard got 
snagged on it.


Language Combo Breaker


A question for Mr Bright

2013-10-04 Thread ProgrammingGhost
Walter Bright: Did you have a beard during anytime of the the 
design or development of D? and if not do you regret it?


Context: http://c2.com/cgi/wiki?LanguageAuthorBeardPattern


Incremental builds?

2013-09-26 Thread ProgrammingGhost
I assume D can do incremental builds? How fast is the compile 
time compared to C++? Is it slower? C++ only has to read its 
header files and D would need to look at the entire project 
source code (or obj files?).


Re: When compiling multiple source files

2013-08-19 Thread ProgrammingGhost

On Monday, 19 August 2013 at 17:35:39 UTC, John Colvin wrote:
On Monday, 19 August 2013 at 17:15:35 UTC, ProgrammingGhost 
wrote:
On Monday, 19 August 2013 at 11:01:54 UTC, Jacob Carlborg 
wrote:
The compiler will start compiling the files passed on the 
command line. It will read the files asynchronously and then 
lex, parse build an AST and do semantic analyze.


When the semantic analyze is done it will have access to all 
import declarations. It basically starts the same processes 
for all these imports, recursively.


The reason for waiting until semantic analyze is done because 
you can have code looking like this:


mixin("import foo;");

The expansion of the mixin and other similar features are 
done in the semantic analyze phase.


So everything is parsed once and kept in memory until the 
compiler finish every source file? Is there any ram problems 
when compiling large codebases?


Unfortunately, yes, if you give dmd a very large number of 
files all at once, it will chew through all your free RAM. But 
dmd does support separate compilation:


$dmd file1.d -c
$dmd file2.d -c
$dmd file1.o file2.o

which alleviates the problem.

My experience with D is limited. Are libraries the same as C 
libraries? From my understanding the linker figures that part 
out and the compiler needs a separate file for the definition. 
If I build a library in D is it the same as a C library or 
different which includes function definitions?


Sorry if I'm confused I know almost nothing about D. I stick 
to .NET, java and C++


Libraries in D use the same formats as C/C++ libraries.


Is it possible that if I just try to compile 1 file it could 
imports enough libraries that import/need the definitions for 
additional large libraries which in turn also imports everything 
causing ram issues? I'm sure in practice this will almost never 
happen. But I don't doubt there are main libraries that use other 
large libraries and everything imports/uses everything


Re: Is D the Answer to the One vs. Two Language High ,Performance Computing Dilemma?

2013-08-19 Thread ProgrammingGhost

On Sunday, 18 August 2013 at 17:28:16 UTC, Iain Buclaw wrote:

On 18 August 2013 18:24, ProgrammingGhost
 wrote:
On Sunday, 11 August 2013 at 18:25:02 UTC, Andrei Alexandrescu 
wrote:


For a column of text to be readable it should have not much 
more than 10
words per line. Going beyond that forces eyes to scan too 
jerkily and causes

difficulty in following line breaks.



This.
Also some people can read a line a second because they read 
downward instead

of left to right. Although I heard this through hearsay


Probably more like two lines at once, if they are reading a 
book.

Reading code? I reckon you can read downwards on that. :)


Is it true? Are you able to read a line (or two) at once?


Re: When compiling multiple source files

2013-08-19 Thread ProgrammingGhost

On Monday, 19 August 2013 at 11:01:54 UTC, Jacob Carlborg wrote:
The compiler will start compiling the files passed on the 
command line. It will read the files asynchronously and then 
lex, parse build an AST and do semantic analyze.


When the semantic analyze is done it will have access to all 
import declarations. It basically starts the same processes for 
all these imports, recursively.


The reason for waiting until semantic analyze is done because 
you can have code looking like this:


mixin("import foo;");

The expansion of the mixin and other similar features are done 
in the semantic analyze phase.


So everything is parsed once and kept in memory until the 
compiler finish every source file? Is there any ram problems when 
compiling large codebases? My experience with D is limited. Are 
libraries the same as C libraries? From my understanding the 
linker figures that part out and the compiler needs a separate 
file for the definition. If I build a library in D is it the same 
as a C library or different which includes function definitions?


Sorry if I'm confused I know almost nothing about D. I stick to 
.NET, java and C++


Re: Is D the Answer to the One vs. Two Language High ,Performance Computing Dilemma?

2013-08-18 Thread ProgrammingGhost
On Sunday, 11 August 2013 at 18:25:02 UTC, Andrei Alexandrescu 
wrote:
For a column of text to be readable it should have not much 
more than 10 words per line. Going beyond that forces eyes to 
scan too jerkily and causes difficulty in following line breaks.


This.
Also some people can read a line a second because they read 
downward instead of left to right. Although I heard this through 
hearsay


When compiling multiple source files

2013-08-18 Thread ProgrammingGhost

How does the compiler do static typing of multiple source files?
I heard D malloc memory and doesn't free to speed up compilation
but I am guessing every instance doesn't compile just one source
file? My question is if I have a function in this file and
another in a different file what does the compiler do when both
files needs to know the definition of another? Also how does it
handle modules?

  From another thing I heard text parsing can be ridiculously fast
so there may be no need for a binary representation of each file
parsed. Does the D compiler read all source files into memory
generate the AST then starts compiling each file? I know there
more than one compiler but I wouldn't mind hearing from either or
both if they differ.