Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Should StringBuilder.appendNewline append the platform’s newline instead of '\n'? #369

lucaswerkmeister opened this Issue · 5 comments

3 participants


I would expect StringBuilder.appendNewline to append operatingSystem.newline instead of a hardcoded \n – otherwise, what’s the point of the method, besides being slightly more verbose?


@lucaswerkmeister this isn't as simple as it may at first appear because a multiline string literal like this

value s = "foo

uses \n. So changing StringBuilder.appendNewline() would make it inconsistent with that, and people will end up with output including a mixture of \n and the OS newline when they intermix appending multiline String literals with appendNewline().


Interesting… I would’ve expected it to keep the line endings of the source file. In that case, you’re right, that would lead to inconsistent output.

In that case, maybe add a PlatformStringBuilder or something that converts the line breaks in all appended strings?


I would’ve expected it to keep the line endings of the source file.

Well people rarely think about those since they're (usually) invisible. If you do that you get inconsistent output too because the developer of module A uses windows and the developer of module B uses linux and the poor author of module C is left annoyed/confused.

Doing as you suggest is not ideal either for the same basic reason: The author of module C doesn't know whether A's strings will have \n or OS newlines (or whether that might change in the future) and has to defend against the possibility that the newlines are not what they want/need. (The only difference is the authors of modules A and B have at least consciously made a decision, maybe). However, not providing a PlatformStringBuilder or equivalent doesn't prevent that from happening anyway. Basically we're damned either way.

We could make it appendNewline(useOsNewline=true), or StringBuilder(useOsNewline=true), but I'm not sure those are better.


If you do that you get inconsistent output too

Yeah, I didn’t mean that that would solve the problem, it’s just what I thought would happen.

And you’re right, converting the line breaks in StringBuilder is useless if that string is used somewhere else… it really only makes a difference when strings enter or leave Ceylon, so maybe it would make more sense to have toplevel helper functions to convert platform line breaks to \n and the other way around, and then possibly additional arguments to print etc. to use these functions? That way, inside your program’s main logic you can always use \n and basically just forget about it.


I would’ve expected it to keep the line endings of the source file.

I don't think this would be a good thing. I don't think the behavior of the program should depend on such a thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.