Making use of case classes and varargs in Link

View: New views
10 Messages — Rating Filter:   Alert me  

Making use of case classes and varargs in Link

by Vesa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I was wondering few thing while reading lift examples. Could the Link
class be turned into a case class so reading would improve? new Link
("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
"b"). This would at least eliminate the need to explain scala's list
construction syntax to the reader. I found out extremely unintuitive
the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
true. This syntax is usually associated with generation of key-value
pairs even in lift APIs and creates confusion (at least on my case). I
guess varargs might be out of question if scala backward compatibility
is considered, but I don't see a reason not to use case classes here.

- Vesa

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


Re: Making use of case classes and varargs in Link

by Jim Barrows :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brutopy@...> wrote:

Hi,

I was wondering few thing while reading lift examples. Could the Link
class be turned into a case class so reading would improve? new Link
("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
"b"). This would at least eliminate the need to explain scala's list

Shouldn't the reader already be aware of Scala's list construction, since that is in fact the language we're using?
If you think Scala's list construction is difficult to for a new reader, I think explaining a case class would be even more confusing.

You might want to look at how case classes differ from a normal class as well.

construction syntax to the reader. I found out extremely unintuitive
the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
true. This syntax is usually associated with generation of key-value
pairs even in lift APIs and creates confusion (at least on my case). I
guess varargs might be out of question if scala backward compatibility
is considered, but I don't see a reason not to use case classes here.

- Vesa





--
James A Barrows


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


Re: Making use of case classes and varargs in Link

by Vesa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


You're right about that. You probably wouldn't get very far without
understanding that. I'm still concerned that I have to type
unnecessary stuff to express myself without getting any gains in (new
Link("a" :: "b" :: nil) vs Link("a", "b")) :D

- Vesa

On 2 marras, 22:27, Jim Barrows <jim.barr...@...> wrote:

> On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brut...@...> wrote:
>
> > Hi,
>
> > I was wondering few thing while reading lift examples. Could the Link
> > class be turned into a case class so reading would improve? new Link
> > ("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
> > Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
> > "b"). This would at least eliminate the need to explain scala's list
>
> Shouldn't the reader already be aware of Scala's list construction, since
> that is in fact the language we're using?
> If you think Scala's list construction is difficult to for a new reader, I
> think explaining a case class would be even more confusing.
>
> You might want to look at how case classes differ from a normal
> class<http://www.scala-lang.org/node/258>as well.
>
>  construction syntax to the reader. I found out extremely unintuitive
>
> > the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
> > true. This syntax is usually associated with generation of key-value
> > pairs even in lift APIs and creates confusion (at least on my case). I
> > guess varargs might be out of question if scala backward compatibility
> > is considered, but I don't see a reason not to use case classes here.
>
> > - Vesa
>
> --
> James A Barrows
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Making use of case classes and varargs in Link

by bearfeeder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, Nov 2, 2009 at 12:34 PM, Vesa <brutopy@...> wrote:

You're right about that. You probably wouldn't get very far without
understanding that. I'm still concerned that I have to type
unnecessary stuff to express myself without getting any gains in (new
Link("a" :: "b" :: nil) vs Link("a", "b")) :D

Or:

List("a", "b")

Or:

"a" :: "b" :: Nil

There are implicit conversions for both
 

- Vesa

On 2 marras, 22:27, Jim Barrows <jim.barr...@...> wrote:
> On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brut...@...> wrote:
>
> > Hi,
>
> > I was wondering few thing while reading lift examples. Could the Link
> > class be turned into a case class so reading would improve? new Link
> > ("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
> > Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
> > "b"). This would at least eliminate the need to explain scala's list
>
> Shouldn't the reader already be aware of Scala's list construction, since
> that is in fact the language we're using?
> If you think Scala's list construction is difficult to for a new reader, I
> think explaining a case class would be even more confusing.
>
> You might want to look at how case classes differ from a normal
> class<http://www.scala-lang.org/node/258>as well.
>
>  construction syntax to the reader. I found out extremely unintuitive
>
> > the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
> > true. This syntax is usually associated with generation of key-value
> > pairs even in lift APIs and creates confusion (at least on my case). I
> > guess varargs might be out of question if scala backward compatibility
> > is considered, but I don't see a reason not to use case classes here.
>
> > - Vesa
>
> --
> James A Barrows




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

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


Re: Making use of case classes and varargs in Link

by bearfeeder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, Nov 2, 2009 at 12:27 PM, Jim Barrows <jim.barrows@...> wrote:


On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brutopy@...> wrote:

Hi,

I was wondering few thing while reading lift examples. Could the Link
class be turned into a case class so reading would improve? new Link
("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
"b"). This would at least eliminate the need to explain scala's list

Shouldn't the reader already be aware of Scala's list construction, since that is in fact the language we're using?
If you think Scala's list construction is difficult to for a new reader, I think explaining a case class would be even more confusing.

Plus, there are a ton of helpers and implicits that build Link() for you.  There is a Link companion object that will build a Link, just as if it was a case class.
 

You might want to look at how case classes differ from a normal class as well.

construction syntax to the reader. I found out extremely unintuitive
the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
true. This syntax is usually associated with generation of key-value
pairs even in lift APIs and creates confusion (at least on my case). I
guess varargs might be out of question if scala backward compatibility
is considered, but I don't see a reason not to use case classes here.

- Vesa





--
James A Barrows







--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

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


Re: Making use of case classes and varargs in Link

by Vesa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Also some plain true or false doesn't really explain it's purpose very
well and with AbsoluteLink("a", "b") I wouldn't have to guess the
meaning or look it up from API documentation.

- Vesa

On 2 marras, 22:34, Vesa <brut...@...> wrote:

> You're right about that. You probably wouldn't get very far without
> understanding that. I'm still concerned that I have to type
> unnecessary stuff to express myself without getting any gains in (new
> Link("a" :: "b" :: nil) vs Link("a", "b")) :D
>
> - Vesa
>
> On 2 marras, 22:27, Jim Barrows <jim.barr...@...> wrote:
>
>
>
> > On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brut...@...> wrote:
>
> > > Hi,
>
> > > I was wondering few thing while reading lift examples. Could the Link
> > > class be turned into a case class so reading would improve? new Link
> > > ("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
> > > Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
> > > "b"). This would at least eliminate the need to explain scala's list
>
> > Shouldn't the reader already be aware of Scala's list construction, since
> > that is in fact the language we're using?
> > If you think Scala's list construction is difficult to for a new reader, I
> > think explaining a case class would be even more confusing.
>
> > You might want to look at how case classes differ from a normal
> > class<http://www.scala-lang.org/node/258>as well.
>
> >  construction syntax to the reader. I found out extremely unintuitive
>
> > > the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
> > > true. This syntax is usually associated with generation of key-value
> > > pairs even in lift APIs and creates confusion (at least on my case). I
> > > guess varargs might be out of question if scala backward compatibility
> > > is considered, but I don't see a reason not to use case classes here.
>
> > > - Vesa
>
> > --
> > James A Barrows
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Making use of case classes and varargs in Link

by Timothy Perrett :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


+1

On 2 Nov 2009, at 20:27, Jim Barrows wrote:

> Shouldn't the reader already be aware of Scala's list construction,  
> since that is in fact the language we're using?
> If you think Scala's list construction is difficult to for a new  
> reader, I think explaining a case class would be even more confusing.


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


Re: Making use of case classes and varargs in Link

by Jim Barrows :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Nov 2, 2009 at 1:34 PM, Vesa <brutopy@...> wrote:

You're right about that. You probably wouldn't get very far without
understanding that. I'm still concerned that I have to type
unnecessary stuff to express myself without getting any gains in (new


A comma separated list of values inside a method call (ie, anything inside parens) are arguments to the method, and not a list of names, in a particular sequence that belong together.
This also means that you can have things like (I didn't run this through a compiler, so syntax is off):
val someStandardDir = "dir1" :: "dir2" :: "dir3" :: Nil
Link( someStandardDir :: "file" :: Nil)

or

Link( fnThatCanCreateTheFirstBit() :: "finalBit" ::Nil)


All of which would harder to read, your way :)


Link("a" :: "b" :: nil) vs Link("a", "b")) :D

- Vesa

On 2 marras, 22:27, Jim Barrows <jim.barr...@...> wrote:
> On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brut...@...> wrote:
>
> > Hi,
>
> > I was wondering few thing while reading lift examples. Could the Link
> > class be turned into a case class so reading would improve? new Link
> > ("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
> > Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
> > "b"). This would at least eliminate the need to explain scala's list
>
> Shouldn't the reader already be aware of Scala's list construction, since
> that is in fact the language we're using?
> If you think Scala's list construction is difficult to for a new reader, I
> think explaining a case class would be even more confusing.
>
> You might want to look at how case classes differ from a normal
> class<http://www.scala-lang.org/node/258>as well.
>
>  construction syntax to the reader. I found out extremely unintuitive
>
> > the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
> > true. This syntax is usually associated with generation of key-value
> > pairs even in lift APIs and creates confusion (at least on my case). I
> > guess varargs might be out of question if scala backward compatibility
> > is considered, but I don't see a reason not to use case classes here.
>
> > - Vesa
>
> --
> James A Barrows




--
James A Barrows


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


Re: Making use of case classes and varargs in Link

by Vesa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Why not with varargs like on below?

case class Link(pathParts: String*)

and I can say Link("a", "b")?

- Vesa

On 3 marras, 00:15, Jim Barrows <jim.barr...@...> wrote:

> On Mon, Nov 2, 2009 at 1:34 PM, Vesa <brut...@...> wrote:
>
> > You're right about that. You probably wouldn't get very far without
> > understanding that. I'm still concerned that I have to type
> > unnecessary stuff to express myself without getting any gains in (new
>
> A comma separated list of values inside a method call (ie, anything inside
> parens) are arguments to the method, and not a list of names, in a
> particular sequence that belong together.
> This also means that you can have things like (I didn't run this through a
> compiler, so syntax is off):
> val someStandardDir = "dir1" :: "dir2" :: "dir3" :: Nil
> Link( someStandardDir :: "file" :: Nil)
>
> or
>
> Link( fnThatCanCreateTheFirstBit() :: "finalBit" ::Nil)
>
> All of which would harder to read, your way :)
>
> Link("a" :: "b" :: nil) vs Link("a", "b")) :D
>
>
>
>
>
>
>
> > - Vesa
>
> > On 2 marras, 22:27, Jim Barrows <jim.barr...@...> wrote:
> > > On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brut...@...> wrote:
>
> > > > Hi,
>
> > > > I was wondering few thing while reading lift examples. Could the Link
> > > > class be turned into a case class so reading would improve? new Link
> > > > ("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
> > > > Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
> > > > "b"). This would at least eliminate the need to explain scala's list
>
> > > Shouldn't the reader already be aware of Scala's list construction, since
> > > that is in fact the language we're using?
> > > If you think Scala's list construction is difficult to for a new reader,
> > I
> > > think explaining a case class would be even more confusing.
>
> > > You might want to look at how case classes differ from a normal
> > > class<http://www.scala-lang.org/node/258>as well.
>
> > >  construction syntax to the reader. I found out extremely unintuitive
>
> > > > the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
> > > > true. This syntax is usually associated with generation of key-value
> > > > pairs even in lift APIs and creates confusion (at least on my case). I
> > > > guess varargs might be out of question if scala backward compatibility
> > > > is considered, but I don't see a reason not to use case classes here.
>
> > > > - Vesa
>
> > > --
> > > James A Barrows
>
> --
> James A Barrows
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to liftweb@...
To unsubscribe from this group, send email to liftweb+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Making use of case classes and varargs in Link

by bearfeeder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Tue, Nov 3, 2009 at 1:16 AM, Vesa <brutopy@...> wrote:

Why not with varargs like on below?

case class Link(pathParts: String*)

and I can say Link("a", "b")?

At this point, we can't overload the object Link.apply method because the compiler will get confused.

If this is bothering you so, why not add your own convenience method:

object MyLink {
  def apply(path: String*): Link = ....
}

 

- Vesa

On 3 marras, 00:15, Jim Barrows <jim.barr...@...> wrote:
> On Mon, Nov 2, 2009 at 1:34 PM, Vesa <brut...@...> wrote:
>
> > You're right about that. You probably wouldn't get very far without
> > understanding that. I'm still concerned that I have to type
> > unnecessary stuff to express myself without getting any gains in (new
>
> A comma separated list of values inside a method call (ie, anything inside
> parens) are arguments to the method, and not a list of names, in a
> particular sequence that belong together.
> This also means that you can have things like (I didn't run this through a
> compiler, so syntax is off):
> val someStandardDir = "dir1" :: "dir2" :: "dir3" :: Nil
> Link( someStandardDir :: "file" :: Nil)
>
> or
>
> Link( fnThatCanCreateTheFirstBit() :: "finalBit" ::Nil)
>
> All of which would harder to read, your way :)
>
> Link("a" :: "b" :: nil) vs Link("a", "b")) :D
>
>
>
>
>
>
>
> > - Vesa
>
> > On 2 marras, 22:27, Jim Barrows <jim.barr...@...> wrote:
> > > On Mon, Nov 2, 2009 at 1:15 PM, Vesa <brut...@...> wrote:
>
> > > > Hi,
>
> > > > I was wondering few thing while reading lift examples. Could the Link
> > > > class be turned into a case class so reading would improve? new Link
> > > > ("a" :: "b" :: nil, false) could be RecursiveLink("a", "b") and new
> > > > Link("a" :: "b" :: Nil) could be something like AbsoluteLink("a",
> > > > "b"). This would at least eliminate the need to explain scala's list
>
> > > Shouldn't the reader already be aware of Scala's list construction, since
> > > that is in fact the language we're using?
> > > If you think Scala's list construction is difficult to for a new reader,
> > I
> > > think explaining a case class would be even more confusing.
>
> > > You might want to look at how case classes differ from a normal
> > > class<http://www.scala-lang.org/node/258>as well.
>
> > >  construction syntax to the reader. I found out extremely unintuitive
>
> > > > the syntax to create Links with dsl like ("help" :: "" :: Nil) ->
> > > > true. This syntax is usually associated with generation of key-value
> > > > pairs even in lift APIs and creates confusion (at least on my case). I
> > > > guess varargs might be out of question if scala backward compatibility
> > > > is considered, but I don't see a reason not to use case classes here.
>
> > > > - Vesa
>
> > > --
> > > James A Barrows
>
> --
> James A Barrows




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

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