Skip to content

strings - Expand concept by newline and text blocks #2941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fapdash
Copy link

@fapdash fapdash commented Apr 27, 2025

pull request

  • Add multi-line strings / text blocks (Java 15)
  • Add explanation of newlines / end of line chars, so students can understand the motivation behind text blocks

Noticed that the String concept was lacking text blocks.
While there are quite some details and intricacies to text blocks, they're not relevant for the level of detail the syllabus is aiming for, therefore it doesn't make sense to have them as an extra concept imo.
I added infos about newlines so students can appreciate the motivation behind text blocks.

Looking forward to your feedback. :)


Reviewer Resources:

Track Policies

fapdash added 4 commits April 27, 2025 17:42
- Add multi-line strings / text blocks (Java 15)
- Add explanation of newlines / end of line chars,
  so students can understand the motivation behind text blocks
@fapdash
Copy link
Author

fapdash commented Apr 27, 2025

Not sure if system dependent newlines are too much information for this concept?

I've looked at how other tracks are testing multi-line strings. Elixir uses highschool sweetheart, which asks you to print a multi-line ascii heart. but I'd rather not swap out the whole exercise.

Maybe tell the students that the system should be able to produce a "fancy" message with the log level?

logLevelMessage("warning");
=>
┌───
│   Exercism Log System
│   Level: warning
└───

Copy link
Member

@kahgoh kahgoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to get to this one! I like the addition to the about.md.

I've looked at how other tracks are testing multi-line strings. Elixir uses highschool sweetheart, which asks you to print a multi-line ascii heart. but I'd rather not swap out the whole exercise.

Maybe tell the students that the system should be able to produce a "fancy" message with the log level?

The problem with adding another task to the exercise is that it would invalidate all existing solutions. There are already something like 26,748 students who have worked on this exercise.

"<html>\n <body>\n <h1>Hello, World!</h1>\n </body>\n</html>\n"
```

For code that should work on varying operating systems Java offers [`System.lineSeparator()`][system-line-separator], which returns the system-dependent line separator string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't using the System.lineSeparator require string concatenation that comes later? I wonder if it would flow better if this section came after string concatenation. Other than that, I think it would be handy to have an example showing how to use this.

For code that should work on varying operating systems Java offers [`System.lineSeparator()`][system-line-separator], which returns the system-dependent line separator string.
This is important if you're writing to files that will be read on the same system.

To comfortable work with texts that contain a lot of newlines you can use [Text Blocks][text-blocks].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To comfortable work with texts that contain a lot of newlines you can use [Text Blocks][text-blocks].
To comfortably work with texts that contain a lot of newlines you can use [Text Blocks][text-blocks].

</body>
</html>
""";
// => "<html>\n <body>\n <h1>Hello, World!</h1>\n </body>\n</html>\n"
Copy link
Member

@kahgoh kahgoh May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the result string line looks a little strange with it all being on one line with the \n because the multi-line template is expressed over multiple lines. Perhaps we could remove it?

Suggested change
// => "<html>\n <body>\n <h1>Hello, World!</h1>\n </body>\n</html>\n"

To put a newline character in a string, use the `\n` escape code (`\r\n` on Windows):

```java
"<html>\n <body>\n <h1>Hello, World!</h1>\n </body>\n</html>\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought to assign to variable to keep consistent with the other examples.

Suggested change
"<html>\n <body>\n <h1>Hello, World!</h1>\n </body>\n</html>\n"
String multilineHtml = "<html>\n <body>\n <h1>Hello, World!</h1>\n </body>\n</html>\n";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants