HTML tag attribute values should be encased in either single or double quotes, doesn't seem to matter which. I think the XHTML spec tightened that up to require double quotes, though.
To me, the print command is a courtesy at least when using ", in order to distinguish between printed strings and string variable assignments. I tend to ignore the print command when printing triple-quote strings, although println is handy to use in case you can't be bothered typing \n at the end of your single-quote string.
"foo" and """foo""" are in many respects the same thing; they're both strings. A string on a line by itself is an implicit print command, basically, although I often see print used with the single-quote version and not with the triple-quote version.
The "foo" version doesn't allow you to have quotes -- you can do print "foo"+otherstuff+"bar";, which means that if you want to print quotes within the string, you either need to escape it by using \" instead of " (some sample text), or need to use single-quotes, which don't count as the end-of-string marker ((some sample text)
I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.
The primary advantage, at least to my mind, of the triple-quote version is that you don't need to escape the quotes. (Especially since I've trained myself into -format HTML tags, and retraining myself to either use ' or \" is annoying.) I'll also often
( ... )
I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.
i'm sure i read somewhere that you couldn't do this with single quotes, but i just tried it, and you can. so who knows...
I definitely can't remember to escape my single-quotes, so I always go ahead and use triple-quotes under the assumption that I'll end up with a single-quote in there somewhere and will throw things when the compiler yells at me for it.
1."moo";moo 2."""moo""";moo 3.print "moo";moo 4.print """moo""";moo 5.print " lj home"; lj home 6.print "lj home"; lj home 7.print """ lj home"""; lj home 8.print """ lj home"""; lj home 9.print """lj home""";lj home 10.print """lj home"""; lj home 11.print $.view;recent 12.print "$.view";recent 13.print """$.view""";recent 14.print "$this->title() ";compile error 15.print "" + $this->title() + " ";kunzite&39s krazy days
16.""; $this->title(); " ";
17.""; print $this->title(); " ";kunzite&39s krazy days
ok... i think that's enough.
1-4 are effectively identical. 5 & 7 are effectively identical. 6, 8, and 10 are effectively identical. 9 is kinda silly. 11-13 are effectively identical. they also assume you are in RecentPage. RecentPage.view is a string. 15 & 17 are effectively identical. 15-17 assume you are in a *Page. Page::title() returns a string.
in 3-13, print can be removed and still have the same result.
Comments 6
To me, the print command is a courtesy at least when using ", in order to distinguish between printed strings and string variable assignments. I tend to ignore the print command when printing triple-quote strings, although println is handy to use in case you can't be bothered typing \n at the end of your single-quote string.
Reply
The "foo" version doesn't allow you to have quotes -- you can do print "foo"+otherstuff+"bar";, which means that if you want to print quotes within the string, you either need to escape it by using \" instead of " (some sample text), or need to use single-quotes, which don't count as the end-of-string marker ((some sample text)
I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.
The primary advantage, at least to my mind, of the triple-quote version is that you don't need to escape the quotes. (Especially since I've trained myself into -format HTML tags, and retraining myself to either use ' or \" is annoying.) I'll also often ( ... )
Reply
i'm sure i read somewhere that you couldn't do this with single quotes, but i just tried it, and you can. so who knows...
Reply
Reply
Reply
1."moo";moo
2."""moo""";moo
3.print "moo";moo
4.print """moo""";moo
5.print " lj home"; lj home
6.print "lj home"; lj home
7.print """ lj home"""; lj home
8.print """ lj home"""; lj home
9.print """lj home""";lj home
10.print """lj home"""; lj home
11.print $.view;recent
12.print "$.view";recent
13.print """$.view""";recent
14.print "$this->title()
";compile error
15.print "" + $this->title() + "
";kunzite&39s krazy days
16.""; $this->title(); "
";
17.""; print $this->title(); "
";kunzite&39s krazy days
ok... i think that's enough.
1-4 are effectively identical.
5 & 7 are effectively identical.
6, 8, and 10 are effectively identical.
9 is kinda silly.
11-13 are effectively identical. they also assume you are in RecentPage. RecentPage.view is a string.
15 & 17 are effectively identical.
15-17 assume you are in a *Page. Page::title() returns a string.
in 3-13, print can be removed and still have the same result.
Reply
Leave a comment