Show HN: CodeMatch: IDE autocomplete on overdrive
languageinterfaces.com
languageinterfaces.com
There are a number of big problems with autogenerated code. One is that if you change your "how to get the path to the Desktop" algorithm, you have to manually change it in every place. This is hard to get right, so now your program is buggy and you have no way of knowing that you ever fixed it. Another problem is that the hard-coded solution is intrinsically inflexible; if the programmer had delegated to some other object, configuration could be passed into the class. It's not the "move all files out of this directory" class' job to know the details of where Windows, GNOME, KDE, and OS X keep the desktop!
One other nitpick is the flaky snippet that makes the for loop. Typing "for (File file : files) {" takes almost no time. But the snippet names the loop variable wrong ("elem"?), and correcting this takes more time than manually typing it correctly the first time. If you're going to be smart, be smart; look up the un-pluarlization in a dictionary and choose that. But don't choose a super-generic variable name, because now you've made the code of everyone that uses this tool less readable.
All in all, people seem to love shit like this, but it encourages horrible programming practices. Making it easy to write long, linear pieces of code is not a good thing. I think the opposite is what we really need: make it harder to type so that you spend more time thinking and creating a design that requires less code!
Snippet search integrated into the IDE is very useful. Yes, the snippets in the video aren't perfect. That isn't a big deal - those snippets will be modified/replaced.
"Programmers would still need to search for methods to call. You can use CodeMatch to write snippets that call methods and CodeMatch can also auto-import libraries (or insert the classes/methods inline)."
1. IDE plugin (Eclipse, Xcode + MSVS incoming)
2. Community driven snippets
3. Integrated into autocomplete
This approach is the trifecta of productivity for software developers.I remember years ago finding some "overly smart" autocomplete hints from IntelliJ that surprised me, for example typing paths to files and having it automatically guess at the path given the execution context and that blew me away.
At some point all of those "try and be extra smart" rules fell out of favor and seemed to disappear and just get replaced by more robust/concrete type-inference inside the IDE. I understand why, trying to be TOO smart and getting it wrong is absolutely maddening and helps no one, but it was still nice to see.
These clippets remind me of a middle ground, where the tool is trying to be very smart, but also requiring you to fill in the part it can't concretely guess at (e.g. path variables in the demo video).
The other big win here is that since this is essentially search plus paramaterized clippets, there is no reason this cannot work for Python, Ruby, Go, JavaScript and anything else you would want.
The community aspects of building up the repo is just brilliant. Best of luck to this team, this looks like a hell of a nice job!
4. version-controlled snippets so you can know if there are improvements / errors
add that, and we're golden. But stale copy/paste code is flat-out dangerous, and that's all this really is from a code standpoint, with a bit of magic and discovery. Not that I'm downplaying the tool - I think it looks really good. Just that using community-generated code is dangerous unless you either carefully curate it, or understand everything it does.I would never paste in a snippet of code from a bad programmer because the code would look ugly and wrong and it would be obvious.
So the risk is bad programmers copy/pasting from other bad programmers. Sounds like an argument against bad programmers, not copy/paste.
Not everything should be abstracted into a library. I think the example in their screencast is a good one.
Yes, if the snippet has a bug, you're copying that bug everywhere. But if it doesn't, it saves you from writing a potentially buggy implementation.
I believed for many years as a programmer the dogma against copy/paste. Now i use it, as I use any other tool, in a way that I find appropriate.
I totally agree, it's over-sold. But any time you're using something you don't fully understand, you run risks. Being able to be informed of updates / problems would change the entire practice of re-using snippets, and integration into an IDE is the perfect way to do so. You, as a contributor, could even learn of problems / improvements that others have found.
All I'm saying is, in my experience, developing systems and apps for 10 years, the "rare bug" you talk about is just not a big enough problem to warrant that kind of caution.
Because the kind of code that you put in a snippet and reuse is the kind of "glue" or boilerplate code that is a solved problem.
So you have a very good point, for longevity, that the snippets need to be versioned.
We're also building a feature to allow users to define groups and share snippets with groups.
As much of a hell as it will be to add / maintain, can I also request that they have version + library dependencies listed somewhere, somehow, so you automagically get the most-correct one? I realize I'm asking for a package management system, and I have yet to see one that isn't fugly, but I can dream, can't I? At the very least, I figure language-version is a necessity due to syntax changes.
Don't you think it would be better to write the code like this?
source = windows_desktop_folder()
for file in source.list_files_in_folder():
file.move_to_folder(source.subfolder("Photos"))
Or in my pidgin Java: Path source = windowsDesktopFolder();
for (Path file : source.listFiles()) {
file.moveToFolder(source.subfolder("Photos"));
}
It might take a little bit longer to write the code that way, but it seems to me that it would be a lot easier to read the code afterward when you have to debug it; and you could use the same search engine to search methods that you use to search snippets.(There's also the issue that, however good your snippet library is, it will contain bugs, and changes in the outside world will require corresponding changes in the library. One example is that my code here could conceivably run on MacOS or Linux, while the snippeted code hardcodes backslashes and therefore cannot.)
Edit: there's a special markup to add a method/class - click on the "Insert Formula" button when in the snippet submission form for instructions.
This results in software containing ten times less code, which makes it dramatically easier to fix, maintain, and extend, than a system built by copying and pasting code snippets.
Now, I am not going to claim that this is a new idea. Ada Byron, after all, invented the subroutine. What I am going to claim is that programming by pasting snippets together and editing them, which is not a new idea either, is a stupid idea. The idea is probably at least as old as the subroutine. We have something like 60 years of experience with programming by copy-and-paste. That's plenty of time to figure out that it's stupid. It's a bad idea. It makes your programs hard to understand and hard to change. We'll probably never stop doing it, because sometimes it's unavoidable. But having a search engine that makes it even easier to paste code snippets does not make pasting code snippets a better idea. It makes it a worse idea, because it means that you can screw yourself more quickly and thoroughly.
I want to see a case that you think is better written using pasted-together snippets of code instead of by calling subroutines. The burden of proof is not on me; I'm just explaining the conventional wisdom. It's on you if you want to show that the conventional wisdom is wrong.
I do think that a search engine for APIs would be useful, and that a lot of APIs suck.
You can use CodeMatch to write snippets that call methods and CodeMatch can also auto-import libraries (or insert the classes/methods inline).
Of course, this isn't featured in the video.
I don't program Java, but I might also be OK with having a program add type names where necessary. For example, you type "foo = new Foo()" and the software will add "Foo " in front, making the line "Foo foo = new Foo()". But, programming in terms of concrete instances is To Be Avoided, so maybe default to an interface and allow the programmer to toggle between the interfaces Foo implements. It would have to be a measurable win, though; typing FooI is not that hard, after all.
I'm definitely not discouraging the use of tools to make managing boilerplate easy; but it's a very fine line, some boilerplate cannot be eliminated with clever library use (imports), but some can (finding the path to the Desktop). Once you have a super-cool boilerplate generation tool, it becomes more tempting to add a quick snippet than to fix the language or library deficiency that's pushing you in the direction of too much typing.
Sometimes it's good to imagine things taken to the extreme. Imagine that C didn't have a preprocessor but it did have an editor that had really good snippets. Instead of saying #define PI 3.14 in your math.h file, the snippet would just type 3.14 in for you whenever you said "insert pi". This would produce the same object code as the preprocessor, but without another extra piece of machinery to mess up your source code. What you type is what the compiler sees!
Turns out that this isn't good, because computers are really good at pushing symbols around, but humans aren't. So don't show the humans the details, show them the abstract and let the compiler push symbols around.
(I've always wondered why someone doesn't add a preprocessor to Java. See also: coffeescript / javascript.)
If you're suggesting that the tool isn't useful or to be encouraged (as you seem to suggest in earlier posts), I'm interested in better understanding your rationale.
As far as I can tell, you have only critiqued possible ways that CodeMatch could be used, not CodeMatch itself.
The Java Overlords should take note: this is what the language should look like. It shouldn't take special software to be expressive.
I'd especially be interested in creating snippets for my own proprietary APIs, which are typically move more quickly and are generally less documented that big, established public APIs.
That said, my sense is similar to what yours sounds like -- the audience will remain small, just because it'll never be as fast, even after a tool like yours cuts down the entry time.
I'll ask around and try to generate some use cases or niches where mobile could take off, and get ahold of you if I do. I remember Paul G. talking about it a year or two ago, maybe if you can get ahold of him he could share his thoughts. Meanwhile -- nice work.
Curious that I'm so opposed to autocomplete in text editors when I'm so attached to globbing in my shell. What's the difference?
Well the first thing is that the shell doesn't use pop-ups that hide my code. This is my #1 problem with "over helpful" editors - popups appear, unasked for, right on top of the code I'm looking at.
Secondly, the shell only helps me out when I ask it to. I have to press <TAB> to trigger the globbing. If the shell can't guess what I want, then I just get nothing - I have to press <TAB> a second time to ask it to give me a list to choose from.
I'm not sure what the equivalent would be with a programmer's editor. The <TAB> key is pretty important for indentation, but a Ctrl+KEY combo might be too clumsy. Where could the list of choices go where it would be both near to the cursor and not obscure nearby code?
See http://www.emacswiki.org/emacs/Yasnippet for one option, http://www.emacswiki.org/emacs/AutoComplete#toc2 for another, and various bolt-ons to Anything: http://www.emacswiki.org/emacs/Anything
user: dougwightman
created: 591 days ago
And this is your first comment, along with an awesome submission! Welcome to HN ;)Snippets will also soon be browsable online (early September) :)
I see CodeMatch as a nice interface to access template-ized snippets, such as those that come with TextMate. Is it more than that?
I don't think I would use it myself, I'm a Vim guy, but I can see it being a very useful tool. Good work!