News for hackers. Stuff that matters.
Re:Rust - a new programming language from Mozilla by jurre on Tuesday April 03, 2012 @08:02AM (#3792549)
Did anyone find an explanation for why they opted for brackets in favor of whitespace or a ruby-like syntax?
Re:Rust - a new programming language from Mozilla by pcwalton on Tuesday April 03, 2012 @12:43PM (#3793684)
Graydon's personal preference, and to make C++ programmers feel at home. I personally prefer whitespace-based syntax, but I'm not a die-hard either way. When designing a language, you pretty much have to pick one and disappoint somebody.
Re:Rust - a new programming language from Mozilla by xd on Tuesday April 03, 2012 @08:22AM (#3792593)
Being someone that has only ever programmed in languages that use brackets, I really, really don't get this white space thing .. it appears, to me at least to make reading code very difficult. With brackets I can scan a page of code and see the blocks of related code.

What are the advantages to using white space?

Re:Rust - a new programming language from Mozilla by jurre on Tuesday April 03, 2012 @08:26AM (#3792607)
Well it's a personal preference of course but in my opinion it actually makes code much more readable. It forces everyone to use the same conventions for indentation and it gets the 'clutter (brackets)' out of the way so you can focus on what's important, the code.

Blocks easily identified by their indentation. It might take a little getting used to but I find it very pleasant.

Re:Rust - a new programming language from Mozilla by 4bpp on Tuesday April 03, 2012 @09:49AM (#3792874)
I can't think of "forcing everyone to use the same conventions for indentation" as a purely good thing, any more than "forcing everyone to write comments in 18th-century English" would be.

Sure, you make it easier for the random onlooker to be prepared to always immediately understand what is going on, but at the same time, the programmer who writes for his own perusal or that of a small team of known others will find themselves restricted by a totalitarian scheme telling them what they can express and what they can't. The assumption that most code is written for most people to read is simply not true, and code that is intended for the masses has always been able to deal with the problem by imposing style guidelines.

Re:Rust - a new programming language from Mozilla by sanxiyn on Tuesday April 03, 2012 @09:57AM (#3792903)
I can't understand how forcing coding convention can result in "being restricted by a totalitarian scheme". We are writing in a formal language instead of English. Style is the last place you want creativity. Use you creativity to express algorithms, not brace styles.
Re:Rust - a new programming language from Mozilla by 4bpp on Tuesday April 03, 2012 @10:11AM (#3792955)
But it's not simply a matter of creativity. Apart from contentious instances pertaining to the complete omission of indentation (if (sdfg) { a; b; }), there are also occasional cases where I'd argue that semantically, you have a block, but syntactically, you don't; for instance, I've always very much favoured the approach when writing OpenGL code to indent everything between a glBegin and glEnd to separate the vertex data from the surrounding code and make it immediately obvious how objects in the scene are grouped. I think several indentation-based languages would ignore the initial indent increase here and consider the indent decrease before the glEnd to be the end of the block containing the group of statements...
Re:Rust - a new programming language from Mozilla by sanxiyn on Tuesday April 03, 2012 @10:22AM (#3793007)
Yes, that is useful. That's why Python has with statements, for example. C++ RAII or Java try-with-resources can be used similarly.

http://www.python.org/dev/peps/pep-0343/

Re:Rust - a new programming language from Mozilla by bickfordb on Tuesday April 03, 2012 @11:29AM (#3793302)
Actually, it's not as totalitarian as you imply. It's just a different way to express blocks of code. Languages which mark blocks using whitespace indentation (such as Python or Haskell) often don't force any particular amount of indentation. Consecutive lines with the same amount of whitespace prefix are considered be a part of the same block.

Most projects/companies have indentation/style standards so that code can be communicated across individuals. Once you add in the indentation style, braces look redundant and are just extra noise and chances for error.

I must admit, though, totalitarian systems often help people work together :)

Re:Rust - a new programming language from Mozilla by rdtsc on Tuesday April 03, 2012 @10:10AM (#3792949)
When I look at code I see structure. Before I even see individual squiggles, brackets, semicolons, I see structures and blocks of code. One code-block indented in another, "oh look this is a huge block here", "these are 3 nested ones" and so on. Brackets don't help me there but indentation does.

Let me ask you this, do you already indent your code? If not it is probably a tangled mess and I wouldn't want to continue the conversion with you. But, if you already indent your code, then why do you need brackets? You are wasting space and you are repeating yourself. It is like enforcing that every declaration of "int counter" to be followed by a comment saying "// declaration of counter as an int".

The only reason to use brackets is to minify a piece of code or to appeal to C++ or C programmers. So Javascript benefits from having brackets. I guess Rust does too because it is trying to appeal to C++ programmers.

Re:Rust - a new programming language from Mozilla by hackinthebochs on Tuesday April 03, 2012 @12:39PM (#3793665)
Brackets and parenthesis help me understand the structure and flow of code at a glance. Indentation helps too, but it doesn't completely subsume structural syntax. It's like commas, semicolons, periods, paragraphs, etc in writing. They're tools to help you convey meaning that isn't apparent from the words themselves.

Minimalism for its own sake is an anti-pattern in language design. I will be very happy once this meme dies.

Re:Rust - a new programming language from Mozilla by scott_s on Tuesday April 03, 2012 @02:22PM (#3794129)
There is no less structural information in, say, a Python code block than in a C code block. Once you get used to the syntax and language semantics, you will just as easily be able to understand the structure and flow at a glance.
Re:Rust - a new programming language from Mozilla by cageface on Tuesday April 03, 2012 @12:21PM (#3793566)
Brackets give your editor the information it needs to automatically infer scoping and to do smart reformatting. Without it you're entirely on your own.
Re:Rust - a new programming language from Mozilla by Symmetry on Tuesday April 03, 2012 @01:40PM (#3793951)
And my editor (or any good editor I'd argue) can do the same thing with indentation just as easily.
Re:Rust - a new programming language from Mozilla by webjprgm on Tuesday April 03, 2012 @04:18PM (#3794627)
What counts as "good"? By your definition it's one that can provide helps with indentation-based blocks. :-)

I can't depend on having a "good" editor. I have 2 work machines, 2 home machines, ssh to a VPS, ssh to a bunch of machines at work, etc. So as often as not I have to use vim to do quick edits of code. I also am generally forced to use Apple's Xcode for Obj-C applications, but use other editors for anything else. Working on my own toys vs. working at work, vs. being in school instead of a commercial entity with nice software licenses also means I can't depend on having the same text editor available, other than free ones.

I'd prefer to use a programming language that was easy to read and write in just about any text editor. The only requirement I can't easily escape is that the editor must support auto-indent. (So MS Notepad is out.)

Re:Rust - a new programming language from Mozilla by rdtsc on Wednesday April 04, 2012 @01:59AM (#3796368)
> I'd prefer to use a programming language that was easy to read and write in just about any text editor.

Actually you can apply that argument for whitespace only languages, because they produce code that is more consistent. So because the code is more consistent it is also easier to read and write (as opposed to say, dealing with someone's eccentric formatting).

Vim or emacs (the one I use) is available for any modern OS out there. It is free and has outstanding syntax highlighting and works through a terminal as far as I know.

In general it seems like this is a tail wagging the dog problem -- picking a language to work with (what seems to be a broken) editor.

Re:Rust - a new programming language from Mozilla by cageface on Wednesday April 04, 2012 @05:09AM (#3796772)
In general it seems like this is a tail wagging the dog problem

I agree but in reverse. You're willing to give up a trivially parseable syntax just to avoid typing a few braces?

Re:Rust - a new programming language from Mozilla by scott_s on Wednesday April 04, 2012 @11:57AM (#3798130)
No, not because of typing. Because of reading.
Re:Rust - a new programming language from Mozilla by cageface on Wednesday April 04, 2012 @04:36AM (#3796683)
It can't because the indentation is part of the code. If I run a Java source file through a script that removes all whitespace I can get a beautifully formatted file back with a single keypress. This is literally impossible for whitespace languages like Python and Haskell.
Re:Rust - a new programming language from Mozilla by Symmetry on Wednesday April 04, 2012 @08:54AM (#3797297)
But likewise, if I remove all braces from Java I can't necessarily get them back with a single keypress.
Re:Rust - a new programming language from Mozilla by cageface on Wednesday April 04, 2012 @10:22AM (#3797693)
But unlike whitespace braces aren't removed or scrambled by routine text manipulation.
Re:Rust - a new programming language from Mozilla by rdtsc on Wednesday April 04, 2012 @01:52AM (#3796358)
My editor (emacs) does a great job at formatting Python code. If your compiler and your eyes get enough information about how code is structures from indentation so should your editor.
Re:Rust - a new programming language from Mozilla by mattdeboard on Tuesday April 03, 2012 @09:15AM (#3792752)
Being someone who has only ever programmed in languages that use whitespace or parens, I really, really don't get the curly braces thing. :) White space is very readable and just as obvious a discernment of codeblocks as curly braces.
Re:Rust - a new programming language from Mozilla by ntkachov on Tuesday April 03, 2012 @12:00PM (#3793456)
As someone who uses both constantly, Whitespace languages and curly braces are the same. For a good programmer, she can take out the curly brace and it should look like a whitespace language. Likewise, a whitespace language would just have braces inserted everywhere there would be an indent change. '{' for forward indent and '}' for backwards indent.
Re:Rust - a new programming language from Mozilla by nickknw on Tuesday April 03, 2012 @04:54PM (#3794778)
Exactly, I agree.

Enough with the bikeshedding! There are much more interesting things about Rust to discuss than this.

Re:Rust - a new programming language from Mozilla by cageface on Tuesday April 03, 2012 @12:21PM (#3793556)
The problem with significant whitespace is that it makes routine tasks like copy & paste and shifting blocks around a tedious and error prone exercise instead of a trivial editor task. Give me instead a syntax that lets my editor completely and correctly reformat an entire file with a keypress.

Significant indentation is the #1 thing keeping me at a distance from Haskell and Coffeescript.

Re:Rust - a new programming language from Mozilla by falcolas on Tuesday April 03, 2012 @01:46PM (#3793978)
I've heard this before, and after working in a 250k loc Python codebase for 4 years, I can't say that this has actually ever been an issue.

Any decent editor lets you handle block indentation very simply, and it's typically easy to see what the indentation level should be.

Re:Rust - a new programming language from Mozilla by webjprgm on Tuesday April 03, 2012 @04:10PM (#3794588)
I find that significant white space is a problem mainly when going between editors, and also mainly because of space vs. tab problems. E.g. if I copy-paste from vim in Terminal into TextWrangler (free BBEdit) then all the tabs have become spaces, which python will throw a fit about. Similarly if I copy-paste code from a website or blog entry.

In languages with () or {} I can hit a key to reformat copy-pasted code. In Python I have to do it manually.

When it comes to moving blocks of Python code around inside one source file, then it's a simple matter to hit the plus/minus indent hotkey.

Re:Rust - a new programming language from Mozilla by falcolas on Tuesday April 03, 2012 @04:17PM (#3794622)
Using tabs instead of spaces is not a recommended practice for Python, or most white space orientated languages that I'm aware of. Adopting that best-practice would seem to alleviate most of your concerns that you've listed here.

Most editors even let you handle that on a filetype basis, so you can use 4 spaces for Python, and tabs for your C files.

Re:Rust - a new programming language from Mozilla by kamaal on Wednesday April 04, 2012 @04:25AM (#3796662)
Why should I even waste my time worrying about supplying spaces or tabs every time I go to a new line while programming.

That was supposed to be the compilers job. I am here to do mine.

No wonder so many people hate whitespace based parsing.

Re:Rust - a new programming language from Mozilla by Bjartr on Wednesday April 04, 2012 @12:11PM (#3798208)
>Why should I even waste my time worrying about supplying spaces or tabs every time I go to a new line while programming.

What are you talking about? Why wouldn't you have your editor just insert the correct number of spaces when you press the tab key? It's worked fine for all my python work.

Re:Rust - a new programming language from Mozilla by webjprgm on Tuesday April 03, 2012 @04:35PM (#3794700)
Why can't I reply to the reply to my comment?

Anyway, that's tab vs. space flamewar, best practices flame war, etc.

Long story short, I don't like spaces because editors do not make it as easy to navigate back/forward 4 (or 2) spaces as it is to navigate 1 tab. Most annoying instance of this: what combination of keypresses does it take to get from the middle of a line to the beginning of a line? In Notepad++ it's easy, but it Xcode its cmd-left-arrow then hit right-arrow for every space/tab you need to pass. (Or in general for a Mac text editor cmd-left-arrow, then opt-right arrow, then opt-left arrow, but that doesn't always work right. In TextWrangler it's cmd-left + opt-right, which is better but still slightly tricky hopping from cmd to opt key.)

Re:Rust - a new programming language from Mozilla by Bjartr on Wednesday April 04, 2012 @12:14PM (#3798225)
And now I'll introduce the editor flamewar: in vim, moving from anywhere on a line to the first non-whitespace character on that line is just ^, moving to the very first character of the line is 0. In general, navigation in vim is whitespace agnostic (inasmuch as you move around by chunks of text, not character by character)
Re:Rust - a new programming language from Mozilla by cageface on Wednesday April 04, 2012 @04:35AM (#3796681)
I worked at a company a few years ago that experienced a site-wide website outage because an engineer hotfixed a python file with an editor that inserted a tab instead of a space. It wasn't easy to pinpoint the problem either.
Re:Rust - a new programming language from Mozilla by mattdeboard on Tuesday April 03, 2012 @01:30PM (#3793907)
Well, I dunno, I've never really had issues with it but, like I say, vast majority of my code has been in Python and Clojure. I'm not arguing against braces, btw, it's just another delimiter like whitespace. It's all just about what kinds of things you're willing to train your brain to do, IMO.
Re:Rust - a new programming language from Mozilla by yumraj on Tuesday April 03, 2012 @03:24PM (#3794378)
IMvHO: Curly braces are like punctuation marks in a language, in that they very clearly mark the beginning, end and so and so forth. But, yes, it is a very style issue, but to me code without curly braces feels very naked.
Re:Rust - a new programming language from Mozilla by inerte on Tuesday April 03, 2012 @09:38AM (#3792832)
I don't know if this will apply to you, but it's also possible to "see" the blocks just by indentation.

If you assume that this is possible, and your eyes can get used to read code just by its blocking, then brackets are unnecessary, even superfluous.

Re:Rust - a new programming language from Mozilla by webjprgm on Tuesday April 03, 2012 @04:39PM (#3794718)
It's like becoming bilingual. When you know only English other languages are completely confusing, but once you learn a second language you can more easily pick out pieces of others.

If all you know is {}, then other code is harder to read. Once you learn either a Lisp-like language or a Python-like language then you learn to see code blocks without {}. This is what happened for me. (I was forced into learning Scheme in school. Only after that did I decide that Python was an OK language after all.)

Re:Rust - a new programming language from Mozilla by tomp on Tuesday April 03, 2012 @09:59AM (#3792907)
> it's also possible to "see" the blocks just by indentation.

As long as there are not too many newlines within blocks...

Re:Rust - a new programming language from Mozilla by blueprint on Tuesday April 03, 2012 @09:41AM (#3792850)
Re:Rust - a new programming language from Mozilla by mindcrime on Tuesday April 03, 2012 @05:51PM (#3794975)
Meh... I've written both Python and C/C++/Java, and I disagree that it's possible to reach a point where the indentation completely obviates the need for brackets in identify blocks. That might be true if you always keep blocks extremely short, and if you never have more than a couple of levels of indentation, but in the real world code never quite seems to fit that Platonic ideal.

I'll grant, however, that the Python approach isn't quite as bad as I thought it would be, and that it can come close to matching the readability of "code with braces." But, for me at least, braces (and vertically aligned ones at that, dangit) absolutely make code more readable.

YMMV, IANAL, HTH, WTFBBQ, etc...

Re:Rust - a new programming language from Mozilla by kibwen on Tuesday April 03, 2012 @10:01AM (#3792913)
My guess is because they're primarily trying to appeal to C++ programmers seeking a safer systems language rather than Python programmers seeking a more accessible low-level language.

Incidentally, I'm the latter, and I'm very interested in Rust.

Re:Rust - a new programming language from Mozilla by webjprgm on Tuesday April 03, 2012 @04:41PM (#3794726)
I also find Rust very interesting. For the target of Go, I think it works just fine to use Python for most things and call out to C for performance-critical sections. But I have been annoyed for a long time by how often programs crash on simple errors that should not happen, like null pointers and buffer overflows. I really hope Rust (or something like it) can take off.
Re:Rust - a new programming language from Mozilla by jemeshsu on Tuesday April 03, 2012 @06:04PM (#3795024)
There is a lot to like about Rust: immutability as default, pattern matching, destructor, coroutines, uses LLVM, no hierarchy interfaces, no null pointer, built-in testing. Interestingly, the Rust compiler is written in Rust itself. If you use Mac, there is homebrew for Rust. I hope Rust will take off.
Re:Rust - a new programming language from Mozilla by MatthewPhillips on Tuesday April 03, 2012 @11:08AM (#3793212)
The developers behind it have a C++ background. Code style was not the point of the language, and therefore they went with something familiar to the devs working on it.
Re:Rust - a new programming language from Mozilla by eric_bullington on Tuesday April 03, 2012 @12:06PM (#3793471)
I know that some PL experts tend to write off syntax as an issue of secondary importance, but for many developers, it's a critical part of code readability. I've spent much too much time trying to untangle masses of ill-written JavaScript with various (or no) levels of indentation, and braces scattered across the screen. I love working with Python, CoffeeScript, and Haskell because the code is almost always very readable because of whitespace (from what I've seen, Ruby is also very readable). I'm intensively interested in Rust as a possible alternative to C or C++ -- Go is a notstarter since I can't even compile as shared object library in it. However, I wish the designers of Rust had taken the arguments for whitespace into serious consideration. There's a large number of Python and Ruby programmers looking for an alternative to C and C++ as a lower-level language to call using an FFI when we need more speed, and for most of us, readability (and therefore syntax) is a major issue. Nonetheless, Rust seems like a very cool language, and I'm looking forward to trying it out.
Re:Rust - a new programming language from Mozilla by MatthewPhillips on Tuesday April 03, 2012 @12:12PM (#3793507)
I understand your reasoning, I find constructs such as:

  if(foo) { doSomething(); } else { doSomethingElse(); }
to be rather unreadable. My solution is to not write it that way.

My observation is that code style is very important to Ruby and Python developers and less important to those from C-family backgrounds. That is, a lot of Ruby developers, for example, refuse to touch anything containing braces whereas few C-family developers require them.

I think the solution is that developers with a Python/Ruby background need to create a systems language, instead of expecting those with different backgrounds to be converted to the Python/Ruby-ists mindset. But in reality it seems that few Python/Ruby developers are all that interested in systems languages whereas those with C-family backgrounds are very interested (hence the situation that presently exists).

Re:Rust - a new programming language from Mozilla by webjprgm on Tuesday April 03, 2012 @04:57PM (#3794791)
Fork Rust and change only the syntax, just to make it use whitespace for blocks. PL experts see syntax as secondary because it is something that can arbitrarily change. Take Racket for example. They built into the language the ability to plug in arbitrary syntaxes and still use the same language tools and API. I got tired of () when I was learning Racket and wrote an alternate syntax that used whitespace indentation and converted to 100% compatible s-exp Racket code.

So, you can have a whitespace-based version of Rust easily.

The practical problem is that then you'd split the community between the two syntaxes since you couldn't copy-paste code examples from one syntax into the other. That could be problematic for building a large base of support. Take D for example where they had fragmentation problems with two standard libraries. Perhaps a split based on syntax would be less? (Since code written in one could be shared with the other.) But it would still cause problems in how the language is marketed to new developers.

Re:Rust - a new programming language from Mozilla by adavies42 on Tuesday April 03, 2012 @12:12PM (#3793505)
have there ever been any successful "skinnable" languages (or any successful language skins)? i'm thinking of things like SPECS for C++, or the way research functional languages sometimes provide both, e.g., a C-ish and a lisp-ish syntax that compile to the same thing.
Re:Rust - a new programming language from Mozilla by yyyt on Wednesday April 04, 2012 @03:55AM (#3796606)
Sass has a spaced syntax and SCSS, curly-braced.
Re:Rust - a new programming language from Mozilla by viraptor on Tuesday April 03, 2012 @08:17AM (#3792582)
Meta-comment: It's interesting how the default way changes with time... around 10 years ago it would be "why does ruby use the weird syntax instead of just brackets like c/java/js/...?"
Re:Rust - a new programming language from Mozilla by silon4 on Tuesday April 03, 2012 @12:25PM (#3793590)
I'm waiting for python to fix "from __future__ import braces". Or at least make "pass" mandatory for end of block
Re:Rust - a new programming language from Mozilla by kamaal on Wednesday April 04, 2012 @04:22AM (#3796655)
For large code blocks and if the levels of indentation go a little deep. White space makes readability very difficult.

Also besides semicolons don't cause any problem at the first place, so why eliminate them?