I totally concur on the awesome explanation.  As a matter of fact, can a 
committer add some of this stuff (maybe not the scala stuff but the 
actual explanation of the SessionVar) to the scaladocs of the SessionVar 
class/object?  That would be a great place for this kind of documentation.

<rant disposition="friendly" purpose="constructive criticism" 
requested-outcome="discussion">
For me, the lack of usable scaladoc is really making it hard to learn 
lift.  I've been toying with the idea of submitting patches to add docs 
as soon as I figure out some stuff...  Problem is that it is going way 
too slow.  A specific example would be the quote from section 6.2.4 in 
the "Eploring Lift" draft that reads: "The CRUDify behavior is very 
flexible, with plenty of defs you can override to control the templates 
for pages..."  Then you go to the API docs for CRUDify and there are 
loads of cool defs, but no documentation what most of these do and what 
an override would get you.  For the ones that have docs it is just a 
single line that doesn't really help that much.
There is the source code.  That's great.  But unfortunately for me, 
Scala is still very much a write-only language since I'm still 
learning.  I know that's my problem, but I know I'm not the only one!  
(I'm learning (and liking!) Scala because of Lift, just like lots of 
people learned Ruby because of Rails.)
</rant>

So, I want to help, because I think Lift is just about the coolest thing 
out there, but it is going to take a while for me to be able to 
contribute.  In the mean time, I would ask those in the know to try to 
add some docs to the code.

BTW, this mailing list of great.  The responses are *very* helpful.  
Keep them comin'!

--Andrew

Charles F. Munat wrote:
> Wow. This was super helpful even to a not-very-newbie. Thanks!
>
> Chas.
>
> David Pollak wrote:
>   
>> On Tue, Apr 28, 2009 at 11:07 PM, pravin karne <pravinka...@gmail.com 
>> <mailto:pravinka...@gmail.com>> wrote:
>>
>>     hi,
>>     i want some explanation for following code
>>
>>
>>     object sessionObj extends SessionVar[HashMap[String, Int]](
>>            new HashMap[String, Int]
>>              {
>>               override def default(key: String): Int = 0
>>             }
>>     )
>>
>>
>> Changing a few things that Tim said.
>>  
>>
>>
>>     1. how object extends class in scala.?
>>
>>
>> object creates a singleton... an instance of the class that can be 
>> shared within the scope that it was created.  If object is used at the 
>> top-level scope, then it is a singleton shared by all classes in that 
>> classloader (your Lift app.)
>>
>> In Scala everything is either an instance of an object or a method. 
>>  This means there are no statics, no primitives, etc.  In order to have 
>> a singleton instance shared within a classloader, use the object mechanism.
>>  
>>
>>
>>     2. are we going to create object of SessionVar class?
>>
>>
>> Yes, we create a singleton instance of the SessionVar class.  The 
>> SessionVar class uses a little machinery to access the backing store of 
>> your session.  So, the SessionVar doesn't actually store a value.  It is 
>> a proxy that gets the current session based on the context of your 
>> thread, it has a globally unique name and uses this name to look up the 
>> underlying value in a hashmap in the session and then casts it to the 
>> type of the specific SessionVar... in this case HashMap[String, Int]. 
>>  In this way, you have type-safe access to session data.  This is a 
>> material advance over the way session data is stored in a Java 
>> session... there's no casting on the user's part.
>>  
>>
>>
>>     3. are we calling constructor of given class?
>>
>>
>> Yes.  However, if you take a look at the SessionVar's constructor, it's 
>> as follows:
>>
>> class SessionVar[T](dflt: => T)
>>
>> This is a "call-by-name" parameter.  So, it's a function rather than a 
>> value.  Why do we do this?  This allows us to create a new instance of 
>> the default value of the SessionVar each time it's needed.  When you 
>> call the is method on the SessionVar, Lift looks to see if the SessioVar 
>> has been defined.  If it has not been defined, then the default value 
>> creator function is applied and we get a new default value, the 
>> SessionVar for the current session is set to that default value and the 
>> freshly minted value is returned.
>>  
>>
>>
>>     4. is it similar to java class which extends other class ,and then
>>     create object of subclass?
>>
>>
>> Scala creates a subclass of SessionVar for your singleton.  If you do 
>> sessionObj.getClass.getName, it will not be SessionVar, but some 
>> compiler-generated name.   See the answer to #1.
>>
>>
>>
>>
>>     I am beginner to scala and lift.
>>
>> Welcome to the community.
>>
>> Thanks,
>>
>> David
>>  
>>
>>
>>     On Tue, Apr 28, 2009 at 7:28 PM, Timothy Perrett
>>     <timo...@getintheloop.eu> wrote:
>>
>>
>>
>>         Try:
>>
>>         // this gets you whatever is in the session object so add to it here
>>         SessionObj.is
>>
>>         Do you specifically need to use Java HashMap? If not, seems like
>>         List[(String,Int)] would be more lift-esq.
>>
>>         Cheers, Tim
>>
>>         On 28/04/2009 13:30, "pravin" <pravinka...@gmail.com
>>         <mailto:pravinka...@gmail.com>> wrote:
>>
>>          >
>>          > Hi guys,
>>          > I want to add objects into session scope.
>>          >
>>          > i am using following code :
>>          >
>>          > object sessionObj extends SessionVar[HashMap[String, Int]](
>>          >         new HashMap[String, Int]
>>          >           {
>>          >            override def default(key: String): Int = 0
>>          >          }
>>          > )
>>          >
>>          > So as per my understanding :-
>>          >
>>          >     1. Session object is of HashMap[String, Int] type.
>>          >     2. I want to add no of string object into above map so i can
>>          > access them during my session
>>          >
>>          >     correct me if i am wrong
>>          >
>>          >
>>          >    So please let me know how can i add/remove  different
>>         String object
>>          > from session scope with above code snippet
>>          >
>>          > Thanks in advance
>>          >
>>          > >
>>          >
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>> Lift, the simply functional web framework http://liftweb.net
>> Beginning Scala http://www.apress.com/book/view/1430219890
>> Follow me: http://twitter.com/dpp
>> Git some: http://github.com/dpp
>>
>>     
>
> >   


--~--~---------~--~----~------------~-------~--~----~
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