Ideas to Decrease Unformatted Code

#1

I’ve been using the forum for a while now and one thing I’ve noticed is that new users don’t always format their code. I personally think this is because people don’t know how and not because they don’t want to. It often makes it hard to read particularly for longer chunks of code.

I have a couple ideas on how this could be improved. I don’t know how easy they would be to implement but I thought I’d throw them out there.

  1. Have new topics created under coding questions sections include a section for the for copy and pasted code at the bottom by default.
    • This could be included in all posts if there was a filter that would remove any code block that had the default type or paste code here text in it.
  2. Include a checker that runs when create topic is pressed if it detects keywords like setup(), draw(), or any () {} outside of a code block it would have a pop up asking if you have formatted your code and telling you how to do it if you don’t already know.
  3. Have the popup that comes up when you create your first topic on the forum mention how to format code. (It might already do this but from what I remember it just said to read the guidelines which I don’t think too many people do)

Also found this old topic related to this topic.

4 Likes
#2

like a default content for new thread:


system : hardware:

system : OS:

processing version:

loaded libraries:

problem description:

your code as a runable version but reduced to the point of question, see MCVE

// paste in here:

#3

Solving this problem would be great. At present I believe that our solution is primarily… me. I wait a few days, then I catch (most) old posts that haven’t been edited and edit them, correcting their code formatting and adding the edit message

please format code with </> button

Even when asked repeatedly to edit their post by other forum members… very few new users actually do the edit. They just ignore the request, or fail to understand it, or they re-post their code and edit the repost rather then editing the first post. A common response is “okay, I’ll do that next time.” For some I think their paradigm for posting to a conversation is Twitter / Snapchat / Instagram, and the whole idea of editing the original thing rather than reposting somehow doesn’t sink in.

This leads me to believe that if somebody wants to work on a solution, the automagic code block detector (#2) is the way to go.

Any additional form elements – even simple ones – probably aren’t going to be used correctly by the users who already can’t find the edit button or can’t use a code format button when given clear directions, so it won’t solve the problem. Keep in mind that our audience includes children and people who are already not very good at using the browser on their laptop or cellphone. A popup also will probably not get good results – although I’m not opposed to it, I just suspect it is not worth development time.

1 Like
#4

I took a quick look around, and I’m not seeing automagic inline-code-block detectors out there for discourse, or any other major forum platform. Possibly because it is a hard problem – especially given that some of our example code submissions will be malformed (errors, but also bad pastes that are missing ending brackets etc.) We could try writing a custom something just for detecting Java / Javascript, to start – I can start to imagine what a detector would look like – but it sounds like it might be pretty thankless (and easily broken when the platform changes).

2 Likes
#5

I looked into a bit more and it looks like it would be possible to create a plugin for discourse that works off regular expressions. I might try to work on it a bit but I probably won’t have enough time to really get into it for a couple of weeks.

1 Like
#6

yes, but how about my idea to have a ready code section
in every new thread already ( so no need to understand/use the “menu”)
the above shown structure for a new opened thread is similar to the
github open issue template.

but i was unable to find a proper “discourse” manual about if a
“new thread template layout”
is possible.

1 Like
#7

this really needs to be sorted out. also maybe adding a homework board would be worthwhile.

#8

here i see that my idea of a FORM might be possible even for each category different…

so it would be 5min for the forum admin to test a form like with the
code section included:

```
your code PASTE in here
```

and if that does not work,
can again think about @figraham enforcement checker code

1 Like
#9

@kll – this sounds worth trying – it would save me a lot of work – but I don’t have permissions to edit categories and add a template. I think (?) only @fjenett does.

To apply this template to all new topics posted in this category, go to a category, click “Edit” and find “Topic Template” in the top menu.

#10

Why not copying GitHub as an easy temporary fix ?

When you add an issue you have your post already pre-filled whith explanation on how to write a good post.

Maybe it is possible to do the same but simple to write “be careful and format your code.”

#11

Sure, absolutely. Either a paste-in or a reminder to format is fine – we could try them both and see which works better. But they are both category templates – only @fjenett can actually edit them.

1 Like
#12

Hey, yes i think this should be possible through “Topic Templates” … will further investigate.

1 Like
#13

Not sure if templates would do the magic here. I have seen in other forums that most people will skip or delete the template through their copy&paste workflow. It will help nevertheless.

I do believe some discipline is needed when posting in the forum. After all, a little bit of effort from the OP could save time to all those ppl that want to help. There is nothing unreasonable about this request. I have been involved in the campaigns to preach this in previous times and it is time consuming. This is my concept:s: You receive help only after you follow the guidelines.

Having a bot to do the auto-formatting seems to be the future beside the many iterations to get it right and the effort involved.

Kf

#14

I do agree but you would need to have everyone following the rule to not help until proper formatting and I’m pretty sure that there will always be someone to help no matter what. :confused:

#15

It would be really nice!

I do have mixed feelings because some of our new visitors aren’t adults or college level – they may be as low as early grade school, and/or have language issues. We often don’t know their background. If they are repeat visitors then yes they should learn, but for one-off beginner questions I do like to lower the barrier to help whenever possible.

3 Likes