• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sybex 829 errata? Textblocks. how is \s = 2 spaces in Textblock or String?

 
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:
From Boyarsky Ch 1 page 33
(A marshal does not like me posting screenshots so I have to describe it)
In the table, it says \s is:
String:
Two spaces (\s is a space and preserves leading space on the line)
Textblock:
Two spaces

But when I run this test program, I see only one space between the guards.



Output:

*** ***



 
Bartender
Posts: 3915
43
  • Number of slices to send:
    Optional 'thank-you' note:
Please check the JEP:  https://openjdk.org/jeps/378
Specifically this part:

Escape sequences aren't translated until after incidental space stripping



So, first the space literal is stripped, making ******, then \s inserted, which gives *** ***
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Mikalai Zaikin wrote:Please check the JEP:  https://openjdk.org/jeps/378
Specifically this part:

Escape sequences aren't translated until after incidental space stripping



So, first the space literal is stripped, making ******, then \s inserted, which gives *** ***


Thank you. But why does the book say 2 spaces when there is exactly one space in the final output?
 
Mikalai Zaikin
Bartender
Posts: 3915
43
  • Number of slices to send:
    Optional 'thank-you' note:
Sorry, I don't know what the book says, I explained the code behavior.
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Mikalai Zaikin wrote:Sorry, I don't know what the book says, I explained the code behavior.


Unfortunately, I cannot post a screenshot because Campbell said it is not allowed to post any screenshots on this forum.
 
Marshal
Posts: 4525
572
  • Number of slices to send:
    Optional 'thank-you' note:

Anil Philip wrote:

Mikalai Zaikin wrote:Sorry, I don't know what the book says, I explained the code behavior.


Unfortunately, I cannot post a screenshot because Campbell said it is not allowed to post any screenshots on this forum.


If I had the book, I would transcribe the text from the printed-page/image and post it here.
 
Master Rancher
Posts: 4905
74
  • Number of slices to send:
    Optional 'thank-you' note:

Anil Philip wrote:In the table, it says \s is:
String:
Two spaces (\s is a space and preserves leading space on the line)
Textblock:
Two spaces


Hmmm.  I hope the table doesn't talk about "String" and "Textblock" as if they are two different things.  A text block is an expression that produces a String - an expression that begins and ends with """.   A String literal is another (older) expression that produces a String - an expression that begins and ends with ".  It's not like one is a String and the other isn't.  One is a text block, and the other is a String literal.

Aside from that...

String:
Two spaces (\s is a space and preserves leading space on the line)


Assuming this is for a String literal... this doesn't make sense.  A String literal doesn't worry about preserving leading spaces.  It's two spaces, because the "\s" is one space, and the " " is another space.  That's it.

Textblock:
Two spaces


Is there no explanation given here?  It's simply not true.  Further, the text block is the one that actually needs an explanation, more than the String literal.  Did they really omit an explanation here?  Or did you leave it off?

The correct explanation would be that the initial "\s" is one space, because the escape sequence \s preserves leading or trailing spaces.  But the subsequent " " is not a space - not one that makes it into the String, that is - because " " does not protect against trimming of leading or trailing space on the line. And this is, in fact, trailing (not leading) space on the line where it appears.

I have the feeling this is all irrelevant if the book was misquoted, but let's try anyway...
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Ron McLeod wrote:

Anil Philip wrote:

Mikalai Zaikin wrote:Sorry, I don't know what the book says, I explained the code behavior.


Unfortunately, I cannot post a screenshot because Campbell said it is not allowed to post any screenshots on this forum.


If I had the book, I would transcribe the text from the printed-page/image and post it here.


I am unable to see what the problem is, in including screenshots, to show an issue clearly.
 
Marshal
Posts: 28258
95
  • Number of slices to send:
    Optional 'thank-you' note:
When I use this code instead: (note the spaces inserted after \s)the same output appears:

*** ***

As far as I can see this is consistent with what Mikalai already posted. And versions of the code which don't include \s result simply in ******, which I believe is also consistent. And it agrees with what Mike just said too.
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Paul Clapham wrote:When I use this code instead: (note the spaces inserted after \s)the same output appears:

*** ***

As far as I can see this is consistent with what Mikalai already posted. And versions of the code which don't include \s result simply in ******, which I believe is also consistent. And it agrees with what Mike just said too.



But why does the book say "Two spaces" ?
 
Ranch Hand
Posts: 55
1
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

Anil Philip wrote:But why does the book say "Two spaces" ?



I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s. At least the comment for the String part mentions that "leading space".
The space escape sequence is just one whitespace by itself.

The book wrote:_\s  - Two spaces (\s is a space and preserves leading space on the line)

 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Ira Go wrote:

Anil Philip wrote:But why does the book say "Two spaces" ?



I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s. At least the comment for the String part mentions that "leading space".


No, The cord is not from the book. I wrote the code to test out what the book was saying. There is just a table in the book that says "two spaces" which I quoted.
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Anil Philip wrote:
No, The cord is not from the


Correction. code
 
Mike Simmons
Master Rancher
Posts: 4905
74
  • Number of slices to send:
    Optional 'thank-you' note:
I note that in that page about not posting images, the first thing it talks about is how users need an extra step to download images, which many users are reluctant to do.  That doesn't seem to describe the current user experience.  Updating the answer to skip that part might make the overall answer more convincing, since there are other, better reasons given later on, but the first reason given doesn't make much sense anymore.

Ira Go wrote:

The book wrote:_\s  - Two spaces (\s is a space and preserves leading space on the line)


So is this  in the part labeled String (or String literal maybe), or text block?  Anil previously showed this as the explanation under "String", but the question is why they talk about two spaces under "text block".  If indeed that's what the book says...

I wonder if the book was talking about a slightly different situation, if you have \s followed by something else?

Now the "\s " part is two spaces.
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Mike Simmons wrote:I note that in that page about not posting images, the first thing it talks about is how users need an extra step to download images, which many users are reluctant to do.  That doesn't seem to describe the current user experience.  


If the marshals say it is fine to include screenshots, then I will be happy to do so.
1) Other marshals (Jeanne Boyarsky) have plainly said in an earlier thread that it is fine to include screenshots.
2) Every technical forum I know (and non-technical ones like Reddit) allow you to post images.
3) If it is really an issue to post a screenshot, then why have the "attachments" feature at all?
 
Mike Simmons
Master Rancher
Posts: 4905
74
  • Number of slices to send:
    Optional 'thank-you' note:
I wonder how much effort has been spend trying to change the policy, when one could have simply typed the text for more clarity?
 
Paul Clapham
Marshal
Posts: 28258
95
  • Number of slices to send:
    Optional 'thank-you' note:
The key part about the "policy" here is, people are posting screenshots which contain text and code. That means that anybody else who wants to work with that code has to retype the code, with all of the errors which might arise from that. So that's an impolite thing for a poster to do, making everybody else retype the code when they could just have copy-pasted it into a forum post.

Notice also that the "policy" doesn't say "No screenshots". It's here: The page in question. It says "Post Text Not Screenshots" and goes on to explain why screenshots can be Not Nice. I don't think it's too much to ask, that. I also think it's not hard to understand.
 
Paul Clapham
Marshal
Posts: 28258
95
  • Number of slices to send:
    Optional 'thank-you' note:

Mike Simmons wrote:I note that in that page about not posting images, the first thing it talks about is how users need an extra step to download images, which many users are reluctant to do.  That doesn't seem to describe the current user experience.


It's true that the days when people set their browsers to save bandwidth by not automatically downloading images are long gone.
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

Paul Clapham wrote:The key part about the "policy" here is, people are posting screenshots which contain text and code. That means that anybody else who wants to work with that code has to retype the code, with all of the errors which might arise from that. So that's an impolite thing for a poster to do, making everybody else retype the code when they could just have copy-pasted it into a forum post.

Notice also that the "policy" doesn't say "No screenshots". It's here: The page in question. It says "Post Text Not Screenshots" and goes on to explain why screenshots can be Not Nice. I don't think it's too much to ask, that. I also think it's not hard to understand.



But sometimes screenshots are unavoidable. I think from all my earlier posts on JavaRanch, you will agree that I do not do what you mentioned above.
I always post code separately unless it is to show a symptom in the IDE UI.
In this thread, I copy-pasted the table exactly (I have the e-book) but obviously it isn't enough.
In the other thread where Campbell told me to not use screenshots, I think it was important to include it http://www.pmsas.pr.gov.br/wp-content/?id=coderanch-1z0-809&exam=t/780937/certification/certification-exam
The screenshot lets people clearly see what the problem is ("a picture is worth a thousand words").
But further, I also described the steps I took to see these two exams. There is no link to "search results".
Just having a link is also of no use to those who do not already have an Oracle account as it would be behind the "wall" and not a link for public access.

I humbly suggest the policy is being enforced incorrectly.
 
Ira Go
Ranch Hand
Posts: 55
1
  • Number of slices to send:
    Optional 'thank-you' note:

Anil Philip wrote:No, The cord is not from the book. I wrote the code to test out what the book was saying. There is just a table in the book that says "two spaces" which I quoted.


Anil, to test that out, you need something before the \s character. In the example from the book (from the table), there is a whitespace before the \s which is very hard to detect as it is in a borderless table. Here is how to see those two spaces:

The first line will print only \s character (one space). The second line will print the space before the \s and then the \s itself as the second white space  (two spaces).
Notice that the leading spaces are removed from text block as incidental. That is why you need something to start the text to see what \s will do. The trailing spaces are also removed.
The example from the book is very confusing.
 
Ira Go
Ranch Hand
Posts: 55
1
  • 2
  • Number of slices to send:
    Optional 'thank-you' note:

Mike Simmons wrote:
So is this  in the part labeled String (or String literal maybe), or text block?  Anil previously showed this as the explanation under "String", but the question is why they talk about two spaces under "text block".  If indeed that's what the book says...

I wonder if the book was talking about a slightly different situation, if you have \s followed by something else?



The book has a borderless table called "Text block formatting".
                                               
Formatting     Meaning in regular String     Meaning in text block
 \s     Two spaces (\s is a space and preserves     Two spaces
      leading space on the line) 

It is not the best example to explain what \s does in text blocks. There is a much better explanation in the link provided above

Escape sequences aren't translated until after incidental space stripping, so \s can act as fence to prevent the stripping of trailing white space. Using \s at the end of each line in this example guarantees that each line is exactly six characters long:

The \s escape sequence can be used in text blocks, traditional string literals, and character literals.

 
Mike Simmons
Master Rancher
Posts: 4905
74
  • Number of slices to send:
    Optional 'thank-you' note:
Thanks, Ira.  Combining that with your previous statement

Ira Go wrote:I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s.


It... sort of makes sense.  Except not really.  First, it seems Anil saw it as a space after the \s, while you saw one before.  Moreover, whether it ends up as one space or two (or more) in a text block would depend entirely on whether there is any other non-whitespace,  text either before or after.  Which seems to be information entirely lacking from the presentation.  I'm not sure there's anything useful to salvage from that table - they would have been better to leave it off entirely.
 
Anil Philip
Ranch Foreman
Posts: 626
2
  • Number of slices to send:
    Optional 'thank-you' note:

Mike Simmons wrote:Thanks, Ira.  Combining that with your previous statement

Ira Go wrote:I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s.


It... sort of makes sense.  Except not really.  First, it seems Anil saw it as a space after the \s, while you saw one before.  Moreover, whether it ends up as one space or two (or more) in a text block would depend entirely on whether there is any other non-whitespace,  text either before or after.  Which seems to be information entirely lacking from the presentation.  I'm not sure there's anything useful to salvage from that table - they would have been better to leave it off entirely.



Sigh. All this long-drawn out discussion, confusion and effort could be avoided with one simple screenshot.
This sentence came to mind while on a walk: Do not enforce the 'letter of the law' without also taking into account the 'spirit of the law'.

@Jeanne to add - it would be good if you, or your publisher can give out free copies of your books to the moderators and regular helpers of this forum (e.g. Mike Simmons),
since they are in effect, performing a valuable support role for your books by answering questions from them. (Since they said they do not have your books, it is hard for us to be on the same page)
The table above could have the text elements with shaded borders so we can see the spaces clearly..
 
author & internet detective
Posts: 41905
909
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
First of all, there is not a ban on screenshots that I'm aware. That link doesn't say you screenshots are banned. I've seen screenshots around the ranch. I've seen a bunch wehre people posted a screenshot of the online mock exam questions when they were broken. It is *preferred* to post text in many cases. For example, people can copy/paste your code to try stuff/help. In this case, a screenshot would have been just fine.

As far the actual question, Ira has it right. The book has a space followed by a \s in that table. The description explains two spaces and even writes in parens that it is preserving the leading space on the line. We knew it was going to be hard to see and that's why wrote that in parens.
 
Mike Simmons
Master Rancher
Posts: 4905
74
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
Sorry, Jeanne, but I think this still doesn't make sense.  If you put " \s" in a text block anywhere that leading space stripping would occur (i.e. at the beginning of a line that's not already protected from stripping by another line with less indentation), then the "\s" does not prevent any space stripping before the "\s".  It will preserve any spaces after that, sure... because it's no longer leading space; that's the point.  But space before the \s, that will get trimmed.

For example:

The String str has only one space before "Hello" - regardless of how many spaces there are in the source code, in front of the \s.  It all gets stripped out.

Alternately, if you create an example that puts " \s" inside a text block in a location where leading space stripping would not occur, then yes, it would count as two spaces... but in that case, what does leading space stripping have to do with the explanation?

E.g.

is exactly equivalent to

because after the first line sets the minimum indent level, the subsequent lines use that, and their additional indentation is not stripped.

This is more readably rendered as

So there's seldom a need to use \s to protect leading spaces.   As long as you don't mind a final newline, you can use the terminal """ to set the indent level for everyone else, and voila, it's readable!

You know, there is a place you can put " \s" such that the \s actually does something useful (that you couldn't get from "  ").  And that's at the end of a line.  Perhaps that's what this table in the book was supposed to be about.  In which case the "\s" is useful because it protects trailing spaces.  E.g.

has no trailing spaces (no matter how many I put at the end of the line, that you can't see).

But

This has exactly 6 characters on each line.  Because each \s is one space, and it's protecting the other spaces in front of it, which otherwise would have been trailing spaces.

So perhaps the explanation should have talked about protecting trailing spaces?  Or should have given an example where it was more clear that leading or trailing space stripping would actually occur?
 
Jeanne Boyarsky
author & internet detective
Posts: 41905
909
  • Number of slices to send:
    Optional 'thank-you' note:
I stand by my point. I agree it doesn't make  a difference in your examples. But it can.


My is indented compared to the other lines. Granted the \s doesn't buy you anything that a regular space doesn't here. But the example is just one space and one \s. So it would be more like this pointless text block:

 
Mike Simmons
Master Rancher
Posts: 4905
74
  • Number of slices to send:
    Optional 'thank-you' note:
Hmmm... so yes, " \s" represents two spaces in a text block, as long as you use it in a place where no leading space stripping is occurring.  In which case, the \s is not preserving anything - so why say that it preserves leading space on the line?  The \s could have preserved leading space after it, or trailing space before it, if it were used in a place where that was actually occurring.  But since none of that is happening, the \s is just a space.

The region marked by X's is where leading spaces are being stripped.  The region marked by Y's is where spaces are not being stripped - I believe that was the point of your example, right?  And the Z's mark where the " \s" falls in this discussion.  So nothing is being protected here.

Anyway, I can see why Anil was confused by this, even if he was wrong about whether the space was before or after the \s.
 
Jeanne Boyarsky
author & internet detective
Posts: 41905
909
  • Number of slices to send:
    Optional 'thank-you' note:
Yes, i understand the confusion. And I agree in your example the \s could have been a normal space. That example didn't come from the book of course
 
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |