425 points · by runesoerensen · 10y ago · 161 comments
[1]: http://number-none.com/blow/john_carmack_on_inlined_code.htm...
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.
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.
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.
int foo = 2
bar = 3;
Am I missing a semicolon there? Or maybe a comma? You could probably guess it based on whether or not "bar" exists in the lexical scope during compilation, but then again, maybe I want to shadow it with a "more local" definition?The point is - you can make suggestions based on probabilities, and maybe it is a good idea to integrate a compiler with a linter. But to actually get error messages that make sense, your compiler would have to understand what you mean.
I get in a funk and my brain refuses to push past it. I feel like Neo when they tell him about the Matrix and he pukes and passes out.
But none of them caught on because they were either too removed from the hardware for its time, or not "macho" enough for the guys in the computer labs.
[0]: usually people use this: http://www.mew.org/~kazu/proj/ghc-mod/en/ghc-modi.html
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/Api...
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()
F# is also adopting some of that style in F# 4.1: https://blogs.msdn.microsoft.com/dotnet/2016/07/25/a-peek-in...
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.
What is next? Clippy? [1]
Clippy – A bunch of lints to catch common mistakes and improve your Rust code https://github.com/Manishearth/rust-clippy
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.
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.As I mentioned below, we love bugs about bad error messages, feel free to file them!
fn next<'i>(&'i mut self) -> Option<Vec<&'a T>>
which, thanks to lifetime elision, is the same as fn next(&mut self) -> Option<Vec<&'a T>>The other changes look valuable. Improving error reporting is great.
Edited to add emphasis: I really did mean a line, not every line.
There are plenty of tools that help people (including myself) to deal with compiler errors more easily, and they're not limited to emacs either.
For most purposes, having at least _one_ line in the standard 'filename:linenumber:[column:] {error,warning,...}:' format is sufficient for compatibility. You have such a line already; just remove the '-->', add the 'error:' or whatever back in, and you should be good to go without sacrificing any of the (very welcome!) improvements from this change.
> Please, take those complaints from others seriously.
We are absolutely taking it seriously. We do not want to regress on tooling for this, and in fact, plan on making it _better_ not worse.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.)
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).
For my use, what I care about is that important locations that I might want to visit appear at the beginning of the line as either "filename:line:col: " or "filename:line: ".
Other lines can begin with "error[E0080]" - that does no harm.
If others have more particular needs, I hope they voice them. (nhaehnle seems to want severity following location?)
Its Rust support is the only reason I care to use a web based editor as desktop application.
https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fi.stack.img...
> Those of you familiar with the Elm style may recognize that the updated --explain messages draw heavy inspiration from the Elm approach.
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?
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.
Also, of that group of people, many of us like to try out new things even if they aren't the best match...
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.
However I don't understand why backticks are still being used - they tend to look ugly especially when pasting them into emails etc.