Lazy eval of argument in ?~(msg: String)

16 views
Skip to first unread message

cristian.vrabie

unread,
Feb 21, 2012, 10:31:28 AM2/21/12
to Lift
I usually use the ?~ method of the Box class in this manner:
myBox ?~ ("param %s is missing".format(param)). flatMap( ..... )

I use this a lot because it's an easy and concise way to add
meaningful error messages. But this means that String.format is being
evaluated every time, and in most cases this will not be necessary.
Wouldn't it be better is we would call the msg parameter in ?~ by
name?

So instead of
def ?~(msg: String): Failure = Failure(msg, Empty, Empty)

use this
def ?~(msg: => String): Failure = Failure(msg, Empty, Empty)

I'm not sure if there's a performance penalty in using named
parameters but the Loggable trait uses this for the same reason so I
immagine it's ignorable.

David Pollak

unread,
Feb 21, 2012, 10:48:10 AM2/21/12
to lif...@googlegroups.com
Please open a ticket (http://ticket.liftweb.net you must be a watcher of the LiftWeb space on Assembla) and assign it to me.

Excellent suggestion!


--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


cristian.vrabie

unread,
Feb 21, 2012, 11:43:04 AM2/21/12
to Lift
Seems that even if I'm a watcher I can no longer see the "New Ticket"
button. A screenshot here: http://dl.dropbox.com/u/5175908/Screen%20Shot%202012-02-21%20at%2016.38.27.png
Has this happened to anyone else? I was able to create new tickets a
few weeks ago.
Cristian

On Feb 21, 3:48 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Please open a ticket (http://ticket.liftweb.netyou must be a watcher of
> the LiftWeb space on Assembla) and assign it to me.
>
> Excellent suggestion!
>
> On Tue, Feb 21, 2012 at 7:31 AM, cristian.vrabie
> <cristian.vra...@gmail.com>wrote:
>
>
>
>
>
>
>
>
>
> > I usually use the ?~ method of the Box class in this manner:
> > myBox ?~ ("param %s is missing".format(param)). flatMap( ..... )
>
> > I use this a lot because it's an easy and concise way to add
> > meaningful error messages. But this means that String.format is being
> > evaluated every time, and in most cases this will not be necessary.
> > Wouldn't it be better is we would call the msg parameter in ?~ by
> > name?
>
> > So instead of
> > def ?~(msg: String): Failure = Failure(msg, Empty, Empty)
>
> > use this
> > def ?~(msg: => String): Failure = Failure(msg, Empty, Empty)
>
> > I'm not sure if there's a performance penalty in using named
> > parameters but the Loggable trait uses this for the same reason so I
> > immagine it's ignorable.
>
> > --
> > Lift, the simply functional web framework:http://liftweb.net
> > Code:http://github.com/lift
> > Discussion:http://groups.google.com/group/liftweb
> > Stuck? Help us help you:
> >https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
> --
> Visi.Pro, Cloud Computing for the Rest of Ushttp://visi.pro
> Lift, the simply functional web frameworkhttp://liftweb.net

David Pollak

unread,
Feb 21, 2012, 12:36:53 PM2/21/12
to lif...@googlegroups.com
Weird.  I've created the ticket: http://www.assembla.com/spaces/liftweb/tickets/1198-lzy-eval-of-certain-box-arguments

Thanks for the suggestion.
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net

Naftoli Gugenheim

unread,
Feb 22, 2012, 11:40:43 PM2/22/12
to lif...@googlegroups.com
Hmm, I guess now we know that was because of the migration back to github.
Reply all
Reply to author
Forward
0 new messages