As others may have said, the difference between a Box and a value that may be 
null is that both may or may not contain what you want it to have; but in one 
case the compiler lets you assume that it does--that it's not null--which is a 
source of many bugs.
Programming presents a tension between type safety and conciseness, and Scala 
does an amazing job of being extremely type safe and extremely concise. But 
type safety comes first.


-------------------------------------
DMB<combust...@gmail.com> wrote:


I guess that could work, but why go to such lengths where there are
much more straightforward solutions available? What do for
comprehensions buy you in this case? I mean, 99% of the time, when I
want to check for a cookie, I don't need the cookie itself or any of
its properties. I need its value, or null if there's no cookie. Why
not do something a-la RoR:

S.cookieValue("cookieName")

or a-la ASP.NET:

val c = S.cookie("cookieName")
if(c != null) {
   val v = c.value
}

Or, indeed, both?

On Nov 16, 1:22 am, Sergey Andreev <andser...@gmail.com> wrote:
> Hi,
>
> For-comprehensions could help you out:
>
> for{
>   cookie <- S.findCookie(cookieName)
>   value <- cookie} doSomethingWithValue
>
> Regards
>
> On Mon, Nov 16, 2009 at 12:07 PM, DMB <combust...@gmail.com> wrote:
>
> > When I call findCookie it returns a Box. Then, the value on the cookie
> > itself is also a box. Hence a ruby one-liner turns into something
> > like:
>
> > val cookie = S.findCookie(cookieName)
> > if(cookie.isDefined) {
> >     val cookieVal = cookie.open_!.value.openOr(null)
> >     // Do something with the cookie value
> > }
>
> > This is very ugly, so I'm guessing I'm doing something wrong, but try
> > as I might, I could not find any examples that would look even vaguely
> > "right" to me.
>
> > Why can't findCookie return a simple, unboxed HTTPCookie object or
> > null if cookie is not found?
> > Why does the value inside a cookie need to also be Box'ed?
>
> > For the sake of comparison, here's how you do the same thing in RoR:
> > v = cookies["cookieName"]
> > // Do something with the cookie
>
> > or ASP.NET:
> > var c = Request.Cookies["CookieName"]
> > if(c != null) {
> >   var v = c.Value
> >   // Do something with the cookie
> > }
>
> > I fail to see why Lift should be more complicated.
>
> > This is with Lift 1.1 M7


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to