News for hackers. Stuff that matters.
Re:Sylph: the programming language I want by okasaki on Sunday March 01, 2015 @08:48AM (#9127014)
>If your language has braces, then you are indenting for the sake of humans (because humans are good at noticing alignment and edges), and bracing for the sake of computers. That’s double the effort for something as mundane as where a block ends. If they get out of sync, then your code naturally breaks in a way that’s very difficult for you to detect.

No, I use braces for the computer, and the computer automatically and unambiguously indents it for me.

If anything the wasted effort happens in whitespace significant languages like Haskell and Python where the computer can't tell what you want and you have to cycle through all sensible indentations (for every line!)

Re:Sylph: the programming language I want by zak_mc_kracken on Sunday March 01, 2015 @10:53AM (#9127475)
You're using a double standard, here: if the computer is good at indenting brace based languages, then it is equally good at indenting languages without braces just based on the grammar.
Re:Sylph: the programming language I want by mindslight on Sunday March 01, 2015 @11:35AM (#9127688)
Not at all. In this case, by 'languages without braces' we mean languages where indentation is part of the grammar. Python's grammar includes explicit INDENT/DEDENT tokens. It is impossible to reindent this mangled python:

    if z:
    print 'a'
    print 'b'
Re:Sylph: the programming language I want by adrusi on Sunday March 01, 2015 @12:58PM (#9128094)
Why would it be improperly indented in the first place? How is removing the indentation any different from removing braces?

Sure, when you paste code somewhere that expects prose (Facebook status updates, for example), it will consolidate consecutive whitespace and thereby remove the indentation, but you shouldn't be pasting code into a place like that anyway, because no matter what you do it'll be unreadable, and most people aren't going to be interested enough to put it into their editor to autoformat.

Re:Sylph: the programming language I want by mindslight on Sunday March 01, 2015 @01:27PM (#9128259)
I did not make the value judgment you are arguing against.
Re:Sylph: the programming language I want by mixmastamyk on Sunday March 01, 2015 @10:55PM (#9130244)
Editors know that a python line ending in a colon must be indented and so indent it automatically. It wouldn't be hard to use the same method to reindent it.
Re:Sylph: the programming language I want by unwind on Monday March 02, 2015 @02:37AM (#9130762)
No, lines following a line ending in a colon must be indented.

But the OP's point is that you can't know how many lines make up the indented block, since there is no explicit block-end-marker left if the indent is gone.

Re:Sylph: the programming language I want by balquhidder on Monday March 02, 2015 @04:09AM (#9131000)
>No, lines following a line ending in a colon must be indented.

Except if you have, for example, an if statement. if x: y() is valid.

Re:Sylph: the programming language I want by mixmastamyk on Monday March 02, 2015 @05:16PM (#9134722)
Yep, that's what I meant.
Re:Sylph: the programming language I want by seanmcdirmid on Sunday March 01, 2015 @08:56AM (#9127031)
The computer is really quite proficient at inferring block structure from indentation, and if you use a modern editor this structure is manipulated rather effortlessly.

The main problem with indent oriented languages is that not everyone is or wants to use a modern editor. Then there are LISPers who think braces everywhere are a swell idea.

Re:Sylph: the programming language I want by geocar on Sunday March 01, 2015 @09:36AM (#9127139)
> The computer is really quite proficient at inferring block structure from indentation, and if you use a modern editor this structure is manipulated rather effortlessly.

Nonsense.

Try pasting a block of Python into Hacker News and you get something that starts off like this:

import os import random def do_something(x): if x: fd = os.open(x)

and only gets worse. A language with braces/semicolons has no such problem; it is easier to communicate with others, and the absolute value of being able to communicate with others when starting a new language is exceptional.

Re:Sylph: the programming language I want by vertex-four on Sunday March 01, 2015 @09:43AM (#9127158)
> A language with braces/semicolons has no such problem; it is easier to communicate with others

If someone posts more than two lines of practically any curly-brace language as one line, it's illegible. Yes, you can pull it into an editor and fix it automatically, but it's a huge waste of time that is best fixed by simply posting the code properly in the first place.

Re:Sylph: the programming language I want by geocar on Sunday March 01, 2015 @10:03AM (#9127228)
> any curly-brace language as one line, it's illegible.

You might not be able to read it, but others can, so it is by definition not illegible.

"Indention language", on the other hand, has actually lost its meaning and therefore is illegible.

> it's a huge waste of time that is best fixed by simply posting the code properly in the first place

Helping others is never a waste of time, but telling people thy are too stupid to ask for help correctly is cruel.

Re:Sylph: the programming language I want by vertex-four on Sunday March 01, 2015 @11:11AM (#9127572)
> Helping others is never a waste of time, but telling people thy are too stupid to ask for help correctly is cruel.

Asking others politely to help you help them is not cruel in any way. If you allow a community to become a place where people can ask questions without putting any effort at all in themselves, you end up with all the people who can actually help leaving, and your community being full of people who will only ever put in the bare minimum of effort.

Re:Sylph: the programming language I want by geocar on Sunday March 01, 2015 @12:12PM (#9127864)
"Help you help them" however is only necessary in the python example because data is lost. The indention doesn't mean anything to C programmers, and thus I need no help from them to help them.
Re:Sylph: the programming language I want by vertex-four on Sunday March 01, 2015 @12:41PM (#9128013)
> The indention doesn't mean anything to C programmers

So you could read and debug a 5000-line program written all on one line without reformatting it?

Re:Sylph: the programming language I want by geocar on Sunday March 01, 2015 @12:53PM (#9128070)
What does "5000 lines all on one line" mean?

If it fits on a page I don't have trouble reading it. Line breaks tend to make it harder to fit on a page and not easier.

Example:

http://www.nsl.com/papers/origins.htm

Re:Sylph: the programming language I want by vertex-four on Sunday March 01, 2015 @01:39PM (#9128302)
You can honestly read and understand that as-is? And adding line breaks and proper indentation would make it absolutely no easier? Impressive. I don't think there's many C programmers who have that ability.
Re:Sylph: the programming language I want by geocar on Sunday March 01, 2015 @02:01PM (#9128385)
Yes I can read this, and adding line breaks would not make it easier.

In fact I think it would make it worse.

This has come up before, if you're interested:

* https://news.ycombinator.com/item?id=8476189

* https://news.ycombinator.com/item?id=8476702

It is also something I set out to learn how to do because I saw someone else do it: If someone produces smaller and faster code than me, then I should want to learn from it.

When working with others, I will often extemporise my code for their sake. I sometimes make mistakes when doing this, but sometimes making friends is more important than fast and correct programs.

Re:Sylph: the programming language I want by falcolas on Sunday March 01, 2015 @11:20AM (#9127619)
> it is by definition not illegible

illegible, adjective: not clear enough to read.

Says nothing about "others being able to read". A doctor's handwriting can be illegible to everyone but the doctor, and not be a contradiction to the definition of illegible.

> Helping others is never a waste of time

If someone cares so little as to paste unformatted code on a forum which provides simple tools to display formatted code, how much value can you really put in their ability to provide quality code? How is requiring someone else decipher something you didn't care enough to post correctly not ultimately a waste of everyone's time?

Re:Sylph: the programming language I want by restalis on Monday March 02, 2015 @10:20AM (#9132176)
"If someone posts more than two lines of practically any curly-brace language as one line, it's illegible." "...you can pull it into an editor ... but it's a huge waste of time..."

Well, I know it may sound a little bit awkward, but sometimes I just want it to see it work before looking into it, and copy-pasting curly-braced kind of code is perfect for that. So the curly-braced style solves a lot of such inside content distortions and actually frees me from a huge waste of time.

Re:Sylph: the programming language I want by gus_massa on Sunday March 01, 2015 @10:05AM (#9127236)
[Note: if you add two spaces at the beginning of each line, it will look like code:

  import os 
  import random 
  def do_something(x):
    if x:
      fd = os.open(x)
Note2: If one line with two spaces is too long, it will mess the whole thread, so if you ever want to quote use italics instead of spaces.]
Re:Sylph: the programming language I want by brudgers on Sunday March 01, 2015 @05:33PM (#9129198)
Sorry about being pedantic.

PEPpy Python should have four spaces at each level of indentation...not two.

Now I feel better

Re:Sylph: the programming language I want by zak_mc_kracken on Sunday March 01, 2015 @11:30AM (#9127663)
> Try pasting a block of Python into Hacker News and you get something that starts off like this:

You're talking about a web site that seems to have been written by web developers who don't know Javascript exists.

Any Python parser will be able to format your snippet correctly.

Re:Sylph: the programming language I want by falcolas on Sunday March 01, 2015 @11:07AM (#9127549)
It's only problematic because the comment grammar used on HN for non-code folds consecutive whitespace down to one space. Ironically, this was done to work around those who feel that text documents should be hard-wrapped at ~70 characters. If the grammar did not apply this folding, then it would be happy to preserve the structure.

If I were designing a language, its compatibility with naive commenting systems (or catering to users who refuse to use code blocks provided by most modern commenting systems) would be pretty low on my list.

Whitespace, even disregarding indentation, is already very significant to a number of modern languages. Why, then, is this particular form of significance bad?

Re:Sylph: the programming language I want by TazeTSchnitzel on Sunday March 01, 2015 @09:54AM (#9127196)
C code with whitespace and new lines stripped is equally unreadable.

You are arguing that braces should be kept so people who don't indent their code properly on HN can be understood.

Re:Sylph: the programming language I want by wolfgke on Sunday March 01, 2015 @10:06AM (#9127246)
Just put two spaces before each line (https://news.ycombinator.com/formatdoc: "Text after a blank line that is indented by two or more spaces is reproduced verbatim. (This is intended for code.)"):

  import os
  import random
  
  def do_something(x):
    if x:
      fd = os.open(x)
Re:Sylph: the programming language I want by wolfgke on Sunday March 01, 2015 @06:45PM (#9129460)
Why the downvote?
Re:Sylph: the programming language I want by Scramblejams on Sunday March 01, 2015 @10:33PM (#9130192)
Because petulant children can downvote here. It was a good comment, and I learned something from it. So thanks!

I wonder how a comment system that made downvotes public would do. And further, if the downvoter was required to give a one line justification. And further yet, if the downvote itself could be downvoted.

Oh, scrap all that. I'd like to see would happen if downvotes were eliminated entirely, so things sorted to the top purely by upvotes.

Re:Sylph: the programming language I want by agumonkey on Sunday March 01, 2015 @09:40AM (#9127153)
The only thing superior to Sexps is Forth. Mechanical syntax forever.
Re:Sylph: the programming language I want by brudgers on Sunday March 01, 2015 @11:08AM (#9127553)
A token is a token. PEPpy Python's four spaces are isomorphic to Lisp's left banana and C++'s curly brace. An ASCII <bell> would be just as well with a lexer.

White space has significance for humans. The road to the Turing tarpit is paved with human intentions. Describing computation mathematically is a solved problem. Expressing it clearly for and by humans, not so much.

Re:Sylph: the programming language I want by marcosdumay on Sunday March 01, 2015 @09:23AM (#9127101)
What's effortless is putting begin and end of blocks symbols only where they matter.

Haskell is particularly guilty of creating several different indenting possibilities, and does require constant intervention. Python is less bad, but still requires more effort than C for example.

Re:Sylph: the programming language I want by masklinn on Sunday March 01, 2015 @10:09AM (#9127260)
Er… you know Haskell's syntax is defined as braces-and-semicolons right? And the braceless-and-semicolons-free syntax is the addition of a few layout rules[0] for human convenience.

[0] https://www.haskell.org/onlinereport/syntax-iso.html#sect9.3

Re:Sylph: the programming language I want by sparkie on Sunday March 01, 2015 @12:13PM (#9127871)
The problem is the addition of "a few layout rules" turns the context-free syntax of the language into a context-sensitive one. For example, if you were to write a parser using just the information from the link you've posted, you can enter a scenario where the same piece of code pasted in two different places in a code base mean two different things.

Case in point: putting if _ then _ else on separate lines is fine, but inside a do-notation it causes problems because the layout stage inserts semicolons between the parts, and the production rules listed at the bottom of the page do not include optional semicolons in the "if" alternation. You need to indent the then/else to overcome it. This problem is fixed with a hack[0], which fortunately has no side-effects for the rest of the language, but it just shows that throwing together ad-hoc rules for parsing code, rather than well understood theory like LR parsing, is inviting room for problems.

With CFG subsets like LR/LL, every production rule in these grammars is also a valid LR/LL grammar - in other words, it's not only the entire grammar of a language that is context-free, but all the parts are too. An indentation-sensitive language is only context-free when looked at for the entire language grammar, but the individual production rules of are context-sensitive. You can't just copy and paste some code into the syntax without providing this context (by means of manually indenting the code).

[0]:https://ghc.haskell.org/trac/haskell-prime/wiki/DoAndIfThenE...

Re:Sylph: the programming language I want by marcosdumay on Monday March 02, 2015 @06:37AM (#9131385)
Yes, I know that. Currently I'm having a better result using parenthesis instead to completely escaping from the semantic blank lines. It's cleaner than using semicolons everywhere.

Anyway, Haskell is a very instructive example about how semantic indentation creates problems.

Re:Sylph: the programming language I want by seanmcdirmid on Sunday March 01, 2015 @09:35AM (#9127138)
You really have to design your language around it for it to work well. Haskell has a a lot of syntactic craziness in the name of simplicity.
Re:Sylph: the programming language I want by masklinn on Sunday March 01, 2015 @10:07AM (#9127249)
What? Haskell has a base language expressed in terms of braces and semicolons, and a relatively simple set of layout rules defining how the compiler can insert these braces and semicolons automatically.
Re:Sylph: the programming language I want by seanmcdirmid on Sunday March 01, 2015 @09:43PM (#9130053)
Right. I meant that Haskell has a whole lot of other weird syntax to consider, that make it hard to read compared to Python. It's use of indentation is not one of the problems.
Re:Sylph: the programming language I want by codygman on Monday March 02, 2015 @01:07AM (#9130534)
Charitably speaking, that is very confusing considering you responded to:

> Haskell is particularly guilty of creating several different indenting possibilities, and does require constant intervention

with:

> You really have to design your language around it for it to work well. Haskell has a a lot of syntactic craziness in the name of simplicity.

Where "it" would seemingly be indentation, implying Haskell wasn't designed around making indentation simple.

Re:Sylph: the programming language I want by gnuvince on Sunday March 01, 2015 @09:37AM (#9127148)
I like writing compilers, how do languages like Haskell and Python handle blocks-by-indentation? I figure you have some sort of INDENT token, but how do you know its width? Also, in specifying the grammar, with explicitly delimited blocks you just say `block := OPEN stmt_list CLOSE`. What about with indentation?
Re:Sylph: the programming language I want by TazeTSchnitzel on Sunday March 01, 2015 @09:55AM (#9127204)
I think they specify "INDENT foo DEDENT" and the lexer tracks indentation and issues INDENT/DEDENT as appropriate.
Re:Sylph: the programming language I want by falcolas on Sunday March 01, 2015 @10:57AM (#9127493)
This is correct. A bit of state (an indentation width stack) in the lexer creates the block boundaries as clearly for the interpreter as normal braces does.

Any problems in parsing are typically only encountered by stateless parsers.

Re:Sylph: the programming language I want by dochtman on Sunday March 01, 2015 @11:14AM (#9127585)
I have one (probably quite naive) implementation here:

https://github.com/djc/runa/blob/master/runac/parser.py#L54

(Runa uses tabs for indentation, not spaces, but it's basically the same thing.) Whitespace at the start of a line is a separate token, then I add a thin layer of processing that turns a change of indentation level (i.e. count chars in the token contents) into INDENT or DEDENT tokens.

Re:Sylph: the programming language I want by vertex-four on Sunday March 01, 2015 @08:50AM (#9127019)
> you have to cycle through all sensible indentations

What? My editor indents stuff for me as per PEP8. I don't have to think about it. Why do you?

Re:Sylph: the programming language I want by okasaki on Sunday March 01, 2015 @08:59AM (#9127038)

  def fun():
      for x in xs:
          if a:
              b
            c
There's no way for an editor to know where to re-indent c to. You have to cycle through the indents manually.
Re:Sylph: the programming language I want by nothrabannosir on Sunday March 01, 2015 @09:50AM (#9127184)
Perhaps I misunderstand, but vim, not a particularly uncommon editor, treats backspace at the start of a line by removing one indent level.

So, you're at `b`, you hit enter: next line, same indent level. Now you hit backspace: indent level matches `if`. Again: indent level matches `for`. Type c, there it is.

If you had curly braces, you'd use } instead of backspace. Literally the same number of keystrokes, no?

Or were you talking about something else and did I misunderstand?

Re:Sylph: the programming language I want by vertex-four on Sunday March 01, 2015 @09:38AM (#9127150)
How did you end up with c there, honestly? It's not a thing that's ever happened to me.
Re:Sylph: the programming language I want by seanmcdirmid on Sunday March 01, 2015 @09:03AM (#9127049)
Auto indent, tab, and shift tab are your friends. Really, it isn't that bad, considering the curly brace alternative is even worse from an effort perspective.
Re:Sylph: the programming language I want by okasaki on Sunday March 01, 2015 @09:16AM (#9127078)
To each their own. I came to C++ from Haskell and found braces to be superior (except visually).