1

The postfix operator // seems more legible when applying formatting functions or functions that provide general information about an object, like Length does.

Is it acceptable to use it in those cases?

Example code:

StringJoin[
  "Elements in Range ", n // ToString , " to ", nMax // ToString, ". Length: ", 
  Block[{}, flast = f] // Length // ToString, "."]

Or should i stick to using ToString[Length[...]]? This seems like "Yodaspeak" without the actual advantages of it.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Gladaed
  • 987
  • 4
  • 12
  • 1
    What do you mean by "acceptable"? whether it works? or whether it's a recommended practice (say, for the sake of readability)? – AccidentalFourierTransform May 28 '18 at 15:30
  • 5
    I think that this is very subjective and up to you. Personally, I would lean towards not doing this, at least not without matching line breaks and indentation. But it's really only about readability, and readability also depends on what you are used to (i.e. it's not entirely universal). So just do what you like. – Szabolcs May 28 '18 at 15:30
  • 3
    There is no clear-cut answer. It is a matter of which style you find clearer and makes the code easier to maintain. – m_goldberg May 28 '18 at 15:31
  • 4
    BTW I think that ToString@Length[...] is objectively better than ToString[Length[...]] because it reduces the number of brackets that one needs to visually match up. – Szabolcs May 28 '18 at 15:32
  • @AccidentalFourierTransform I mean whether it's Recommended practice. – Gladaed May 28 '18 at 15:33
  • @Szabolcs Your ToString@ seems way better. The bracket thing was one of the reasons i found // better. – Gladaed May 28 '18 at 15:35
  • @Szabolcs just use ToString@*Length@... and you need no brackets at all :-D – AccidentalFourierTransform May 28 '18 at 15:37
  • Yes, some people like ToString@Length@x, some others like ToString@Length[x]. I think that this is again entirely subjective. (I like the second, but there's no rational reason I can bring up. Perhaps it's just habit.) ToString @* Length @ x is not quite equivalent ... though it usually has the same effect. – Szabolcs May 28 '18 at 15:39
  • @Szabolcs I think ToString@(value) is better since it optically differentiates formatting functions and functions which actually do something to value like Length does. – Gladaed May 28 '18 at 15:50
  • 2
    I like the postfix notation as a convenient way to build an expression incrementally. After each evaluation, I can add a step with a minimum of cursor movement. – mikado May 28 '18 at 17:41

0 Answers0