How do we format code?



  • @Lorne_Kates said:

    I'm not learning another markup language for a shitty piece of forum software. I already barely remember BBCode and wiki.

    You forgot HTML - this is evolution on a timeline:

    BBCode ( [b] ) -> HTML ( <b> ) -> wiki ( ''' ) and now Discourse ( ** ).

    As for why Discourse had to reinvent the wheel again... dunno, it's a way to put one's stamp on the world, innit?

    @Lorne_Kates said:

    And besides, it's 2014. I mean, one of these days someone will invent a WYSIWYG editor, right?

    That would sure help, as the scrollbars in the editor and preview are not synched.

    And because the editor replaces emoticons with a small icon, it might be very helpful to see the preview of what you are posting... since the auto substitution of emoticons means you can't write (<b>) any more but to have to insert a something between the ; and the ).

    TDWTF is a coder/programmer forum; people post code here. Using an editor that interpretes that posted code and replaces it with its own substitutions is really, really bad. As bad as using the asterisk as marker for bold / italic text.

    Some C++ code with four asterisks: int x = **ptr; int y= **ptr2;

    Broken. Fundamentally.



  • @faoileag said:

    TDWTF is a coder/programmer forum; people post code here. Using an editor that interpretes that posted code and replaces it with its own substitutions is really, really bad. As bad as using the asterisk as marker for bold / italic text.

    Some C++ code with four asterisks: int x = ptr; int y= ptr2;

    Broken. Fundamentally.

    int x = **ptr; int y= **ptr2;
    

    That's one thing that isn't broken. And understandably - the editor seems to be based on the SO one, and imagine running a Q&A site about programming that doesn't let you post code. Now that's the level of insanity even Jeff hasn't reached yet.



  • @Maciejasjmj said:

    int x = **ptr; int y= **ptr2;
    That's one thing that isn't broken. And understandably - the editor seems to be based on the SO one, and imagine running a Q&A site about programming that doesn't let you post code. Now that's the level of insanity even Jeff hasn't reached yet.

    An editor for a programming site that forces me to format code I post is fundamentally broken.

    I was well aware that there would probably be some markup that would show int x = **ptr; int y= **ptr2; correctly, I only didn't look it up.

    Having done so I can't but note that even that markup is fundamentally broken because the quote sign used to preformat code has a meaning in the bash.

    Sorry, try as you might, you can't defend that editor.


  • Winner of the 2016 Presidential Election

    CS didn't properly support brackets or chevrons without escaping. The triple backtick works OK, even if it's not very intuitive.



  • You can also indent your preformated code block with 4 spaces. Which breaks even more things, but oh well.


  • Discourse touched me in a no-no place

    @faoileag said:

    I was well aware that there would probably be some markup that would show int x = **ptr; int y= **ptr2; correctly, I only didn't look it up.

    The indent one works well. There's even a button to help you with it (which looks like </> right now).

    Here, this() {
        is done with;
        that button!
    }
    

    The only indents that I typed were the ones within the code itself. If I'd been copy-pasting the code from elsewhere, I wouldn't have even had to do those. (Is there a reasonable way to say which language the code is in and so pick up the right set of highlight rules? On SO I'd use <!-- language: foobar --> when the autodetect based on question tags didn't work, but there isn't the same sort of hinting here.)


  • Winner of the 2016 Presidential Election

    function foo() {
    
    }
    
    function foo() {
    
    }
    

    Hinting seems to work OK, but I find the languages supported to be lacking.


  • Discourse touched me in a no-no place

    Ah! You're using the triple-backtick form whereas I was using the space4 indent form.


    Filed under: Markdown's an inconsistent mess



  • @error said:

    I find the languages supported to be lacking.

    tdwtf(threadID)
    n id,text,success
    f id=$o(^POSTS("thread",threadID,id)) q:id="" q:'success d
    . s text=$tr($$formatPost(id,ANSI_STD)," ","")
    . s %=$$insrtVitriol(.text) s:% success=1
    . i 'success d q
    . . w !,"WTF"
    . . k ^POSTS("thread")
    d renderPost(text)
    d complain
    q 1

    Agreed. I tried using < code > elements and had to use separate ones on each line, and the syntax highlighting is completely missing. And it totally collapsed my whitespace! This patch will never get accepted...



  • @subscript_error said:

    Agreed. I tried using < code > elements and had to use separate ones on each line, and the syntax highlighting is completely missing. And it totally collapsed my whitespace! This patch will never get accepted...

    tdwtf(threadID)
    n id,text,success
    f id=$o(^POSTS("thread",threadID,id)) q:id="" q:'success d 
    . s text=$tr($$formatPost(id,ANSI_STD)," ","")
    . s %=$$insrtVitriol(.text) s:% success=1
    . i 'success d q
    . . w !,"WTF"
    . . k ^POSTS("thread")
    d renderPost(text)
    d complain
    q 1
    

    What the hell language is that anyway?



  • One that's perfect for semi-sarcastic replies about broad syntax support. C-style languages are too easy.
    What'd you do to get it in one block? It added some coloration in random places... oh I see, it took the apostrophes as string delimiters. Makes sense.



  • ```
    Your code here
    ```


  • Banned

    def hello_world
       "hi there"
    end
    
    # no I insist its bash
    def hello_world
       "hi there"
    end
    

    We use highlight.js http://highlightjs.org/static/test.html

    To hint a language use:

    ```language
    my awesome source code
    ```


  • POST / HTTP/1.1
    X-I-Told-It-This-Was: Scala
    X-There-Might-Be-A: bug
    


  • So, to recapture, we have four ways to format code:

    1. Triple left-leaning single quote which works best if only used once:
      <b>this is not bold</b> and there is no emoticon img after this :)
      But is broken if used twice because someone seems to use regexes to parse the formatting and doesn't seem to know that regexes are greedy (I might actually submit this to TDWTF, a site that specializes in collecting such blunders).
    2. Single left-leaning single quote which can be used inline
      foobar :)
    3. 4-space indentation that does not seem to do much apart from
      indenting text :)
    4. And the </> button, which uses a single left-leaning single quote if you are past the first character but 4-space indentation if not.

    So, if I use a button labeled "Preformatted text" post-typing on an entire line it is broken because
    this is bold and there is an emoticon img after this :)

    And the knowledge needed to format code correctly (using triple left-leaning single quote) I had to get by reading comments, because there is no such thing as a help button in the editor's button bar.

    I repeat it: this editor is broken as it is for a programming forum.


  • Banned

    @faoileag said:

    I might actually submit this to TDWTF

    You know, there is another option

    Fix https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/dialects/github_code_dialect.js or its parent Discourse.Dialect.replaceBlock if needed.


  • Discourse touched me in a no-no place

    @faoileag said:

    So, to recapture, we have four ways to format code

    If you're talking about not having to use excessive quoting methods, I believe you have missed <pre>.

    Sort of (at least by what's going on in that preview window at the moment); I present two copies of <pre> ** ;) **</pre> . This first is on the same line as this text:

     ** ;) **

    However, when presented on a separate line:

     ** ;) **
    with other text after it it renders differently.

    Hey - look - context sensitive HTML. Mixed in with markdown. Sometimes. What's not to love...

    Especially on mobile where you don't even get the benefit of the preview window...



  • @sam said:

    You know, there is another option

    Fix https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/dialects/github_code_dialect.js or its parent Discourse.Dialect.replaceBlock if needed.


    Good riposte, actually ;-)

    But tempted as I might be, I won't.

    Reason 1: this is not fixing a typo like a misspelled var and I would need to fully grok the code before I started, because I would have to be able to gauge any side effects. So this is not done in a quiet moment after work.

    Reason 2: I seem to recall from the thread on the beta test that some people were pretty frustrated because they fixed things and then had their changes rejected. Which is not exactly motivating.


  • Banned

    @faoileag said:

    I seem to recall from the thread on the beta test that some people were pretty frustrated because they fixed things and then had their changes rejected. Which is not exactly motivating.

    I can assure you

    1. This never happened with any contributions that originated from TDWTF
    2. We very very rarely reject PRs, you can look through the repo and history of PRs to confirm this yourself.

    I also fully acknowledge that just getting started contributing to Discourse can be hard, and am working on ways to improve this (hoping to get a Docker dev image up at some point)



  • @sam said:

    Fix https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/dialects/github_code_dialect.js or its parent Discourse.Dialect.replaceBlock if needed.

    Having at least looked at the github code, it actually might not be Discourse that is at fault here. To quote from dialect.js: "Discourse uses the Markdown.js as its main parser."

    So it could well be that markdown.js needs to be fixed. Can't check though, since that project's example html page doesn't seem to work and I don't have the time to figure out what all I have to install where to get it to work.


  • Banned

    This post is deleted!

Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.