Wrapping comments

T

Tobias Weber

Hi,
the guideline (PEP 8) is hard wrap to 7x characters. The reason given is
that soft wrap makes code illegible.

So what if you hard wrap code but let comments and docstrings soft-wrap?

Otherwise it's hugely annoying to edit them. Say you remove the first
three words of a 150 character sentence. Either keep the ugly or rewrap
manually.

Or are there editors that can do a "soft hard wrap" while keeping
indentation and #comment markers intact?
 
T

Tobias Weber

Scott David Daniels said:
You apparently have caught the soft-/hard- disease spread by several

By soft I mean not in the file at all, done dynamically in the
displaying application.
 
S

Steven D'Aprano

You apparently have caught the soft-/hard- disease spread by several
software retailers. There are no such characters as "hard break," "soft
break," "hard space," and "soft space." Check you ASCII or Unicode
standards if you disagree. There is a "non-breaking space" in Unicode,
but it doesn't mean what you mean.

You say that as if ASCII and Unicode are the only conceivable sets of
characters.

Even if they are (and they're not), the OP didn't ask about inserting
hard/soft *characters*. He asked about *actions*: hard-wrapping code and
soft-wrapping comments. He does that (presumably) by inserting newline
characters in code where he wants to force a new line, and telling his
editor to wrap comments according to the editor's own algorithm
(presumably some variation of the rule "if a line extends beyond the
right-edge of the window, wrap it to the next line in the display, but do
not insert a newline character"). This is not a disease, it is very
useful when editing unstructured text. Believe it or not, text editors
are not only useful for editing source code *wink*


[aside]
Personally, I think it is just a little bit sad that in 2009 we still
write programs using editors which are character-based instead of token-
based and syntax-aware. At least good editors have syntax highlighting.
Maybe in another 20 years, nobody will care about low-level details like
the characters used to write code. Only the tokens really matter.
[/aside]


My own opinion is that if the OP is not sharing his code with anyone
else, he can do whatever he likes. Nevertheless, there is value in
sticking to the standards that the majority use, and so I tend to stick
to a line length of 70 characters or less for both code and comments. I'm
not religious about it though.
 
T

Tobias Weber

Steven D'Aprano said:
Maybe in another 20 years, nobody will care about low-level details like
the characters used to write code. Only the tokens really matter.

You could have that ten years ago with AppleScript. Gets annoying
quickly...
 
T

Tobias Weber

Ben Finney said:
Yes. Both Emacs and Vim will do exactly this when re-wrapping a

Thought so. And editors without a learning curve?

I've seen TextWrangler recommended, and it has indented soft wrap, but
seemingly cannot convert that to newlines.

BTW does pydoc care about line length? I didn't find documentation for
it.
 
T

Tobias Weber

Scott David Daniels said:
At least vim and emacs can do so.

Just tried Aquamacs. Using the defaults it correctly re-wraped
docstrings using newlines when inserting, but not when removing words.
So even with the prime editor hard wrap seems, for writing, inferior to
soft wrap.
 
A

Arnaud Delobelle

Tobias Weber said:
Just tried Aquamacs. Using the defaults it correctly re-wraped
docstrings using newlines when inserting, but not when removing words.
So even with the prime editor hard wrap seems, for writing, inferior to
soft wrap.

A simple Alt-Q will reformat everything nicely.
 
L

Lawrence D'Oliveiro

Tobias Weber said:
the guideline (PEP 8) is hard wrap to 7x characters.

Nowadays I set my maximum line lengths, and the widths of my terminal
windows to 100 characters. And I'm wondering whether or not to go wider
still. After all, the screens can take it.
 
L

Lawrence D'Oliveiro

Scott David Daniels said:
But the printers cannot.

If I had to print out all the code and documentation I have to look at, I'd
need to add another room to my house.
 
L

Lawrence D'Oliveiro

If I had to print out all the code and documentation I have to look at,
I'd need to add another room to my house.

And yes, the printers most certainly can take it. Back in the days when you
couldn't even choose different fonts, the most common width for printouts
was 132 columns.
 
T

Tobias Weber

Arnaud Delobelle said:
A simple Alt-Q will reformat everything nicely.

Now that's something. Thanks!

(still not gonna use software that doesn't let me type # because it's
alt+3 on a UK layout; having to re-learn or configure that is just sick)
 
S

Steven D'Aprano

If I had to print out all the code and documentation I have to look at,
I'd need to add another room to my house.


You are allowed to throw it away when you're done with it :)
 
D

David Robinow

Now that's something. Thanks!

(still not gonna use software that doesn't let me type # because it's
alt+3 on a UK layout; having to re-learn or configure that is just sick)
Put the following in your .emacs file:

(define-key key-translation-map [?\M-3] "#")


or, if you prefer, just be sick.
 
T

Tobias Weber

David Robinow said:
(define-key key-translation-map [?\M-3] "#")


or, if you prefer, just be sick.

Thanks, but I don't believe using releases from people who think I jump
should through hoops just to make my keyboard work is a good plan for a
relaxed future. According to their release notes this was (once) fixed
years ago.
 
R

Rhodri James

Now that's something. Thanks!

(still not gonna use software that doesn't let me type # because it's
alt+3 on a UK layout; having to re-learn or configure that is just sick)

What on earth are you talking about? '#' has its own key on a UK layout
(shared with '~', but you know what I mean), just to the left of the
RETURN key. Emacs is my editor of choice, and I've never once come
across anything like this.
 
T

Tobias Weber

"Rhodri James said:
What on earth are you talking about? '#' has its own key on a UK layout

Not on Apple keyboards, and the emacs release in question is Mac only.
 
N

norseman

Tobias said:
Hi,
the guideline (PEP 8) is hard wrap to 7x characters. The reason given is
that soft wrap makes code illegible.

So what if you hard wrap code but let comments and docstrings soft-wrap?

Otherwise it's hugely annoying to edit them. Say you remove the first
three words of a 150 character sentence. Either keep the ugly or rewrap
manually.

Or are there editors that can do a "soft hard wrap" while keeping
indentation and #comment markers intact?

=======================
Paragraph 1: 65 and 72 cols are US typewriter standard 12 and 10 pt
respectively. (MSDOS screen, business standard paper, ..)
And yes, soft wrap does. Check the hardcopy which wraps
code with lots of long lines.

Paragraph 2: Comments? I vote no. These are in the code and should
conform to helping at that location.
Doc_stuff - I vote yes. For the obvious reason that it
makes formating the Docs easier AND is to be 'extracted'
to a separate file for that purpose in the first place.

Paragraph 3: True

Could you give a short example of what you are referring to in your last
paragraph? I showed this to several friends and got several 'views' as
to what is intended.


I assume you are NOT intending to use third party programs to write code
in but rather to use Python somehow?

I assume you are intending that the editor add the backslash newline at
appropriate places without causing a word or code break when needed
and simply wrapping with indent without breaking the code the rest of
the time and doing so in such a fashion that ALL general text editors
will be able to display code properly as well as be usable in modifying
code?
Not to mention that the interpreter and/or compiler will still be able
to use the file.


Steve
 
A

Arnaud Delobelle

Tobias Weber said:
David Robinow said:
(define-key key-translation-map [?\M-3] "#")


or, if you prefer, just be sick.

Thanks, but I don't believe using releases from people who think I jump
should through hoops just to make my keyboard work is a good plan for a
relaxed future. According to their release notes this was (once) fixed
years ago.

No need for editing .emacs.

Click 'Options' on the menu bar, hover down to the 'Option Key >' item,
then select the 'Meta & British' option. This is IMHO the best option
(if you have a UK keyboard, of course!). This way, Alt-3 gives you a
'#'.

It would be a shame to abandon Aquamacs just for this, they have made a
lot of efforts to make it integrate well with OSX and I think this is
one of the few hurdles that are left.
 
M

MRAB

norseman said:
=======================
Paragraph 1: 65 and 72 cols are US typewriter standard 12 and 10 pt
respectively. (MSDOS screen, business standard paper, ..)
And yes, soft wrap does. Check the hardcopy which wraps
code with lots of long lines.

Paragraph 2: Comments? I vote no. These are in the code and should
conform to helping at that location.
Doc_stuff - I vote yes. For the obvious reason that it
makes formating the Docs easier AND is to be 'extracted'
to a separate file for that purpose in the first place.

Paragraph 3: True

Could you give a short example of what you are referring to in your last
paragraph? I showed this to several friends and got several 'views' as
to what is intended.
I think he means something like:

# 65 and 72 cols are US typewriter standard 12 and 10 pt respectively.

when wrapped to 40 gives:

# 65 and 72 cols are US typewriter
# standard 12 and 10 pt respectively.

and when rewrapped to 60 gives:

# 65 and 72 cols are US typewriter standard 12 and 10 pt
# respectively.

Indentation of lines wouldn't be affected, so:

# 65 and 72 cols are US typewriter standard 12 and 10 pt
respectively.

when wrapped to 40 gives:

# 65 and 72 cols are US
# typewriter standard 12 and 10
# pt respectively.

and when rewrapped to 60 gives:

# 65 and 72 cols are US typewriter standard 12 and
# 10 pt respectively.
 
S

Simon Brunning

2009/5/10 Tobias Weber said:
(still not gonna use software that doesn't let me type # because it's
alt+3 on a UK layout; having to re-learn or configure that is just sick)

To use Aquamacs with a UK keyboard, you want to select Options, Option
Key, Meta & British. Things just work then.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top