Skip to main content
added 2 characters in body
Source Link
gnasher729
  • 49.4k
  • 4
  • 71
  • 137

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. You could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment char *p = “/* */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

Wouldwould first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters. And then it is changed to

/*
let p = “/*”     // */
*/

Swift has an additional funny feature where strings can contain expressions. Which can contain comments.

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. You could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment char *p = “/* */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

Would first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters.

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. You could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment char *p = “/* */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

would first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters. And then it is changed to

/*
let p = “/*”     // */
*/

Swift has an additional funny feature where strings can contain expressions. Which can contain comments.

added 2 characters in body
Source Link
gnasher729
  • 49.4k
  • 4
  • 71
  • 137

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. YYou could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment charp = “/ *p = “/* */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

Would first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters.

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. Y could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment charp = “/ */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

Would first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters.

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. You could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment char *p = “/* */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

Would first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters.

Source Link
gnasher729
  • 49.4k
  • 4
  • 71
  • 137

Some problems in Swift (and likely elsewhere)

Assume you have a source file containing X C Y. Y could delete C giving X Y, or comment it out giving X /* C */ Y. You’d hope that the two resulting programs are identical (except for line numbers). We call C “commentable” if all three versions compile, and the last two have identical semantics.

Clearly code that is “commentable” can be removed by surrounding it with /* */ and code that isnt commentable can’t. Not all code is commentable, for example code with partial block comments.

Like C, Swift has some special rules. Block comments don’t count after // or after /* in a string. But the */ in the c code

/* Comment charp = “/ */“;

ends the comment leading to an error. In Swift it would be the start of a block comment.

It’s tricky. I’d want an editor feature where I can select code that I want to remove, then the editor modifies it without changing the semantics to make it commentable, then adds /* */. For example

let p = “/*”

Would first be changed to

let p = “/*”     // */

which has the same semantics but matching comment delimiters.