replacing default Std.string for null

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

replacing default Std.string for null

Renaud Bardet-2
Hi everyone,
 
quick question, is it possible to set a different default String for Std.string(null) so that null values don't come up as "null",
displaying nothing is better in a released application when you failed to track null values :/
 
cheers

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: replacing default Std.string for null

Franco Ponticelli
You cannot redefine it but you can write your own Lib.string() and fallback to Std.string if the valus is not null.

Franco

On Wed, Mar 9, 2011 at 10:12 AM, Renaud Bardet <[hidden email]> wrote:
Hi everyone,
 
quick question, is it possible to set a different default String for Std.string(null) so that null values don't come up as "null",
displaying nothing is better in a released application when you failed to track null values :/
 
cheers

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: replacing default Std.string for null

justin_mills
In reply to this post by Renaud Bardet-2
Can you overwrite as3 prototypes in haXe ie...

http://tobyho.com/Modifying_Core_Types_in_ActionScript_3_Using_the_Prototype_Object

Maybe not a good idea but maybe possible.

 On Wed  9/03/11 10:43, Franco Ponticelli [hidden email] wrote:

> You cannot redefine it but you can write your own Lib.string() and
> fallback to Std.string if the valus is not null.
>
> Franco
>
> On Wed, Mar 9, 2011 at 10:12 AM, Renaud Bardet
>  wrote:
> Hi everyone,
>  
> quick question, is it possible to set a different default String for
> Std.string(null) so that null values dont come up as "null",
> displaying nothing is better in a released application when you
> failed to track null values :/
>  
> cheers
>
> --
> haXe - an open source web programming language
> http://haxe.org [1]
>
>
>
> Links:
> ------
> [1] http://haxe.org
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: replacing default Std.string for null

Pimm Hogeling
In reply to this post by Renaud Bardet-2
Franco's solution is the safest.

Overriding Std.string would change the behaviour everywhere. This potentially affects the standard haXe library itself, as well as the other libraries you are using.

On 9 March 2011 11:12, Renaud Bardet <[hidden email]> wrote:
Hi everyone,
 
quick question, is it possible to set a different default String for Std.string(null) so that null values don't come up as "null",
displaying nothing is better in a released application when you failed to track null values :/
 
cheers

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: replacing default Std.string for null

Jordo Odroj
In reply to this post by Renaud Bardet-2
I would suggest making null a conceptual compiler error (if you don't have to deal with many other third party libraries). You can lint all submitted code to your project and reject any with literal references to null. This has worked out great for me so far. I experience about 99% less NPE than I used to because of this. Instead, use an Option<T> class (make your own) so that you can conceptually represent "none" without breaking type safety.
enum Option<T> {
   None;
   Some(t: T);
}

On Wed, Mar 9, 2011 at 2:12 AM, Renaud Bardet <[hidden email]> wrote:
Hi everyone,
 
quick question, is it possible to set a different default String for Std.string(null) so that null values don't come up as "null",
displaying nothing is better in a released application when you failed to track null values :/
 
cheers

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: replacing default Std.string for null

Jordo Odroj
To clarify, I apologize for not answering your actual question, but the real root problem here is that nulls are capable of being "untracked" and the Option enum can help you avoid that in just about *every* part of your application, not just this one.

On Sat, Mar 12, 2011 at 1:03 AM, Jordo Odroj <[hidden email]> wrote:
I would suggest making null a conceptual compiler error (if you don't have to deal with many other third party libraries). You can lint all submitted code to your project and reject any with literal references to null. This has worked out great for me so far. I experience about 99% less NPE than I used to because of this. Instead, use an Option<T> class (make your own) so that you can conceptually represent "none" without breaking type safety.
enum Option<T> {
   None;
   Some(t: T);
}

On Wed, Mar 9, 2011 at 2:12 AM, Renaud Bardet <[hidden email]> wrote:
Hi everyone,
 
quick question, is it possible to set a different default String for Std.string(null) so that null values don't come up as "null",
displaying nothing is better in a released application when you failed to track null values :/
 
cheers

--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org