17

-- in a title is collapsed to . This probably isn't so great if the title contains <!-- --> or x--.

Is this intended behavior?


Running this query on data.stackexchange (I don't claim to be good at SQL):

SELECT
    sum(case when Title LIKE '% -- %' then 1 else 0 end) AS [mdash],
    sum(case when Title LIKE '% <!-- %' then 1 else 0 end) AS [comment],
    sum(case when Title LIKE '%[a-z0-9]-- %' then 1 else 0 end) AS [decrement],
    sum(case when Title LIKE '% --[a-z0-9]%' then 1 else 0 end) AS [increment],
    sum(case when (Title LIKE '%-- %' OR Title LIKE '%--- %')
              and Title NOT LIKE '% -- %'
              and Title NOT LIKE '% <!-- %'
              and Title NOT LIKE '%[a-z0-9]-- %'
              and Title NOT LIKE '% --[a-z0-9]%' then 1 else 0 end) AS [uncategorized] FROM Posts

I get the following results:

mdash comment decrement increment uncategorized
7665  34      368       1752      472

The vast majority of valid uses cases would be unaffected by Tim Stone's proposal

14
  • 3
    <!-- --> shouldn't be in titles. Titles should be descriptive about the problem, not include code snippets. Commented Aug 16, 2013 at 15:10
  • 6
    Yes, it’s intended behaviour. Yes, it’s stupid behaviour. It’s also silly inconsistent.
    – Ry-
    Commented Aug 16, 2013 at 15:13
  • 1
    @MichaelIrigoyen: What if the question is about this bug? ;)
    – Ry-
    Commented Aug 16, 2013 at 15:15
  • "Questions containing two dashes in the title collapses to an mdash"? I mean, why in the title did @Eric include -- but spell out mdash? Titles should contain words, not code, IMO. Commented Aug 16, 2013 at 15:19
  • 4
    @Michael, Manual specification of code block with <!— language: python --> fails seems like a fine title to me.
    – Arjan
    Commented Aug 16, 2013 at 15:20
  • 1
    For one, the double dash is used for -- operator Commented Aug 16, 2013 at 15:25
  • 3
    And, @Michael, so does Why is i— faster than i++ in loops?...
    – Arjan
    Commented Aug 16, 2013 at 15:26
  • 2
    What you all need — in my opinion — is a proper compose key…
    – Ry-
    Commented Aug 16, 2013 at 15:27
  • Unless I'm seeing things, in the example Arjan showed the effect only occured with the first -- in the title. Commented Aug 16, 2013 at 15:28
  • Despite some legitimate uses, it seems a lot of time they are used for [tag] --... in titles. Commented Aug 16, 2013 at 15:28
  • @BillWoodger: Yep; see regex below.
    – Ry-
    Commented Aug 16, 2013 at 15:28
  • @BillWoodger: That's because the other -- is actually a ++
    – Eric
    Commented Aug 16, 2013 at 15:28
  • 1
    Or you could add support for backtick quoted code. Commented Aug 16, 2013 at 15:55
  • As a note, I see "--" in all titles instead of an em dash on my phone's browser (BB10), confused me for a while because both looked identical in the title. Commented Aug 16, 2013 at 17:17

1 Answer 1

6

Yes, although obviously it's not perfect in that it can't detect your intent when you actually mean to have double hyphens. Titles are modified based loosely on rules from SmartyPants, which include transforming -- and --- to &mdash; (—).

The regular expression used to do the replacement is just ---?(\s), which may be considered incorrect on the grounds that most style guides frown on putting spaces around en/em dashes…but given that the trailing space is in fact a requirement here, requiring a leading one might be a reasonable way to reduce incorrect conversions (validity of including code snippets in titles aside).

11
  • 16
    How about letting people type em dashes if they want em dashes?
    – Ry-
    Commented Aug 16, 2013 at 15:20
  • I'm all for changing the regex to require a leading whitespace character
    – Eric
    Commented Aug 16, 2013 at 15:22
  • 6
    @minitech People using double minus signs as a pseudo em dash is likely a more common case than there being a legitimate reason to have them literally rendered in the title, with the notable programming-topic exceptions of having something like --i or i--, which tweaking the regex would fully address.
    – Tim Stone
    Commented Aug 16, 2013 at 15:24
  • So do I retag this as a feature-request, or what?
    – Eric
    Commented Aug 16, 2013 at 15:52
  • @Eric You could, sure. I think Jeff's counterargument on that other post is a bit weak.
    – Tim Stone
    Commented Aug 16, 2013 at 16:42
  • 3
    The real problem is that you can’t escape it, though
    – Ry-
    Commented Aug 16, 2013 at 17:10
  • @minitech: Sure, just surround it in quotes!
    – Eric
    Commented Aug 16, 2013 at 17:31
  • 1
    @Eric: But that’s yucky!
    – Ry-
    Commented Aug 16, 2013 at 17:32
  • @minitech: Hey, you're referring to the literal string '--' - seems reasonable to quote it
    – Eric
    Commented Aug 16, 2013 at 17:32
  • 2
    @Eric: But then I wouldn’t be able to make an annoyed reference to this bug!
    – Ry-
    Commented Aug 16, 2013 at 17:34
  • How about an escape way ? Commented Dec 7, 2013 at 20:21

Not the answer you're looking for? Browse other questions tagged .