13 ms·
Shape of errors to come
- cfallin 10y agoI really appreciate the user-friendliness of Rust's error messages -- I can't remember seeing a compiler tell me "maybe try this instead?" before (perhaps something from Clang, but never with the specificity of, e.g., a suggested lifetime annotation). And from a parsing / compiler-hacking perspective, it seems really hard to get the heuristics good enough to produce the "right" root cause. Kudos to the Rust team for this continued focus!
- jerf 10y agoIt's taken... I dunno, 50+ years?... but it's nice to see more and more code being written that doesn't assume programmers are superhuman beings with an IQ of 250 and infinite concentration and working memory. We need all the help we can get, so that we can focus as much of our precious, limited cognitive firepower on what really matters. When even John Carmack is talking about getting all the help he can from his development environment [1], you really ought to listen. [1]: http://number-none.com/blow/john_carmack_on_inlined_code.html http://number-none.com/blow/john_carmack_on_inlined_code.htm...
- hinkley 10y agoPair debugging is an exercise in patience that I often lose. If I had a dollar for every time I asked someone "Okay, look for other uses of this variable" and they grab the mouse and stare at the screen because THEY'RE READING THE ENTIRE FILE LOOKING FOR A PIECE OF TEXT, instead of using any of the dozens of search mechanisms at their disposal, I could retire and write self-help books for programmers. Stop trying to white-knuckle everything all the time, you masochistic people. Use tools like a sentient creature is supposed to.
- quantumhobbit 10y agoMaybe the other person in the pair is forgetting to use their tools because they are stressed out by the aggressive person standing over their shoulder looking for any excuse to grab the keyboard?
- kctess5 10y agoSometimes, this might be the case, however after the nth time of nicely saying "oh btw you can just do [insert shortcut] and find it right away!" it's hard to not get frustrated. I have definitely worked with people who for whatever reason, absolutely refuse to learn their text editors and debugging aids.
- hinkley 10y agoUsually this becomes an interpersonal issue when you're working with someone who has a track record of only changing 90% of the code that needs to be changed to implement a feature/bug fix because they keep missing one spot where the information is used.
- hinkley 10y agocough I have no idea what you're talking about. Mostly I think the exploratory phase of debugging is a battle between your limited short term memory and your imagination. It's a think you need to do alone and without someone stopping you to ask why every fifteen seconds. I think that's why people are so big on repro steps, so they can go off and start the process of elimination without having to dump state while defending checking possibility A before checking possibility B. I think the only reason (besides tenacity) that I fix bugs that others gave up on is that I have tricks that let me walk the code faster, which lets me make forward progress on deduction before I forget WHY I was looking under this rock in the first place. My debugging practices look not unlike a guy looking for his missing keys. You have to be careful about when to hit him for questions, and most of the time it's better to just start your own parallel search if you want to help.
- kbenson 10y ago
- mrob 10y agoIt's your fault for saying "look for". They're doing just that. They're using all their available brain power thinking about the code so they don't have any to spare to interpret unclear instructions. Instead say "search for", or if that's still unclear say "control-F for" (or whatever shortcut activates search).
- donw 10y agoHave you tried suggesting that exact trick (using search rather than scanning) to your pair whenever they default to the Mark One Eyeball? Having paired quite a bit, it's rather amazing how many programmers just don't know the full utility of their existing tooling. Not because they are stupid, but just because they never made that particular connection. I have been on the receiving end of this dozens of times, and it is one of my favorite things about pairing as a programmer: where my pair shares a neat trick that saves me a notable amount of time and/or aggravation.
- cmontella 10y ago> it's nice to see more and more code being written that doesn't assume programmers are superhuman beings I would say that most compilers don't even assume the programmer is human. The root cause of bad errors is that they emanate from the compiler, and are reported from the perspective of the compiler. That's why you get errors like "can't access method undefined of undefined", or the hell that is C++ template errors. Sure, the errors make perfect logical sense from the perspective of a compiler, but they make my human eyes bleed. My favorite is a single missing semicolon that causes a cascade of unrelated errors, none of which indicate there's a missing semicolon. grammars, parsers, compilers, and languages as a whole should be designed for humans first. Even if it makes the language implementation a little more complex, human users will benefit greatly and thank you for it.
- boznz 10y agoI think that is why ADA became popular for mission critical stuff as you can inform the compiler a lot more about the constraints and so in effect make the compiler more user friendly. (Disclaimer happy to be corrected as I have never used ADA but I just finished listening to the podcast on embedded.com and thought it relevant)
- msbarnett 10y agoThe biggest correction I have is that it's not an acronym -- Ada, not ADA.
- eatbitseveryday 10y ago"ADA" as an acronym is more easily know as "Assistant District Attorney".
- nommm-nommm 10y agoI read ADA first as Americans with Disabilities Act (https://www.ada.gov https://www.ada.gov). In all seriousness, Ada the programming language is named after a person - the English mathematician Ada, Countess of Lovelace known as "the first computer programmer" ( https://en.m.wikipedia.org/wiki/Ada_Lovelace https://en.m.wikipedia.org/wiki/Ada_Lovelace)
- overcast 10y agoReading HN comments, I assumed everyone is a superhuman with an IQ of 250 and infinite concentration.
- qwertyuiop924 10y agoAre you even reading the same website as me?
- D-Coder 10y agoNot all of us.
- telotortium 10y agoJust wait until the next politics thread.
- smcl 10y agoDid you post the right link? That one was about John Carmack inlining some function calls and eliminating weird branching to (potentiall) reduce bugs/errors. Or am I missing something?
- ams6110 10y agoIn OpenBSD you'll see stuff like: warning: stpcpy() is dangerous GNU crap; don't use it warning: strcpy() is almost always misused, please use strlcpy() warning: strcat() is almost always misused, please use strlcat() warning: sprintf() is often misused, please use snprintf()
- jules 10y agoThose error messages, no matter how good, are curing the symptom not the cause. In other languages this particular problem doesn't exist in the first place.
- Sir_Cmpwn 10y agoRust has not killed and will not kill C. Can we please cut this crap out? Rust is a cool and useful language but I am getting tired of its proponents talking smack about everything else all the time.
- dikaiosune 10y agoThe person you're replying to didn't even mention Rust -- and they're right that many languages other than Rust avoid the problems cited in the listed error messages.
- Sir_Cmpwn 10y agoLoads of languages have old functions that could be better with hindsight, I'd probably say all of them. Some of them even have security implications (mysql_real_escape, anyone?). C isn't going away any time soon, and there's no value in decrying it as a response to being told about a feature that makes it safer!
- nickpsecurity 10y ago"Loads of languages have old functions that could be better with hindsight" Strawman. C's predecessors did it better with foresight. One of best such systems was built by C's inventors. BCPL author and C inventors deliberately removed safety at OS and language level due to hardware constraints plus personal preferences. Then nobody changed it to avoid work or broken apps. Hindsight aspect has nothing to do with it. "C isn't going away any time soon, and there's no value in decrying it as a response to being told about a feature that makes it safer!" Got mixed feelings on when to slam C or help its users out. I agree with you that bashing it at a comment on a safety improvement is probably a bad idea. It might have effect of reducing number of people promoting safer C strategies. I usually ignore, upvote them, or mention stuff like SAFEcode/Softbound depending on what's in comment. I go anti-C when misinformation shows up or on more general topics of safe, efficient apps.
- tetrep 10y agoHaskell has gotten really good at more or less telling you what to do, it's a pretty common technique while developing to have the compiler run in the background whenever you change a file[0]. I've found it to be great when developing because you can just let the compiler tell you what type you need to put somewhere, and you can use something like Hoogle[1] to find how you can get that type. [0]: usually people use this: http://www.mew.org/~kazu/proj/ghc-mod/en/ghc-modi.html http://www.mew.org/~kazu/proj/ghc-mod/en/ghc-modi.html [1]: http://hoogle.haskell.org/ http://hoogle.haskell.org/
- cfallin 10y agoI've heard that technique described as "type tetris". I find myself trusting the type system to guide me a lot in Rust too -- it's very nice!
- runeks 10y agoAt the end of that spectrum (moving away from values and towards types) are languages like Coq, where you have only types, no values, and it's the compiler that derives the implementation/values from the types you define. Like Haskell Servant[1], where you define your API as a type, and then you can derive functions from that type to query the API, because the type itself contains all the information necessary. Pretty fascinating stuff. [1] http://haskell-servant.readthedocs.io/en/stable/tutorial/ApiType.html http://haskell-servant.readthedocs.io/en/stable/tutorial/Api...
- cmrx64 10y agoCoq unifies terms and types, so that all you have a terms, but there's still a very concrete meaning of value: that which can be reduced no further (normalization, a property that the calculus of inductive constructions has).
- runeks 10y agohlint is also pretty good at giving advice: http://imgur.com/a/9oXd8 http://imgur.com/a/9oXd8
- edgyswingset 10y agoElm has great error messages which do this. F# is also adopting some of that style in F# 4.1: https://blogs.msdn.microsoft.com/dotnet/2016/07/25/a-peek-into-f-4-1/ https://blogs.msdn.microsoft.com/dotnet/2016/07/25/a-peek-in...
- fizzbatter 10y agoI'm quite new to a lot of the concepts in Rust, and while many error messages are simply infuriatingly confusing.. there are many that are extremely helpful. Hell, just the underline showing you what area is wrong really helps you spend the fewest cycles on simple typos and etc. It's really a joy. Fwiw, the frustrating times are usually involving some semi-obscure type system issue i've caused. But seeing as i'm probably their target user for these sort of messages (beginner), i guess my issues are still probably relevant.
- steveklabnik 10y agoIf you have the energy, we have an entire tag, A-diagnostics, on the tracker. It's to track confusing/poor error messages. So please file them!
- taeric 10y agoThe jikes java compiler had very well done error messages, from what I remember.
- amelius 10y ago> I can't remember seeing a compiler tell me "maybe try this instead?" What is next? Clippy? [1] [1] https://en.wikipedia.org/wiki/Office_Assistant https://en.wikipedia.org/wiki/Office_Assistant
- steveklabnik 10y agohttps://github.com/Manishearth/rust-clippy https://github.com/Manishearth/rust-clippy
- cpeterso 10y agoHave any Clippy warnings be added to rustc? Many of them look like real bugs that would benefit more people if included in rustc itself.
- steveklabnik 10y agoNot yet. Adding warnings is tough; some part of the ecosystem compiles with "warnings == errors", and so adding new lints can cause ecosystem breakage.
- lifthrasiir 10y agoAnd not to mention that "soft" warnings not included to the list would essentially have the same problem as `-Wall` vs. `-Weverything`. wink
- chrismorgan 10y agoCrates.io should have a check for things that get published to it that objects if you try to upload something with `#![deny(warnings)]` on the crate. It’s fine for your own code, but production libraries should never use it.
- GolDDranks 10y agoThe joke's on you: Clippy – A bunch of lints to catch common mistakes and improve your Rust code https://github.com/Manishearth/rust-clippy https://github.com/Manishearth/rust-clippy
- kalleboo 10y agoI don't know if I've seen it in compiler output, but I've seen IDEs like Eclipse and XCode have some pretty good "fix it for me" suggestions (maybe those are sourced from the compiler, I'm not sure).
- zalmoxes 10y agoInspired by Elm?
- alexbock 10y agoElm inspiration is mentioned at the end of the "Extended error messages" section.
- squiguy7 10y agoYes, here is a quote from the post: > Those of you familiar with the Elm style may recognize that the updated --explain messages draw heavy inspiration from the Elm approach.
- corysama 10y agoExample: https://twitter.com/GregorySchier/status/732830868562182144 https://twitter.com/GregorySchier/status/732830868562182144
- jweir 10y agoI've been working with Elm over the last week, and the error messages are informative and helpful. When, possible they educate you on the nature of the error and guide you on how to fix the problem.
- gnuvince 10y agoVery good! I always liked the content of Rust's error messages as it clearly explained the issue, but the form of those error messages was a bit problematic, they were very noisy and it wasn't easy to see the issue by simply glancing, you had to scroll up, find the beginning of the error and read carefully.
- hyperpape 10y agoDo I understand correctly that since this is in the current nightlies, it's slated for 1.12? So, sometime in October?
- steveklabnik 10y agoYes, current nightlies are 1.12. Anything can happen before release, though, so in theory, it's not guaranteed to land in 1.12 until the day that 1.12 forks off from master.
- knodi 10y agodamn... thats nice. Can't wait to dive into it.
- dllthomas 10y agoPlease put file locations (as many as might be relevant) at the start of a line in the standard format! The other changes look valuable. Improving error reporting is great. Edited to add emphasis: I really did mean a line, not every line.
- pcwalton 10y agoThose file locations repeated every line accounted for a lot of the noise in the previous format. I'm glad they're gone.
- db48x 10y agoAgreed. Get a dozen errors at once and you can feel your eyes glass over from all of the repeated file names. Better to just update the error parser in emacs.
- dllthomas 10y agoI actually agree about the repetition. I was speaking to formatting of the file locations that are included. Far better to remove (or move) for characters, than to update every tool to handle yet another format (and/or increase false positives in detection of src locations in an error stream).
- dllthomas 10y agofour characters too late to edit...
- dllthomas 10y agoThe repetition is not what I was speaking of. As you say, including the same file name N times with successive line numbers just because you've localized the error somewhere in that span means a bunch of noise. But where you are going to include a file location (and one is included), put it at the beginning of the line, to be friendly to existing to existing tooling. Putting the "-->" in front of the location is not what makes this format more readable. (Including multiple locations is great where they are actually distinct locations.)
- waynenilsen 10y agoI would love to see an option for showing the error order forward or backward. My workflow is to start fixing compile time errors from the top of the `cargo` output but scrolling to the top can be fairly annoying when there are a lot of errors. Having the most relevant error at the bottom of the command line (where it automatically scrolls) would be useful as an option IMO. This probably causes some other unseen problems however
- steveklabnik 10y agohttps://github.com/rust-lang/rust/issues/32650 https://github.com/rust-lang/rust/issues/32650
- ansible 10y agoWell, I just use 'more' or 'less' to see the beginning of the output. I'm also using GNU screen, and can easily scroll back through the terminal's history if I can't be bothered to re-run the command with a pager on the output.
- saghm 10y agoI sometimes do that, but the output loses the color it had, which can make parsing it a bit tricky (although the less noisy new format will help a bit with that)
- tbirdz 10y agoUse less -R to preserve color escape sequences when paging in less.
- heinrich5991 10y agoThis only helps if the program that pipes into less doesn't do terminal detection to decide that it doesn't want to output ANSI color escapes into a pipe (to less).
- 10y ago
- Animats 10y agoImagine what you could do if error messages didn't have to appear as plain text. You could have arrows, lines, shaded areas, and even multiple fonts.
- dikaiosune 10y agoThere's some ongoing work in that area that may be relevant: https://github.com/nrc/rustw https://github.com/nrc/rustw
- taneq 10y agoWhat would this gain us, other than visual clutter and compatibility issues between IDEs?
- Animats 10y agoBetter ways to display non-local problems. Rust's borrow checker detects many errors that reflect inconsistency between two places far apart in code. This is hard to display.
- kibwen 10y agoEvery error has a JSON representation, which any tool can receive and display it whatever way it chooses.
- outworlder 10y agoSomething like this? https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fi.stack.imgur.com%2FKcSdb.jpg&f=1 https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fi.stack.img...
- marsrover 10y agoNot related to this article, but I was looking through the Rust survey mentioned at the bottom of the article and was surprised at the amount of people using it for web development. I'm not very knowledgeable about Rust but I guess I assumed it would not be the best technology to use in that space. Is Rust really that prevalent in web development?
- steveklabnik 10y agocrates.io, for example, has Rust on the backend. There's a HN poster who uses Rust server-side for his business, IRC. https://news.ycombinator.com/item?id=10312354 https://news.ycombinator.com/item?id=10312354 is a comment I made a while back about it. I've gone from "why would you do that" to "this can make sense, depending" over the years.
- nfriedly 10y agoI think part of it is just because there are a lot of people doing web development. Also, of that group of people, many of us like to try out new things even if they aren't the best match...
- fizzbatter 10y agoThat's mainly my goal as i learn Rust. It's been a difficult learning process[1], but i persist because the code i write feels simply more correct. I also think as time goes on frameworks will improve the ease of use, much of the ecosystem is very young. Even better (or more crazy, heh), i plan on using Rust for clientside as soon as we have a feasible Rust -> DOM api bridge. [1]: My learning process was mainly involved in the type system, when writing my own libraries. Not so much to do with basic web development.
- Symmetry 10y agoThat looks really cool and I'll have to give learning Rust another try when this lands. Also, the title was pretty wonderful. I spent a bit thinking about it before looking at the domain and realizing what it had to be.
- ColinDabritz 10y agoI love the clarity and readability of these errors. You can work on UX at lower levels, and it looks like this. Beautiful. I'm not even a Rust dev, I'm mostly in C# land these days, but I appreciate the effort this takes. Well done!
- mrich 10y agoGreat to see an improvement over the already improved error reporting established by clang and later adopted by gcc. However I don't understand why backticks are still being used - they tend to look ugly especially when pasting them into emails etc.
- kibwen 10y agoBackticks aren't used anywhere in the language itself so they're an obvious choice for a delimiter, and such usage has been popularized by markdown.
- justinsaccount 10y agoIn my little rust experience the suggestions the error messages had, even in the longer explanations, were useless. Mostly it came down to me trying to do something that was simply not supported, but the compiler not knowing that and leading me on a wild goose chase. From what I remember, I was trying to use the iterator trait, but return records that contained str pointers.. The goal being to parse a file and yield pointers to the strings from each line to avoid allocating memory and copying bytes around. Rust tries to tell you that you need lifetime specifiers, but if you try adding those nothing compiles anyway because the iterator stuff doesn't actually support that. I eventually got it to work by returning copies of the strings.. maybe the unsafe stuff would have done what I wanted, that's what rust-csv seems to do at least. I concluded that Rust is definitely not a language you can learn by chasing down error messages and incrementally fixing things. If you don't 100% understand the borrow and lifetime stuff, fixing one error is just going to cause two new ones.
- steveklabnik 10y agoHm, iterators can definitely return pointers. Post on users.rust-lang.org or drop by IRC sometime! We're happy to help.
- justinsaccount 10y agoOh? Maybe I was looking up the wrong thing. Now that I search again I think this is what I was trying to do: http://stackoverflow.com/questions/30422177/lifetime-in-iterator-impl http://stackoverflow.com/questions/30422177/lifetime-in-iter... though in my case I had a vec of &str or something like that. What I do remember was the compiler sending me in circles. Honestly if it had just said something like "Hey dummy, you can't do that, go read the chapters on lifetimes again" I might have fixed it. But it kept telling me things like "Just add a lifetime specifier on this line" and I would do that and then get 2 more error messages. I think the errors sent me down the path of trying to do what the SO post mentions, which is fn next<'a>(&'a mut self) -> Option<Vec<&'a T>> instead of putting the lifetime on the impl block, which probably never even occurred to me was something you could do.
- miguelrochefort 10y agoNothing that Visual Studio and C# doesn't do.
- nneonneo 10y agoThis focus on compiler usability is really fantastic. C calls these "compiler diagnostics" for a reason - they should help the programmer diagnose and fix the problem. I loved it when Clang started making C errors sane (and getting GCC to introduce better messages too!), and I'm glad to see Rust take the next step. Since I'm stuck in C++ for the time being, I'm (selfishly) hoping that Clang takes a page from these new Rust errors - these sorts of diagnostics would look great on C++!
- karysto 10y agoI always love it when we bring UX to the the tooling we use, and not just on the end product in our users' hands. Everyone appreciates a delightful UX, including software engineers. I've been eyeing Rust for a while now, this just gives me another excuse to hack with it.
- IshKebab 10y agoThis is great! Why keep the row/column numbers at the end of the source file though? Aren't they redundant (IDEs shouldn't be parsing command line output anyway so they don't need it).