First time here? Check out the FAQ!

Sorry, this content is no longer available

Ask Your Question
3

Single quotes vs double quotes

asked 5 years ago

dsejas gravatar image

Hello, Sage Community.

According to Python's PEP8 on string quotes, there is no preference between single quotes and double quotes for enclosing strings. Does this rule also applies to Sage? Is there any de facto standard?

I always assumed that a huge project like SageMath should have its own set of style rules. (For example, Scilab, another open-source alternative to Matlab, has its coding-style guidelines!)

I suppose this question is specially directed to Sage developers, but any concrete (not opinion-based) answer is welcome!

Preview: (hide)

Comments

2

http://doc.sagemath.org/html/en/devel... should be enough. Doc strings of functions / classes use """ as delimitrers. (Rather then '''.)

dan_fulea gravatar imagedan_fulea ( 5 years ago )

Hello, @dan_fulea. Thank you for your comment. Unfortunately, the Sage Development Documentation references PEP8, which leaves in on a loop.

dsejas gravatar imagedsejas ( 5 years ago )

1 Answer

Sort by » oldest newest most voted
5

answered 5 years ago

Iguananaut gravatar image

Nope. Use whatever makes sense in the given context. If editing existing code I try to be consistent at least with the surrounding code (if there are already strings in the function, class, or module I'm editing).

When writing new code I always default to single-quotes (why bother using double-quotes when I can save one of my fingers a stroke (at least on a US keyboard double-quotes require holding shift)) unless I'm writing a string that contains an apostrophe in which case I'll use double-quotes.

If you look at the existing Sage sources this is all over the place and there's no standard. Normally that would bother me but when it comes to single vs. double-quotes I think that's so completely subjective that it's impossible and pointless to enforce a standard.

Preview: (hide)
link

Comments

Thank you, @Iguananaut. This is an excellent guidance. As a curious fact, Spanish keyboards also require to press SHIFT in order to use double quotes.

dsejas gravatar imagedsejas ( 5 years ago )

The only standard is, as @dan_fulea says, to use """ to delimit docstrings, rather than '''. Otherwise, single and double quotes are interchangeable.

John Palmieri gravatar imageJohn Palmieri ( 5 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 740 times

Last updated: Apr 24 '19