Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-12-04 Thread PacMan via Digitalmars-d-learn
On Monday, 19 November 2018 at 21:23:31 UTC, Jordi GutiƩrrez 
Hermoso wrote:
When I was first playing with D, I managed to create a segfault 
by doing `SomeClass c;` and then trying do something with the 
object I thought I had default-created, by analogy with C++ 
syntax. Seasoned D programmers will recognise that I did 
nothing of the sort and instead created c is null and my 
program ended up dereferencing a null pointer.


I'm not the only one who has done this. I can't find it right 
now, but I've seen at least one person open a bug report 
because they misunderstood this as a bug in dmd.


I have been told a couple of times that this isn't something 
that needs to be patched in the language, but I don't 
understand. It seems like a very easy way to generate a 
segfault (and not a NullPointerException or whatever).


What's the reasoning for allowing this?


This is because you're transfering what you know from C++ to D, 
directly. You shouldn't do that, check out how the specific 
feature works in the particular language. I used C# mostly and 
Foo f; wouldn't make sense for me, it's not allocated, ti's null. 
So right away I used Foo f = new Foo();


What can I use to parse a date string in a custom format?

2018-11-27 Thread PacMan via Digitalmars-d-learn
I've been looking for a function or library to parse a date in a 
custom format (for validation) similar to C#'s [1] 
TryParseExactbut I couldn't find any. so far I only found 
fromISOExtString(), and fromSimpleString() which doesn't allow me 
to set a custom string format. I've looked up at


https://code.dlang.org/search?q=date
https://code.dlang.org/search?q=date+parsing

but to my surpise I didn't find either. Am I using wrong keywords 
or there's no really such method implemented yet?


[1]: 
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact?redirectedfrom=MSDN&view=netframework-4.7.2#System_DateTime_TryParseExact_System_String_System_String_System_IFormatProvider_System_Globalization_DateTimeStyles_System_DateTime__


How do I the temlate parameter name as string?

2018-11-26 Thread PacMan via Digitalmars-d-learn
ParameterIdentifierTuple from std.traits did work fine for 
regular functions but not for template functions:


Error: template instance 
`std.traits.ParameterIdentifierTuple!(f)` does not match 
template declaration `ParameterIdentifierTuple(func...) if 
(func.length == 1 && isCallable!func)` (foo)


f is defined as:


void f(T)(T t, string p)
if(is(T == A) || is(T == B))
{
// ...
}


my goal is get "p" as string.