8

With several code blocks on the same question (especially heavily occurring in framework stacks), it is needed to identify the location of the code when in multiple file locations. Some frameworks even address this in their documentation, such as Ember's quickstart guide like so in the upper portion (file name in the top bar, language/markup in the upper right corner): enter image description here

Can Stack Overflow support this? I think we should.

There are several issues here:

  • code blocks already are not named or identified
  • several code blocks in the same question can become cumbersome when analyzing

Suggestions :

  • allow code blocks to be named or identified
    • such as code type
    • but also generic-name OR filename/path
  • allow the user to be able to stack them into tabs or in the current scrolling presentation view

Notes:

I don't know how to write the query to find data related to average length for any question or specific tags (here), but I think this would help justify its future necessity.

Additional Thoughts:

  • with Identifiers/markups, users can add additional markup to signify additional information such as (this is a secondary but potentially irrelevant code)
  • justification Complexity Increasing for frameworks

With great questions come great tools!

6
  • 7
    Naming code blocks sounds like a cool idea. I'm undecided about the stacking: It might have advantages when used correctly, but it could also lead to generally more code in questions which would be bad.
    – BDL
    Sep 26, 2018 at 20:04
  • 5
    // eh/you/can/already/do/this/by/adding/a/comment.png
    – user1228
    Sep 26, 2018 at 20:13
  • 25
    Newer users are already unable to cope with simply indenting a code block - naming (and tabbing) them would confuse them even more Sep 26, 2018 at 21:37
  • How many people really post that much code? Is their a breakdown or any sort of statistics? I like the idea of named code blocks as I think very people would actually use except who are really trying to get a very particular bit of information out there.
    – ouflak
    Sep 27, 2018 at 7:03
  • There shouldn't be several code blocks in the same question in the first place. It defeats the entire intent of a Minimal, Complete and Verifiable Example.
    – Ken White
    Sep 29, 2018 at 2:06
  • 3
    @ouflak Pretty much any problem with MVC requires 3 code blocks, not counting CSS or JS.
    – Chloe
    Sep 29, 2018 at 8:27

2 Answers 2

34

This would likely create more problems than it solves (or it would get used too rarely to justify having it).

  • Most posts only have single code blocks, or code blocks that are too short for this to be particularly useful.

  • We don't want to encourage users to post more when less code would do.

    We don't want users to post a ton of code when a minimal complete example of their problem would fit into a few lines.

    Of course many users also provide too little code, but this change seems unlikely to affect that problem in any way.

  • In general, you really shouldn't be spending enough time reading a post for this to be particularly useful.

    In the case of a question, you should read through it roughly once, and then head towards the answers (to provide one yourself or read what others wrote).

    In the case of an answer, you should read through it roughly once, and then incorporate it into whatever you were doing before.

  • New users already have a hard enough time understanding the UI and formatting.

Of course there are exceptions to all of this, but the above should apply in most cases.

0
17

While I think this could be a nifty idea, I worry about its intent; I could hardly call a code snippet "minimal" if we had the ability to jump between tens or hundreds of named code blocks.

5
  • 9
    I could see this being a much nicer display for JS/HTML/CSS snippets (or for similar things where you have multiple languages that all kinda work together but don't make sense as a single code block - C headers, etc).
    – Shog9
    Sep 26, 2018 at 20:30
  • 1
    @Shog9: I don't disagree fundamentally. I'm just incredibly pessimistic. Best way to stunt that pessimism is to reduce the scope in which it can be used (Stack Snippets, for example), and that'd probably be a nice feature. I've not really known/experienced C questions on Stack Overflow to be overly painful between headers and source files before, but I could be proven wrong.
    – Makoto
    Sep 26, 2018 at 20:33
  • 7
    Well... the nice thing about C is that for a small, self-contained example there's often no reason to have a header at all - which pretty much sidesteps the whole issue. But still, I've seen enough examples where someone's posting multiple files and just using headers or bold text (or... just text, and screwing up the code formatting by putting it too close to the code block...) - I think this'd be something worth keeping in mind if we ever redesign the editor to actually, y'know, support code editing in a not-crappy way.
    – Shog9
    Sep 26, 2018 at 20:36
  • 2
    Even for just two code files this would be useful. Sep 26, 2018 at 22:00
  • I think this would probably be useful for listing Winforms designer code, maybe WPF xaml / C# code too.
    – jrh
    Sep 26, 2018 at 22:12

You must log in to answer this question.

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