Ask Your Question
3

Single quotes vs double quotes

asked 2019-04-23 13:04:31 -0600

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!

edit retag flag offensive close merge delete

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 ( 2019-04-23 13:23:36 -0600 )edit

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

dsejas gravatar imagedsejas ( 2019-04-24 12:01:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
5

answered 2019-04-24 08:03:34 -0600

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.

edit flag offensive delete link more

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 ( 2019-04-24 12:16:37 -0600 )edit

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 ( 2019-04-24 16:23:10 -0600 )edit

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: 2019-04-23 13:04:31 -0600

Seen: 108 times

Last updated: Apr 24