Michael T. Jones
Chief Technology Advocate, Google Inc.
1600 Amphitheatre Parkway, Mountain View, California 94043
Email: m...@google.com Mobile: 650-335-5765 Fax: 650-649-1938
Organizing the world's information to make it universally accessible and useful
[I find the extremely bare nature of Go's raw strings to be
a definite plus, although I didn't at first.]
Well, there's the startlingly clumsy
"bit the first" +
"and the second" +
"and the third"
[1]
If you weren't using a lot of backticks inside the string, then
you could just write
`+"WHATEVER"+`
when you wanted to use fancy escape syntax (or a quoted
backtick) WHATEVER in your string -- do you really need to
quote *every* table name and field? I suppose it is the safe
thing to do -- or you could post-process the string and so your
own escape replaces, which isn't hard unless they might
turn up as literals in the SQL.
Chris
[1] I say "startling clumsy" because I've had to do that in Java
and it rapidly becomes tedious, especially since you then have
to remember to put the \n's in by hand.
--
Chris "allusive" Dollin
> Yet another way.
Nitpick "another" because
or you could post-process the string and so your own
escape replaces,
(complete with missing word).
--
Chris "allusive" Dollin
On 29 June 2011 15:52, Jan Mercl <jan....@nic.cz> wrote:> Yet another way.
Nitpick "another" because
or you could post-process the string and so your own
escape replaces,(complete with missing word).
You can arrange for it to happen during initialisation, so
its not a big run-time deal.
> Wouldn't it be nicer if there was something like:
Probably not, no.
No, really. Go provides a very simple tool -- the raw
string -- and you can get lots of useful effects by working
on the string. It's not clear to me that it would be worth
adding the complications of php/python's big strings
to Go -- it's not a matter of how hard it is to add to the
compiler, it's a matter of how much complication it adds
to the language and its users.
Chris
(Now, interpolation in non-raw strings would be nice.
But we do have fmt.Sprintf, so that's not a big deal either.)
--
Chris "allusive" Dollin
You could write a small program that takes text and outputs the Go
formatted string (%q) which you can paste in your code, along with a
comment containing the original text. Another way is to read it from a
file during from gram initialization (the string would be read from
your binary anyways).
I do agree that multiline quotes look ugly.
Hey all,
I want to store a large SQL query (string) in my code. Because it is so large, I want to use multiple lines for it.