Jump to page: 1 2
Thread overview
Parameter is null by default. No value is given. Code says it is not null.
Apr 09, 2015
tcak
Apr 09, 2015
tcak
Apr 09, 2015
Daniel Kozák
Apr 09, 2015
tcak
Apr 09, 2015
Adam D. Ruppe
Apr 09, 2015
tcak
Apr 09, 2015
tcak
Apr 09, 2015
Daniel Kozak
Apr 09, 2015
Daniel Kozak
Apr 09, 2015
Daniel Kozak
Apr 09, 2015
Daniel Kozak
Apr 09, 2015
tcak
Apr 09, 2015
Adam D. Ruppe
Apr 09, 2015
Daniel Kozák
Apr 09, 2015
Daniel Kozák
April 09, 2015
I have written a function as follows:

public bool setCookie(
	string name,
	string value,
	long maxAgeInSeconds = long.min,
	string expiresOnGMTDate=null,
	string path=null,
	string domain=null,
	bool secure=false
) shared{

	// if headers are sent already, leave
	if( headersSent ) return false;

	// name cannot be empty
	if( (name is null) || (name.length <= 0) ) return false;

	writeln(
		"Name: ", name,
		"  Max Age: ", maxAgeInSeconds,
		"  Expires null: ", (expiresOnGMTDate == null),
		"  Path equals null: ", (path == null),
		"  Domain null: ", (domain is null)
	);

	return true;
}



Here is the testing code:

responseObject.setCookie( "A", "B" );
auto now = std.datetime.Clock.currTime().toSimpleString();
//writeln("Now |", now, "|");
responseObject.setCookie( "Response Time", now );


Here is the results:

Name: A  Max Age: -9223372036854775808  Expires null: true  Path equals null: true  Domain null: true

Name: Response Time  Max Age: -9223372036854775808  Expires null: true  Path equals null: false  Domain null: false


I don't know what is happening though, somehow path and domain parameters in second use of function are not null even I haven't given any value to them.

If I uncomment the "writeln" line in test code, it turns normal. I am so much confused right now. What is happening here?
April 09, 2015
On Thursday, 9 April 2015 at 11:45:31 UTC, tcak wrote:
> I have written a function as follows:
>
> public bool setCookie(
> 	string name,
> 	string value,
> 	long maxAgeInSeconds = long.min,
> 	string expiresOnGMTDate=null,
> 	string path=null,
> 	string domain=null,
> 	bool secure=false
> ) shared{
>
> 	// if headers are sent already, leave
> 	if( headersSent ) return false;
>
> 	// name cannot be empty
> 	if( (name is null) || (name.length <= 0) ) return false;
>
> 	writeln(
> 		"Name: ", name,
> 		"  Max Age: ", maxAgeInSeconds,
> 		"  Expires null: ", (expiresOnGMTDate == null),
> 		"  Path equals null: ", (path == null),
> 		"  Domain null: ", (domain is null)
> 	);
>
> 	return true;
> }
>
>
>
> Here is the testing code:
>
> responseObject.setCookie( "A", "B" );
> auto now = std.datetime.Clock.currTime().toSimpleString();
> //writeln("Now |", now, "|");
> responseObject.setCookie( "Response Time", now );
>
>
> Here is the results:
>
> Name: A  Max Age: -9223372036854775808  Expires null: true  Path equals null: true  Domain null: true
>
> Name: Response Time  Max Age: -9223372036854775808  Expires null: true  Path equals null: false  Domain null: false
>
>
> I don't know what is happening though, somehow path and domain parameters in second use of function are not null even I haven't given any value to them.
>
> If I uncomment the "writeln" line in test code, it turns normal. I am so much confused right now. What is happening here?

Well, I have tried same code without objects in a test code, and it is null now as expected. Completely same code though.
April 09, 2015
On Thu, 09 Apr 2015 11:45:30 +0000
tcak via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:

> I have written a function as follows:
> 
> public bool setCookie(
> 	string name,
> 	string value,
> 	long maxAgeInSeconds = long.min,
> 	string expiresOnGMTDate=null,
> 	string path=null,
> 	string domain=null,
> 	bool secure=false
> ) shared{
> 
> 	// if headers are sent already, leave
> 	if( headersSent ) return false;
> 
> 	// name cannot be empty
> 	if( (name is null) || (name.length <= 0) ) return false;
> 
> 	writeln(
> 		"Name: ", name,
> 		"  Max Age: ", maxAgeInSeconds,
> 		"  Expires null: ", (expiresOnGMTDate == null),
> 		"  Path equals null: ", (path == null),
> 		"  Domain null: ", (domain is null)
> 	);
> 
> 	return true;
> }
> 
> 
> 
> Here is the testing code:
> 
> responseObject.setCookie( "A", "B" );
> auto now = std.datetime.Clock.currTime().toSimpleString();
> //writeln("Now |", now, "|");
> responseObject.setCookie( "Response Time", now );
> 
> 
> Here is the results:
> 
> Name: A  Max Age: -9223372036854775808  Expires null: true  Path equals null: true  Domain null: true
> 
> Name: Response Time  Max Age: -9223372036854775808  Expires null: true  Path equals null: false  Domain null: false
> 
> 
> I don't know what is happening though, somehow path and domain parameters in second use of function are not null even I haven't given any value to them.
> 
> If I uncomment the "writeln" line in test code, it turns normal. I am so much confused right now. What is happening here?

Can you post full example somewhere, this code works ok for me:

import std.stdio;
import std.datetime;

class Response
{
    public bool setCookie(
            string name,
            string value,
            long maxAgeInSeconds = long.min,
            string expiresOnGMTDate=null,
            string path=null,
            string domain=null,
            bool secure=false
    ) shared
    {

            // name cannot be empty
            if( (name is null) || (name.length <= 0) ) return false;

            writeln(
                    "Name: ", name,
                    "  Max Age: ", maxAgeInSeconds,
                    "  Expires null: ", (expiresOnGMTDate == null),
                    "  Path equals null: ", (path == null),
                    "  Domain null: ", (domain is null)
            );

            return true;
    }
}

void main()
{
    auto response = new shared Response();
    response.setCookie( "A", "B" );
    auto now = std.datetime.Clock.currTime().toSimpleString();
    //writeln("Now |", now, "|");
    response.setCookie( "Response Time", now );
}
April 09, 2015
On Thursday, 9 April 2015 at 12:06:49 UTC, Daniel Kozák wrote:
>
> On Thu, 09 Apr 2015 11:45:30 +0000
> tcak via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
>
>
> Can you post full example somewhere, this code works ok for me:
>
> import std.stdio;
> import std.datetime;
>
> class Response
> {
>     public bool setCookie(
>             string name,
>             string value,
>             long maxAgeInSeconds = long.min,
>             string expiresOnGMTDate=null,
>             string path=null,
>             string domain=null,
>             bool secure=false
>     ) shared
>     {
>
>             // name cannot be empty
>             if( (name is null) || (name.length <= 0) ) return false;
>
>             writeln(
>                     "Name: ", name,
>                     "  Max Age: ", maxAgeInSeconds,
>                     "  Expires null: ", (expiresOnGMTDate == null),
>                     "  Path equals null: ", (path == null),
>                     "  Domain null: ", (domain is null)
>             );
>
>             return true;
>     }
> }
>
> void main()
> {
>     auto response = new shared Response();
>     response.setCookie( "A", "B" );
>     auto now = std.datetime.Clock.currTime().toSimpleString();
>     //writeln("Now |", now, "|");
>     response.setCookie( "Response Time", now );
> }

I have listed full code down below. It is written in test.d file and I run it with "rdmd test.d". Its result is as below for me:

tolga@tolga-H97M-D3H:~/Desktop$ rdmd test.d
Name: A 1  Expires null: true  Path equals null: true  Domain null: true
Name: A 2  Expires null: true  Path equals null: true  Domain null: false
Name: A 3  Expires null: true  Path equals null: true  Domain null: false
Name: A 4  Expires null: true  Path equals null: true  Domain null: false
Name: A 5  Expires null: true  Path equals null: true  Domain null: false
~~~~~~~~~
Name: A 6  Expires null: true  Path equals null: false  Domain null: false
Name: A 7  Expires null: true  Path equals null: true  Domain null: false
Name: A 8  Expires null: true  Path equals null: true  Domain null: false
Name: A 9  Expires null: true  Path equals null: true  Domain null: false
~~~~~~~~~
Name: A10  Expires null: true  Path equals null: false  Domain null: false
Name: A11  Expires null: true  Path equals null: true  Domain null: false
Name: A12  Expires null: true  Path equals null: true  Domain null: false
Name: A13  Expires null: true  Path equals null: true  Domain null: false


[[code]]

import std.stdio;
import std.datetime;

public class HttpResponse{
	public void setCookie(
		string name,
		string value,
		long maxAgeInSeconds = long.min,
		string expiresOnGMTDate=null,
		string path=null,
		string domain=null,
		bool secure=false
	) shared{
		writeln(
			"Name: ", name,
			"  Expires null: ", (expiresOnGMTDate == null),
			"  Path equals null: ", (path == null),
			"  Domain null: ", (domain is null)
		);
	}

	public void hellYeah(
		string name,
		string value,
		long maxAgeInSeconds = long.min,
		string expiresOnGMTDate=null,
		string path=null,
		string domain=null,
		bool secure=false
	) shared{
		writeln(
			"Name: ", name,
			"  Expires null: ", (expiresOnGMTDate == null),
			"  Path equals null: ", (path == null),
			"  Domain null: ", (domain is null)
		);
	}

	public void hellYeah2(
		string name,
		string value,
		long maxAgeInSeconds = long.min,
		string expiresOnGMTDate=null,
		string path=null,
		string domain=null,
		bool secure=false
	) shared{
		writeln(
			"Name: ", name,
			"  Expires null: ", (expiresOnGMTDate == null),
			"  Path equals null: ", (path == null),
			"  Domain null: ", (domain is null)
		);
	}
}

void main(){
	auto responseObject = new shared HttpResponse();

	responseObject.hellYeah( "A 1", "B1" );
	responseObject.hellYeah( "A 2", "B2" );
	responseObject.hellYeah( "A 3", "B3" );
	responseObject.hellYeah( "A 4", "B4" );
	responseObject.hellYeah( "A 5", "B5" );

	writeln("~~~~~~~~~");

	responseObject.setCookie( "A 6", "B6" );
	responseObject.setCookie( "A 7", "B7" );
	responseObject.setCookie( "A 8", "B8" );
	responseObject.setCookie( "A 9", "B9" );

	writeln("~~~~~~~~~");
	
	responseObject.hellYeah2( "A10", "B10" );
	responseObject.hellYeah2( "A11", "B11" );
	responseObject.hellYeah2( "A12", "B12" );
	responseObject.hellYeah2( "A13", "B13" );
}
April 09, 2015
Don't use string == null, it is true for empty strings since null and an empty string are almost interchangable.

You can try if(string is null) - is instead of ==. Though usually in D, I just if(string.length == 0) and treat empty and null the same way.
April 09, 2015
On Thursday, 9 April 2015 at 13:32:38 UTC, Adam D. Ruppe wrote:
> Don't use string == null, it is true for empty strings since null and an empty string are almost interchangable.
>
> You can try if(string is null) - is instead of ==. Though usually in D, I just if(string.length == 0) and treat empty and null the same way.

I replaced all == with "is" for path and domain. Here are results:

Name: A 1  Expires null: true  Path equals null: true  Domain null: true
Name: A 2  Expires null: true  Path equals null: false  Domain null: false
Name: A 3  Expires null: true  Path equals null: false  Domain null: false
Name: A 4  Expires null: true  Path equals null: false  Domain null: false
Name: A 5  Expires null: true  Path equals null: false  Domain null: false
~~~~~~~~~
Name: A 6  Expires null: true  Path equals null: false  Domain null: false
Name: A 7  Expires null: true  Path equals null: false  Domain null: false
Name: A 8  Expires null: true  Path equals null: false  Domain null: false
Name: A 9  Expires null: true  Path equals null: false  Domain null: false
~~~~~~~~~
Name: A10  Expires null: true  Path equals null: false  Domain null: false
Name: A11  Expires null: true  Path equals null: false  Domain null: false
Name: A12  Expires null: true  Path equals null: false  Domain null: false
Name: A13  Expires null: true  Path equals null: false  Domain null: false


Could you try the code yourself as well? Because something is clearly wrong here. I even have removed "shared" from everywhere, results are still as above. There is no way "Expires" becomes null, and "Path" and "Domain" become false.
April 09, 2015
By the way, I am using "DMD64 D Compiler v2.067.0" on Ubuntu 14.04.
April 09, 2015
On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote:
> By the way, I am using "DMD64 D Compiler v2.067.0" on Ubuntu 14.04.

I have Archlinux DMD64 D Compiler v2.067.0 and it works OK for me.
April 09, 2015
On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote:
> On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote:
>> By the way, I am using "DMD64 D Compiler v2.067.0" on Ubuntu 14.04.
>
> I have Archlinux DMD64 D Compiler v2.067.0 and it works OK for me.

WOW

rdmd app.d(without params):
Name: A 1  Expires null: true  Path equals null: true  Domain null: true
Name: A 2  Expires null: true  Path equals null: true  Domain null: true
Name: A 3  Expires null: true  Path equals null: true  Domain null: true
Name: A 4  Expires null: true  Path equals null: true  Domain null: true
Name: A 5  Expires null: true  Path equals null: true  Domain null: true
~~~~~~~~~
Name: A 6  Expires null: true  Path equals null: true  Domain null: true
Name: A 7  Expires null: true  Path equals null: true  Domain null: true
Name: A 8  Expires null: true  Path equals null: true  Domain null: true
Name: A 9  Expires null: true  Path equals null: true  Domain null: true
~~~~~~~~~
Name: A10  Expires null: true  Path equals null: true  Domain null: true
Name: A11  Expires null: true  Path equals null: true  Domain null: true
Name: A12  Expires null: true  Path equals null: true  Domain null: true
Name: A13  Expires null: true  Path equals null: true  Domain null: true



dmd -O:
Name: A 1  Expires null: true  Path equals null: false  Domain null: false
Name: A 2  Expires null: true  Path equals null: false  Domain null: false
Name: A 3  Expires null: true  Path equals null: false  Domain null: false
Name: A 4  Expires null: true  Path equals null: false  Domain null: false
Name: A 5  Expires null: true  Path equals null: false  Domain null: false
~~~~~~~~~
Name: A 6  Expires null: true  Path equals null: false  Domain null: false
Name: A 7  Expires null: true  Path equals null: false  Domain null: false
Name: A 8  Expires null: true  Path equals null: false  Domain null: false
Name: A 9  Expires null: true  Path equals null: false  Domain null: false
~~~~~~~~~
Name: A10  Expires null: true  Path equals null: false  Domain null: false
Name: A11  Expires null: true  Path equals null: false  Domain null: false
Name: A12  Expires null: true  Path equals null: false  Domain null: false
Name: A13  Expires null: true  Path equals null: false  Domain null: false

dmd -release:
Name: A 1  Expires null: true  Path equals null: true  Domain null: true
Name: A 2  Expires null: true  Path equals null: false  Domain null: false
Name: A 3  Expires null: true  Path equals null: false  Domain null: false
Name: A 4  Expires null: true  Path equals null: false  Domain null: false
Name: A 5  Expires null: true  Path equals null: false  Domain null: false
~~~~~~~~~
Name: A 6  Expires null: true  Path equals null: false  Domain null: false
Name: A 7  Expires null: true  Path equals null: false  Domain null: false
Name: A 8  Expires null: true  Path equals null: false  Domain null: false
Name: A 9  Expires null: true  Path equals null: false  Domain null: false
~~~~~~~~~
Name: A10  Expires null: true  Path equals null: false  Domain null: false
Name: A11  Expires null: true  Path equals null: false  Domain null: false
Name: A12  Expires null: true  Path equals null: false  Domain null: false
Name: A13  Expires null: true  Path equals null: false  Domain null: false

with ldc everything is ok

April 09, 2015
On Thursday, 9 April 2015 at 14:30:07 UTC, Daniel Kozak wrote:
> On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote:
>> On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote:
>>> By the way, I am using "DMD64 D Compiler v2.067.0" on Ubuntu 14.04.
>>
>> I have Archlinux DMD64 D Compiler v2.067.0 and it works OK for me.
>
> WOW
>
> rdmd app.d(without params):
Ok rdmd and dub works because they are use ldc, but do not me ask how. I always think that dub and rdmd should use dmd compiler until I tell them otherwise

« First   ‹ Prev
1 2