-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
base: main
Are you sure you want to change the base?
Conversation
- 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
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?
|
There was a problem hiding this 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. |
There was a problem hiding this comment.
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]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
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?
// => "<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" |
There was a problem hiding this comment.
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.
"<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"; |
pull request
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