News for hackers. Stuff that matters.
Re:Space After Periods (1993) by thaumasiotes on Tuesday July 11, 2023 @04:47PM (#36687000)
> looking back, I'm mostly amused that Guido van Rossum (the developer of the Python programming language) wanted web browsers to collapse multiple spaces to a single space after periods. Python, notably among programming languages, treats whitespace as significant.

It does so by collapsing any amount of space into single INDENT and DEDENT tokens, so I'm not sure what the irony is supposed to be. If the last line started with 8 spaces, Python will not distinguish between the next line starting with 10 spaces and the next line starting with 50.

Re:Space After Periods (1993) by simiones on Wednesday July 12, 2023 @05:47AM (#36692292)
It's a bit funny because it's actually hard to represent Python code in regular HTML, exactly because of this collapsing.

For example, here is some Python code typed correctly in the comment box but rendered without the code formatting support (using a | at beginning of line to prevent the code formatting to kick in):

|def foo(flag):

| if flag:

| print("this is indented")

| print("is this?")

If you check the HTML, it looks like this:

  <p>|def foo(flag):</p>
  <p>|    if flag:</p>
  <p>|       print("this is indented")</p>
  <p>|    print("is this?")</p>
Re:Space After Periods (1993) by distcs on Wednesday July 12, 2023 @07:41AM (#36693085)
> it's actually hard to represent Python code in regular HTML

It is not hard. Just use the right tag. You want the <pre> tag here. Here, fixed it for you:

  def foo(flag):
      if flag:
         print("this is indented")
      print("is this?")
Re:Space After Periods (1993) by pwdisswordfishc on Wednesday July 12, 2023 @05:48AM (#36692296)
Have you ever seen a nested control structure?
Re:Space After Periods (1993) by BeetleB on Wednesday July 12, 2023 @10:54AM (#36695467)
> If the last line started with 8 spaces, Python will not distinguish between the next line starting with 10 spaces and the next line starting with 50.

Perhaps I misunderstood your comment, but this is quite wrong. If I have a block that's indented at 8 spaces, and the next line is 10 spaces, but should be in the same block, it will definitely throw an IndentationError.

Re:Space After Periods (1993) by thaumasiotes on Wednesday July 12, 2023 @06:13PM (#36702390)
Yes, you've misunderstood. If the last line started with 8 spaces, Python will see a difference between (the next line starting with 8 spaces), (the next line starting with 6 spaces), and (the next line starting with 10 spaces). Option 1 does nothing. Option 2 produces a DEDENT token. And option 3 produces an INDENT token.

In the same scenario, Python does not distinguish between (the next line starting with 10 spaces), which produces an INDENT token, and (the next line starting with 50 spaces), which produces the same INDENT token. The amount of whitespace isn't relevant. All that matters is the comparison between one line and the previous line.