25

magick convert *.png -trim -background none -resize 300x300 -gravity center -extent 300x300 out/processed.png

vs

magick convert *.png -trim -background none -resize 300x300 -gravity center -extent 300x300 out/processed.png

I think the first one is strange because it's not inline. Using the backticks seems more natural to me if it's something used in the middle of a sentence. It may also look strange because IDEs typically don't wrap.

Is there a consensus on this already? Which is generally preferred?

2
  • 29
    I personally would put it in a code block instead of inline code. Jun 2, 2017 at 14:19
  • 1
    On an ipad no scroll bars are displayed so it isn't at all obvious that the second one continues after -extent Jun 4, 2017 at 16:47

2 Answers 2

52

For a *nix command line it makes the most sense and is the most readable, in my opinion, to put it in a code block and use a \ line continuation to break it into readable length lines. Horizontal scrolling on these long single lines make them very difficult (for me) to grasp when you can't see the whole thing.

magick convert *.png -trim -background none \
    -resize 300x300 -gravity center \
    -extent 300x300 out/processed.png

This can even be pasted.

6
  • 1
    Is the code runnable like that or would people need to take the slashes back out?
    – BSMP
    Jun 3, 2017 at 2:17
  • 9
    @BSMP: Yup, you can copy/paste that right into a bash shell.
    – genpfault
    Jun 3, 2017 at 2:18
  • 13
    On Windows the equivalent would be ^ in cmd and ` in power shell. Jun 4, 2017 at 15:28
  • If this was cross platform it would be perfect. I guess you could manually wrap it without the line continuation mark and just make a note... Too bad.
    – user736893
    Jun 5, 2017 at 13:55
  • 2
    @RatherNotsay I don't think cross-platform compatibility is really a huge concern.... Most answers will be written with a single platform in mind anyway, and it's not exactly difficult to reformat the `\`s on the very rare occasion that you need to copy+paste to Windows etc.
    – Tom Lord
    Jun 7, 2017 at 13:03
  • @RatherNotsay If this were cross platform, the platforms would be perfect. The code is fine. Non-adherence to standards is the problem. ;)
    – Almo
    Jun 8, 2017 at 12:50
39

The inline backticks are more for distinguishing references to code within the context of an English sentence (such as object names and function names). For example, a C# List has a more specific meaning than just the actual word "list" and therefore needs formatting when talking about it.

Any actual code deserves a code block, even single-line fix to the code. For example, there could be an error in FunctionFromMcve that needs to add a single line of code:

var solution = this; //This is actual code and needs to be in a code block

I personally consider command line things "code" that deserves a code block. So in your example I would use a code block for the entire command, but inline formatting if specifically discussing magick convert syntax with English instead of code.

1
  • Agreed and nicely put. Thanks.
    – user736893
    Jun 2, 2017 at 14:34

You must log in to answer this question.