octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Escape sequences in *printf family of functions


From: Daniel J Sebald
Subject: Re: Escape sequences in *printf family of functions
Date: Thu, 05 Apr 2012 15:16:14 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 04/05/2012 11:58 AM, John W. Eaton wrote:
I'd prefer it if we just have single-quoted strings behave in a
way that is compatible with Matlab.  I know it is inconsistent and
ugly, but I think making the behavior optional is worse.

I don't think it is too bad the way it is. The user is inherently choosing the compatibility mode by selecting the single or double quotes.

However, it would be good to make the documentation reflect what you just wrote, if that hasn't been done yet. For example, I suggest

"
5 Strings
*********
[snip]
   Since the single-quote mark is also used for the transpose operator
(*note Arithmetic Ops::) but double-quote marks have no other purpose
in Octave, it is best to use double-quote marks to denote strings.
"

be removed. If there is a difference in behavior between the two, don't suggest one method over the other. Using single quotes instead of double quotes isn't really an egregious practice anyway, as Octave properly interprets things.

And it would be worth qualifying:

"
5.1 Escape Sequences in string constants
========================================

In double-quoted strings, the backslash character is used to introduce
"escape sequences" that represent other characters.  For example, `\n'
embeds a newline character in a double-quoted string and `\"' embeds a
double quote character.  In single-quoted strings, backslash is not a
special character.  Here is an example showing the difference:
"

to read "In single-quoted strings, backslash is not a special character except when the character strings appear in the printf family of functions where they behave similar to double-quoted strings."

Also, tell me if the following sentence is difficult to comprehend on first read. It is to me:

In double-quoted strings, the backslash character is used to introduce
"escape sequences" that represent other characters.  For example, `\n'
embeds a newline character in a double-quoted string and `\"' embeds a
double quote character.

The reason is that the topic is double and single quote strings and there are double and single quote marks all over this sentence used in multiple ways. For example "escape sequences" uses double quotes as a rhetorical quotation. I think it would be fine to drop the double quotes and just use the phrase "introduce escape sequences that". The reader should know what escape sequences are, and I don't know what the original intent of putting that in quotes is. Next comes `\n' when the context is characters in double quotes. If the reader is trying to get straight the difference between single/double quotes and sees `\n' he or she might think '\n', the single quotes format. Could this just read as follows?

For example, "\n" embeds a newline character and "\"" embeds a double quote character.

I like that because the reader sees how the double quotes combine and the four characters "\"" sink in to one's mind. Seeing `\"' isn't a character sequence one wants to remember. I understand that the `' combo is meant to suggest sample code, but I think that is well understood because \n and \" aren't part of the conventional English language.

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]