Skip to main content
1 of 3
200_success
  • 144.2k
  • 22
  • 188
  • 473

No, that's unreadable code and therefore not idiomatic. The typical way to generate large numbers is to use multiplication.

"Hello, World!" translates to ASCII values

< 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33 >

… which can be thought of as

10 * < 7, 10, 11, 11, 11,  4,  3,  9, 11, 11, 11, 10, 3 >
   + < 2,  1, -2, -2,  1,  4,  2, -3,  1,  4, -2,  0, 3 >

The code should therefore be written that way. The consecutive elevens can lead to a compression optimization.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ >
 +++++ +++++ + >
 +++++ +++++ >
 +++ <<<<< <<<<
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
> + . +++ . ----- - .    "orl"
> .                      "d"
> +++ .                  "!"

For readability, you should also group the increment and decrement operators in fives. I also find your comments unnecessarily verbose.

This solution uses one more memory cell than the original code. It's well worth it for the readability, in my opinion.

200_success
  • 144.2k
  • 22
  • 188
  • 473