Yes it is elegant for the compiler/interpreter or the person who has been socialized to understand the code. The brain unconsciously looks for characters not spaces or more correctly the lack of characters. This all happens before our conscious mind becomes aware of it. That is why we can spend some time looking for errors related to identifier casing long after we become used to the fact that a programming language is case sensitive.CIB said:While I do see your point and agree with you for the most part(How often has my code gone bad because I didn't de-indent right after a 2 pages long block?), I'd be careful not to generalize on this. Indentation *helps* recognize meaning, and once you are used to a specific indentation style, your brain will be able to recognize the meaning immediately without further indicators(as long as the blocks don't span more than one page ^^).shadow skill said:These sorts of suggestions on the part of OODBMS advocates remind me of the suggestion by Python programmers that syntactic indentation is a good thing because it makes programs more readable. This is laughable when you realize that giving a character that is invisible to the human eye meaning is one of the dumbest things a person can do. The human brain doesn't care about white space the subconscious discards white space because our brain is interested in deriving meaning from context more so than structure.
At this point, using indentation exclusively might indeed make your code more readable. I think there are quite many similar phenomenons in language. So, yes, it will be harder to understand the first time, just like for someone who's learning a foreign language elliptic sentences will be harder to understand, but once you have a grip on the language, it might actually be used to make the language more concise and elegant.
The first language I've mastered(simple game making language) uses syntactic indentation, and I think it's put to quite good use there.
(Code sample moved to paste-bin due to ontological.. er, technical problems. http://paste.pocoo.org/show/307430/ )
Imagine having to put an end-tag after every definition. Would look quite ugly, wouldn't it? For a language that mixes code and data, syntactic indentation seems to be an efficient and aesthetic solution, though languages like python are a whole different story.
The problem is that in the case of whitespace imparting meaning or casing schemes the conscious mind has to fight the unconscious mental processes that make reading possible in the first place. To be honest with you I would rather deal with the ugliness of having to explicitly end a statement then gamble that every possible statement/complete sentence in a language is going to be contextually clear enough that using whitespace to impart meaning is not going to become a problem.
My main concern with my previous remarks is not the machine or but the human beings who read code and the fact that the overwhelming majority of human beings have not been socialized to interpret formatting in the ways that your code snippet and Python require and instinctively parse characters rather than the lack of characters. While one could argue that it is fine once you learn how things work, such an argument does not answer the issue of why we bother to create abstractions like this in the first place.
Incidentally I think that part of the reason that Python became so popular in spite of its' ridiculous choice with respect to denoting blocks is that it was developed to teach people programming. The creator has therefore been able to socialize scores of people such that they do not even realize the stupidity of this particular design choice. Ironically when people first start programming they typically do not indent their code the reason being that the beginning student is most concerned with the characters on the screen the only thing that is meaningful to him or her. (Unless we are talking Python or Brainfuck.) Really the "elegance" of using whitespace is kind of like saying that it is more elegant to just type each sentence of this post on a new line instead of using a punctuation because humans eventually learn how to pickup on what is and is not a complete thought even without punctuation.
]I am reminded of a talk by one of the designers of Scheme where a few minutes in he states that mathematical notation is terrible because identifiers can only be one letter and the value of the identifier can change across an equation or the notation hides entire steps from the reader.
I'm sure mathematicians find their notation beautiful, but I can tell you from personal experience that I cannot understand any of it when I look up something related to programming that has a direct mathematical analogue. I always find myself wondering how they computed a specific value or what is the rule that governs a specific operation. But then again I am weird, I can eventually pick up a concept in a programming language after much cursing and head banging but math still confounds me.
I think we often get trapped in thinking about designs aesthetically instead of in a more pragmatic way because just like an architect, those of us who enjoy programming like to sit back and admire our work especially when it is completed. Take Lambdas/Closures for example. I prefer to write anything that needs to be iterated over using this technique when it is available in the language I happen to be using. I think that the for/foreach construct is ugly in comparison. Despite my own feelings towards the technique it is probably a better idea to use a traditional for loop in something like C# where Lambdas/Closures are new functionalities. (That said I'm still going to be using them where ever I can.