Hacker News new | ask | show | jobs
by andr3w321 3139 days ago
What I'd really like is a smarter compiler. My normal dev process is

1. Write code

2. Run code

3. See error

4. Google error

5. Write code to fix error

6. Repeat

I'd like a compiler that helps speed up steps 3-5. I know IDEs do some of this, but I'd like a compiler that automatically fixes errors instead of just telling me what went wrong. One that fixes parentheses that I left off or automatically fixes typos in variable names or function calls. One that knows to keep things DRY and creates a function for me when it sees the same similar code written twice. One that knows when I wrote an inefficient bubble sort and swaps it out with a faster sorting algorithm etc. One that can make my code run faster. I think this is a long way off, and I know it's really hard to write a program that writes code, but it's always seemed that programming simple things is way harder and takes longer than it should to me.

4 comments

Typesafe languages are potentially a lot better here; they move "see error" to before "run code". Visual Studio or even Eclipse are quite good at inserting parens or quotes for you, warning if they're not there, and providing completion over identifier names to avoid spelling errors.

> One that knows to keep things DRY and creates a function for me when it sees the same similar code written twice

This is potentially an interesting idea.

> One that knows when I wrote an inefficient bubble sort and swaps it out with a faster sorting algorithm etc.

This is also the sort of thing that optimises out your security-critical delay loop or memory wipe.

It wouldn't overwrite your code without your approval of course, but if it could at least provide helpful suggestions that I could choose to approve it would be immensely helpful.
Which language are you using? IDE or no IDE, it's been a long time since I've used a language that doesn't get statically analyzed or linted while I type. E.g. Clang statically analyzes on the fly in Emacs. I certainly don't need to Google any errors as the error messages are helpful.

Some of the other stuff you mention is not a way long off if you use an IDE like Visual Studio, which, with or without Resharper does a lot of code analysis. You get notified if you have dead code (branches that never get ran), duplicate code (i.e., things that should be turned into a common method or class), etc.

One that fixes parentheses that I left off or automatically fixes typos in variable names or function calls.

Webstorm can do some of what you mention:

https://news.ycombinator.com/item?id=15514285

https://news.ycombinator.com/item?id=15638652

One that knows to keep things DRY and creates a function for me when it sees the same similar code written twice.

Unfortunately this is "sufficiently smart compiler" territory. I'd love to be wrong about that though.

You can use Javascript, the main engines will do that kind of magical "fixing" like adding missing semicolons and hoist variable definitions upwards in functions. It's even transparent. It's an hot mess.

What you request in the last paragraph is a Junior Developer to do the grunt work of implementing a spec.

I'm not sure why this has been down voted, but what you are describing as "magical" were a direct consequence of the "lazy" or "lackluster" language implementation. Semicolons are optional, and variable scope is not strictly lexical. This can be seen easily by implementing a javascript subset, which is an interesting excercise. Specifically, the part where you build symbol tables and do symbol resolution. These are also some of the reasons why Javascript is derided by many.