5 ms·
This is very cool, but I wonder why people are already inventing different indentation styles for Rust already. Guys, we have the canonical way all Rust code sh
by devinus 13y ago
This is very cool, but I wonder why people are already inventing different indentation styles for Rust already. Guys, we have the canonical way all Rust code should look from the Rust compiler itself. Let's not all start using disparate styles just because we can like C/C++.
- pointyhatuk 13y agoGood point. Need a rustfmt like gofmt in go.
- gloob 13y agoI, too, feel that perfectly uniform brace positioning is one of the critical technical challenges facing any new language today. There is no longer any excuse to get such an important and fundamental advance wrong.
- jlgreco 13y agoSarcasm? It may not be a "critical technical challenge" but if you are writing a new language there is really no excuse to not cement things like that down before it is too late.
- kybernetyk 13y agoWhy do you want to force people to use your style? That's pretty much against the hacker mindset.
- sophacles 13y agoWhy do you want to force people to whatever style you want to read in? There is a strong case for having one style: namely that now it becomes easy to understand aspects of a program at a glance (e.g. structure of flow, where you can gloss over for now, and where you have complexity) and also helps identify errors and on right away. Sometimes it's imperfect, but consistency is more important than "looks pretty". Besides, if we're talking about the hacker mindset: 1) there are other languages 2) you can do amazingly complex and deep things with your brain, but you can't adapt to a style? 3) consistency and correctness is more important than "what I whimsically decide is neat looking today, no matter how many errors it is hiding".
- nsmartt 13y ago>That's pretty much against the hacker mindset. I see how you would think so, but I lean in the opposite direction. If all programs in X language are written in the same style, you never have to pause to think about how to style something. This also means that you can quickly read other programs without being thrown by differences in style, and it's a great use-case for a tool that does the formatting for you. You can just write a quick example, run the formatting tool, and you won't have to pause next time. If you really can't afford the interruption, you can just skip formatting and run the formatting tool later-- though this is the sort of use-case that only occurs early in your relationship with the language.
- jlgreco 13y agoMy style? Not my style, a style. And there would be no "forced" unless the reference implementation were to error when un-standard styles were used. I see absolutely nothing particularly "un-hackerish" about this. We standardize syntax and keywords, why not syntactical style? You know what does seem hackerish though? Having tools that do mundane tasks (for example, formatting) for you so that you don't have to. Lisp, and lisp pretty-printers, also strike me as pretty hackerish.
- coldtea 13y agoHackers are about creating things. Arguing about "using your own style" with regards to braces and such is not hacking, it's bike-shedding.
- kybernetyk 13y agoSo suddenly you decide what hacking should mean to me? Sorry, but this thread smells of authoritarian people. I'm not really compatible with that.
- coldtea 13y ago>So suddenly you decide what hacking should mean to me? Did you start this sub-thread saying: "Why do you want to force people to use your style? That's pretty much against the hacker mindset", ie telling us what hacking should mean to us? To answer your question: no. I merely restated what hacking means for everybody. Words have meanings built-in, individuals don't get to decide "what it means to them" and have that be accepted by other people (Else why even use the common word in the first place? Invent your own). So, if hacking means "no standard syntax rules" to you (among other things of course), that doesn't mean squat to the general hacking population. Guido Van Rossum, for example, is as much a hacker as anybody, as are Python users, hacking in a language where indenting is enforced. "Bike-shedding" is also well known, and is well known that syntax-style, brace wars and such fall under bike-shedding and/or yak shaving in Hacker culture, along with Emacs/Vi etc. >Sorry, but this thread smells of authoritarian people. Yes. Either that or people who couldn't give a flying duck for brace/common style wars, and have found by experience that not arguing about such things and having language standards make them more productive. People that know that your "rebellion" and "creativity" have millions of interesting avenues to be exhibiting in the things you CREATE with your code, instead of in your brace style and such. It's as if saying "I cannot be creative in this company/school" because they have a dress code. As if wearing some lame t-shirt or whatever makes one more creative.
- marshray 13y agoNo no, give developers something cosmetic to argue about! If you don't they'll find something fundamental to be dissatisfied with. E.g., the lack of full TCO or a Turing complete type system.
- ArtB 13y agoI hope I am detecting sarcasm. I say use whatever the consensus is, but TCO is a much bigger issue IMHO.
- deleted 13y ago[deleted]
- erickt 13y agoWe do have a pretty printer that we're planning on growing into a gofmt-like tool, but we still have a ways to go with it before we will be comfortable using it in an automatic fashion like Go.
- steveklabnik 13y agoNot perfect, but it exists: $ cat > hello.rs fn main() { core::io::println("Hello"); } $ rustc hello.rs --pretty normal fn main() { core::io::println("Hello"); }
- Aloisius 13y agoThis is inevitable with any language that looks like C. As there are already numerous styles for C/C++/Java that people have strong feelings for and they'll just carry them over to Rust. My C++ style is identical to the first Draft ANSI C++ book I read. I've carried that style to Java and even to C (I hated pre-ISO K&R though mine looks now nearly identical to 1TBS). Heck, even when playing with Go, I used that style (gofmt be damned). Now if Rust looked more like Python...
- coldtea 13y ago>This is inevitable with any language that looks like C. As there are already numerous styles for C/C++/Java that people have strong feelings for and they'll just carry them over to Rust. Not really. Go solves this with gofmt. You might insist on your own style (as you say) but for most people it's a command line away to format it in the standard way, and all GitHub projects etc will be gofmt'ed anyway.
- spc476 13y agoIf you want One True Indentation Style for a language, then make it a part of the language, instead of leaving it to a style guide or an external program.
- ShardPhoenix 13y agoHaving it externally can be an advantage in that it doesn't matter if you have an extraneous space when you type the code in because it will be cleaned up by the formatter, whereas making it part of the language makes that an error (and possible quite a confusing one).
- spc476 13y agoIt leaves space (pun intended) for bike shedding, or for inadvertently checking in code that voilates the coding standards. If you really want One True Format, then make it part of the language spec.
- mheathr 13y agoIf a tool exists to format the code, it is of no consequence that a check in violates the formatting, as when that code is actually viewed it can (and should be) passed through that tool ahead of time such that the check in which violates the formatting guide lines is never actually viewed as such.
- Jeaye 13y agoIt's true; I fall victim of my C++ habits. A style guide is floating around the Rust mailing list; I see no reason why further code couldn't follow it more closely.
- jaredmcateer 13y agoIs it a new style? It seems inconsistent within itself... for example sometimes the code starts one a new line after the opening brace, sometimes it starts on the same line, sometimes the closing brace is on the same line sometimes it's not. I don't know enough of Rust to know whether this means anything or the coder is just being sloppy.
- steveklabnik 13y ago> Guys, we have the canonical way all Rust code should look from the Rust compiler itself. The Rust compiler is in many different 'dialects' of Rust, since it's been around for so long. Parts of it haven't been touched in a while. We're working on a general style guide here: https://github.com/mozilla/rust/wiki/Note-style-guide https://github.com/mozilla/rust/wiki/Note-style-guide
- coldtea 13y ago>We're working on a general style guide here: https://github.com/mozilla/rust/wiki/Note-style-guide* https://github.com/mozilla/rust/wiki/Note-style-guide* Better than that would be a goftm like tool, that applies the style guide. People (including me) love that about Go. (I've actually never read a negative comment about it and many possitives). It puts an end to all issues with formatting, really. I don't know how reusable the parse is -- it would make something like this even easier.
- kibwen 13y agoThere exists one of these built into the Rust compiler, but it's not very good right now. The process of creating an "official" style guide as per the above wiki page might help build the momentum needed to actually make the pretty printer usable.
- steveklabnik 13y agoPlease see my comment upthread about rustc --pretty. You can't figure out what a pretty printer should pretty print until the style is figured out.