You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Igor Vaynberg <ig...@gmail.com> on 2011/01/05 18:44:22 UTC

more explicit handling of null values - yay or nay?

ive recently ran into a few cases where while implementing
ajaxfallbacklink i forgot to test the passed in request target for
null, causing NPEs when the app was accessed from browsers where ajax
failed for whatever reason.

with all this talk of scala recently i figured why not try and
translate one of the feature i really like in scala Option/Null/Some
to our code base.

i came up with a simple value class:
https://gist.github.com/c38456ee75fed541c932

and changed the ajaxfallbacklink to use it
https://gist.github.com/2f648c7feacacf18fc40

the cascade from this change was pretty impressive, a lot of places in
our code support passing a possibly null request target but make no
mention of it:
https://gist.github.com/d9933e24c21f061c6ac2

so advantages:
makes possible null value handling explicit
no more checking the javadoc to see if the method supports null as a
parameter value or ever returns a null
an api break before 1.5 rc1
i think overall makes lives of wicket users easier

disadvantages:
a bit wordier code
an api break just about when we are ready to release 1.5 m4/rc1
whatever we call it

yay or nay? obviously if we say yay there are a lot more places in our
code that can benefit from this

-igor

Re: more explicit handling of null values - yay or nay?

Posted by Igor Vaynberg <ig...@gmail.com>.
They are there to  aid readability.

Sometimes opt.isNotSet is more readable the opt.isNull

-igor

On Jan 5, 2011 11:49 AM, "Martin Grigorov" <mg...@apache.org> wrote:

I am one of those that use NoopAjaxRequestTarget.

I like the approach. It is clear that the parameter may be null and you
cannot forget to make the check.

What is the reason to have both isNull/isNotNull and isSet/isNotSet?
I think just isSet() is enough. It is quite easy to do "if (!isSet())
{return;}

On Wed, Jan 5, 2011 at 7:49 PM, Igor Vaynberg <igor.vaynberg@gmail.com
>wrote:


> we have adopted a required-by-default style, which is correct imho.
> only a few places in our co...

Re: more explicit handling of null values - yay or nay?

Posted by Martin Grigorov <mg...@apache.org>.
I am one of those that use NoopAjaxRequestTarget.

I like the approach. It is clear that the parameter may be null and you
cannot forget to make the check.

What is the reason to have both isNull/isNotNull and isSet/isNotSet?
I think just isSet() is enough. It is quite easy to do "if (!isSet())
{return;}

On Wed, Jan 5, 2011 at 7:49 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> we have adopted a required-by-default style, which is correct imho.
> only a few places in our code are allowed to return null and Optional
> is a simple way to document them directly in our code.
>
> -igor
>
> On Wed, Jan 5, 2011 at 10:36 AM, Martijn Dashorst
> <ma...@gmail.com> wrote:
> > Conversely you could create a Required<T> class that fails when a null
> > is used, properly documenting that a parameter is required.
> >
> > Martijn
> >
> > On Wed, Jan 5, 2011 at 6:44 PM, Igor Vaynberg <ig...@gmail.com>
> wrote:
> >> ive recently ran into a few cases where while implementing
> >> ajaxfallbacklink i forgot to test the passed in request target for
> >> null, causing NPEs when the app was accessed from browsers where ajax
> >> failed for whatever reason.
> >>
> >> with all this talk of scala recently i figured why not try and
> >> translate one of the feature i really like in scala Option/Null/Some
> >> to our code base.
> >>
> >> i came up with a simple value class:
> >> https://gist.github.com/c38456ee75fed541c932
> >>
> >> and changed the ajaxfallbacklink to use it
> >> https://gist.github.com/2f648c7feacacf18fc40
> >>
> >> the cascade from this change was pretty impressive, a lot of places in
> >> our code support passing a possibly null request target but make no
> >> mention of it:
> >> https://gist.github.com/d9933e24c21f061c6ac2
> >>
> >> so advantages:
> >> makes possible null value handling explicit
> >> no more checking the javadoc to see if the method supports null as a
> >> parameter value or ever returns a null
> >> an api break before 1.5 rc1
> >> i think overall makes lives of wicket users easier
> >>
> >> disadvantages:
> >> a bit wordier code
> >> an api break just about when we are ready to release 1.5 m4/rc1
> >> whatever we call it
> >>
> >> yay or nay? obviously if we say yay there are a lot more places in our
> >> code that can benefit from this
> >>
> >> -igor
> >>
> >
> >
> >
> > --
> > Become a Wicket expert, learn from the best: http://wicketinaction.com
> >
>

Re: more explicit handling of null values - yay or nay?

Posted by Igor Vaynberg <ig...@gmail.com>.
we have adopted a required-by-default style, which is correct imho.
only a few places in our code are allowed to return null and Optional
is a simple way to document them directly in our code.

-igor

On Wed, Jan 5, 2011 at 10:36 AM, Martijn Dashorst
<ma...@gmail.com> wrote:
> Conversely you could create a Required<T> class that fails when a null
> is used, properly documenting that a parameter is required.
>
> Martijn
>
> On Wed, Jan 5, 2011 at 6:44 PM, Igor Vaynberg <ig...@gmail.com> wrote:
>> ive recently ran into a few cases where while implementing
>> ajaxfallbacklink i forgot to test the passed in request target for
>> null, causing NPEs when the app was accessed from browsers where ajax
>> failed for whatever reason.
>>
>> with all this talk of scala recently i figured why not try and
>> translate one of the feature i really like in scala Option/Null/Some
>> to our code base.
>>
>> i came up with a simple value class:
>> https://gist.github.com/c38456ee75fed541c932
>>
>> and changed the ajaxfallbacklink to use it
>> https://gist.github.com/2f648c7feacacf18fc40
>>
>> the cascade from this change was pretty impressive, a lot of places in
>> our code support passing a possibly null request target but make no
>> mention of it:
>> https://gist.github.com/d9933e24c21f061c6ac2
>>
>> so advantages:
>> makes possible null value handling explicit
>> no more checking the javadoc to see if the method supports null as a
>> parameter value or ever returns a null
>> an api break before 1.5 rc1
>> i think overall makes lives of wicket users easier
>>
>> disadvantages:
>> a bit wordier code
>> an api break just about when we are ready to release 1.5 m4/rc1
>> whatever we call it
>>
>> yay or nay? obviously if we say yay there are a lot more places in our
>> code that can benefit from this
>>
>> -igor
>>
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
>

Re: more explicit handling of null values - yay or nay?

Posted by Martijn Dashorst <ma...@gmail.com>.
Conversely you could create a Required<T> class that fails when a null
is used, properly documenting that a parameter is required.

Martijn

On Wed, Jan 5, 2011 at 6:44 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> ive recently ran into a few cases where while implementing
> ajaxfallbacklink i forgot to test the passed in request target for
> null, causing NPEs when the app was accessed from browsers where ajax
> failed for whatever reason.
>
> with all this talk of scala recently i figured why not try and
> translate one of the feature i really like in scala Option/Null/Some
> to our code base.
>
> i came up with a simple value class:
> https://gist.github.com/c38456ee75fed541c932
>
> and changed the ajaxfallbacklink to use it
> https://gist.github.com/2f648c7feacacf18fc40
>
> the cascade from this change was pretty impressive, a lot of places in
> our code support passing a possibly null request target but make no
> mention of it:
> https://gist.github.com/d9933e24c21f061c6ac2
>
> so advantages:
> makes possible null value handling explicit
> no more checking the javadoc to see if the method supports null as a
> parameter value or ever returns a null
> an api break before 1.5 rc1
> i think overall makes lives of wicket users easier
>
> disadvantages:
> a bit wordier code
> an api break just about when we are ready to release 1.5 m4/rc1
> whatever we call it
>
> yay or nay? obviously if we say yay there are a lot more places in our
> code that can benefit from this
>
> -igor
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

Re: more explicit handling of null values - yay or nay?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Jan 5, 2011 at 11:44 AM, Igor Vaynberg <ig...@gmail.com> wrote:
> ive recently ran into a few cases where while implementing
> ajaxfallbacklink i forgot to test the passed in request target for
> null, causing NPEs when the app was accessed from browsers where ajax
> failed for whatever reason.
>
> with all this talk of scala recently i figured why not try and
> translate one of the feature i really like in scala Option/Null/Some
> to our code base.
>
> i came up with a simple value class:
> https://gist.github.com/c38456ee75fed541c932
>
> and changed the ajaxfallbacklink to use it
> https://gist.github.com/2f648c7feacacf18fc40
>
> the cascade from this change was pretty impressive, a lot of places in
> our code support passing a possibly null request target but make no
> mention of it:
> https://gist.github.com/d9933e24c21f061c6ac2
>
> so advantages:
> makes possible null value handling explicit
> no more checking the javadoc to see if the method supports null as a
> parameter value or ever returns a null
> an api break before 1.5 rc1
> i think overall makes lives of wicket users easier
>
> disadvantages:
> a bit wordier code
> an api break just about when we are ready to release 1.5 m4/rc1
> whatever we call it
>
> yay or nay? obviously if we say yay there are a lot more places in our
> code that can benefit from this
>
> -igor
>

Someone on the list a while ago asked that we simply have a
NoOpAjaxRequestTarget to avoid NPE.  Obviously it's not as generic as
your option, but it also requires less code changes.

-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

Re: more explicit handling of null values - yay or nay?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Jan 5, 2011 at 12:13 PM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
> We use only Ajax or non-Ajax components. No fallbacks. I think in the
> (near) future we don't really need fallbacks. Everything is javascript
> nowdays. Only mammooths are fallback.
>
> From that perspective it seems excess to add code to make something
> nice that is not going to exist for long.
>
> Ofcourse the opposite is also true, if we make fallbacks very
> comfortable and widely supported, people will continue using
> non-javascript devices longer than necessary.

The developers of Wicket won't be influencing whether people use JS or
not, and we don't influence the people who make the decisions on
whether or not an app needs to support JS / non-JS users.  We provide
a framework for supporting whatever needs to be supported - within
reason.  I think that for the short-term, we still will have many apps
that need to support both.  We just want to know what's the best way
to support those developers who have to support both.

-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

Re: more explicit handling of null values - yay or nay?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
We use only Ajax or non-Ajax components. No fallbacks. I think in the
(near) future we don't really need fallbacks. Everything is javascript
nowdays. Only mammooths are fallback.

>From that perspective it seems excess to add code to make something
nice that is not going to exist for long.

Ofcourse the opposite is also true, if we make fallbacks very
comfortable and widely supported, people will continue using
non-javascript devices longer than necessary.

**
Martin

2011/1/5 Pedro Santos <pe...@gmail.com>:
> Not simplifing (not complicating also), but making clear that an specific
> parameter is optional, it can prevent some runtime NPE by exposing in a very
> clear way at development time that some parameter may be null.
>
> On Wed, Jan 5, 2011 at 3:53 PM, Martin Makundi <
> martin.makundi@koodaripalvelut.com> wrote:
>
>> How would it simplify actual code?
>>
>> **
>> Martin
>>
>> 2011/1/5 Igor Vaynberg <ig...@gmail.com>:
>> > ive recently ran into a few cases where while implementing
>> > ajaxfallbacklink i forgot to test the passed in request target for
>> > null, causing NPEs when the app was accessed from browsers where ajax
>> > failed for whatever reason.
>> >
>> > with all this talk of scala recently i figured why not try and
>> > translate one of the feature i really like in scala Option/Null/Some
>> > to our code base.
>> >
>> > i came up with a simple value class:
>> > https://gist.github.com/c38456ee75fed541c932
>> >
>> > and changed the ajaxfallbacklink to use it
>> > https://gist.github.com/2f648c7feacacf18fc40
>> >
>> > the cascade from this change was pretty impressive, a lot of places in
>> > our code support passing a possibly null request target but make no
>> > mention of it:
>> > https://gist.github.com/d9933e24c21f061c6ac2
>> >
>> > so advantages:
>> > makes possible null value handling explicit
>> > no more checking the javadoc to see if the method supports null as a
>> > parameter value or ever returns a null
>> > an api break before 1.5 rc1
>> > i think overall makes lives of wicket users easier
>> >
>> > disadvantages:
>> > a bit wordier code
>> > an api break just about when we are ready to release 1.5 m4/rc1
>> > whatever we call it
>> >
>> > yay or nay? obviously if we say yay there are a lot more places in our
>> > code that can benefit from this
>> >
>> > -igor
>> >
>>
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: more explicit handling of null values - yay or nay?

Posted by Pedro Santos <pe...@gmail.com>.
Not simplifing (not complicating also), but making clear that an specific
parameter is optional, it can prevent some runtime NPE by exposing in a very
clear way at development time that some parameter may be null.

On Wed, Jan 5, 2011 at 3:53 PM, Martin Makundi <
martin.makundi@koodaripalvelut.com> wrote:

> How would it simplify actual code?
>
> **
> Martin
>
> 2011/1/5 Igor Vaynberg <ig...@gmail.com>:
> > ive recently ran into a few cases where while implementing
> > ajaxfallbacklink i forgot to test the passed in request target for
> > null, causing NPEs when the app was accessed from browsers where ajax
> > failed for whatever reason.
> >
> > with all this talk of scala recently i figured why not try and
> > translate one of the feature i really like in scala Option/Null/Some
> > to our code base.
> >
> > i came up with a simple value class:
> > https://gist.github.com/c38456ee75fed541c932
> >
> > and changed the ajaxfallbacklink to use it
> > https://gist.github.com/2f648c7feacacf18fc40
> >
> > the cascade from this change was pretty impressive, a lot of places in
> > our code support passing a possibly null request target but make no
> > mention of it:
> > https://gist.github.com/d9933e24c21f061c6ac2
> >
> > so advantages:
> > makes possible null value handling explicit
> > no more checking the javadoc to see if the method supports null as a
> > parameter value or ever returns a null
> > an api break before 1.5 rc1
> > i think overall makes lives of wicket users easier
> >
> > disadvantages:
> > a bit wordier code
> > an api break just about when we are ready to release 1.5 m4/rc1
> > whatever we call it
> >
> > yay or nay? obviously if we say yay there are a lot more places in our
> > code that can benefit from this
> >
> > -igor
> >
>



-- 
Pedro Henrique Oliveira dos Santos

Re: more explicit handling of null values - yay or nay?

Posted by richard emberson <ri...@gmail.com>.
There are many, many mailing list threads, blogs, etc., which
discuss nulls versus Option. Mostly, Java folks say that
a Scala-like Option does not really get you anything while the
Scala folks say, yes it does.
Now, being a Scala folk, I have one opinion, but I would
expect that a year ago I might have had a different opinion.

But its not just a "yay or nay" issue, there is a third option :-)

Richard

On 01/05/2011 09:53 AM, Martin Makundi wrote:
> How would it simplify actual code?
>
> **
> Martin
>
> 2011/1/5 Igor Vaynberg<ig...@gmail.com>:
>> ive recently ran into a few cases where while implementing
>> ajaxfallbacklink i forgot to test the passed in request target for
>> null, causing NPEs when the app was accessed from browsers where ajax
>> failed for whatever reason.
>>
>> with all this talk of scala recently i figured why not try and
>> translate one of the feature i really like in scala Option/Null/Some
>> to our code base.
>>
>> i came up with a simple value class:
>> https://gist.github.com/c38456ee75fed541c932
>>
>> and changed the ajaxfallbacklink to use it
>> https://gist.github.com/2f648c7feacacf18fc40
>>
>> the cascade from this change was pretty impressive, a lot of places in
>> our code support passing a possibly null request target but make no
>> mention of it:
>> https://gist.github.com/d9933e24c21f061c6ac2
>>
>> so advantages:
>> makes possible null value handling explicit
>> no more checking the javadoc to see if the method supports null as a
>> parameter value or ever returns a null
>> an api break before 1.5 rc1
>> i think overall makes lives of wicket users easier
>>
>> disadvantages:
>> a bit wordier code
>> an api break just about when we are ready to release 1.5 m4/rc1
>> whatever we call it
>>
>> yay or nay? obviously if we say yay there are a lot more places in our
>> code that can benefit from this
>>
>> -igor
>>
>

-- 
Quis custodiet ipsos custodes

Re: more explicit handling of null values - yay or nay?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
How would it simplify actual code?

**
Martin

2011/1/5 Igor Vaynberg <ig...@gmail.com>:
> ive recently ran into a few cases where while implementing
> ajaxfallbacklink i forgot to test the passed in request target for
> null, causing NPEs when the app was accessed from browsers where ajax
> failed for whatever reason.
>
> with all this talk of scala recently i figured why not try and
> translate one of the feature i really like in scala Option/Null/Some
> to our code base.
>
> i came up with a simple value class:
> https://gist.github.com/c38456ee75fed541c932
>
> and changed the ajaxfallbacklink to use it
> https://gist.github.com/2f648c7feacacf18fc40
>
> the cascade from this change was pretty impressive, a lot of places in
> our code support passing a possibly null request target but make no
> mention of it:
> https://gist.github.com/d9933e24c21f061c6ac2
>
> so advantages:
> makes possible null value handling explicit
> no more checking the javadoc to see if the method supports null as a
> parameter value or ever returns a null
> an api break before 1.5 rc1
> i think overall makes lives of wicket users easier
>
> disadvantages:
> a bit wordier code
> an api break just about when we are ready to release 1.5 m4/rc1
> whatever we call it
>
> yay or nay? obviously if we say yay there are a lot more places in our
> code that can benefit from this
>
> -igor
>

Re: more explicit handling of null values - yay or nay?

Posted by Martijn Dashorst <ma...@gmail.com>.
I think this is one for 1.6, so we can flesh out any issues that arise
from this style of programming.

Martijn

On Wed, Jan 5, 2011 at 6:44 PM, Igor Vaynberg <ig...@gmail.com> wrote:
> ive recently ran into a few cases where while implementing
> ajaxfallbacklink i forgot to test the passed in request target for
> null, causing NPEs when the app was accessed from browsers where ajax
> failed for whatever reason.
>
> with all this talk of scala recently i figured why not try and
> translate one of the feature i really like in scala Option/Null/Some
> to our code base.
>
> i came up with a simple value class:
> https://gist.github.com/c38456ee75fed541c932
>
> and changed the ajaxfallbacklink to use it
> https://gist.github.com/2f648c7feacacf18fc40
>
> the cascade from this change was pretty impressive, a lot of places in
> our code support passing a possibly null request target but make no
> mention of it:
> https://gist.github.com/d9933e24c21f061c6ac2
>
> so advantages:
> makes possible null value handling explicit
> no more checking the javadoc to see if the method supports null as a
> parameter value or ever returns a null
> an api break before 1.5 rc1
> i think overall makes lives of wicket users easier
>
> disadvantages:
> a bit wordier code
> an api break just about when we are ready to release 1.5 m4/rc1
> whatever we call it
>
> yay or nay? obviously if we say yay there are a lot more places in our
> code that can benefit from this
>
> -igor
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com