Hacker News new | past | comments | ask | show | jobs | submit login
Tern – Intelligent JavaScript editing (ternjs.net)
191 points by aerique on March 7, 2013 | hide | past | favorite | 79 comments



To be clear the author of this IS the author of code mirror! That should be in large bold letters on that first page (it is on the crowd sourcing page). My first thought was "really? this is just code mirror with added cleverness, sort of lame to profit from it" - totally different story when it's the author adding value to something he has already contributed to the community. In that case this is the "premium" plan for code mirror.


Note that Tern's core is editor-independent. I made the demo on top of CodeMirror, obviously, since I know it very well. But the meat of this project does not have anything to with the editor that's used to interact with it.


Still, I wouldn't be shy about the fact that you did CodeMirror. It makes a huge difference to me....you are a known quantity and convinces me that this is a solid project.

And I'd think that CodeMirror is the obvious thing to hook this into, for the rest of us as well.


That "added cleverness" is a big story in itself. Linking it with an editor is trivial. If you never tried to do static analysis on a dynamic language like JS you can't really appreciate just how smart Tern is (or wants to be).


It might sound like an abomination, but Visual Studio is apart from obv. being excellent in C++/C# also a very pleasant IDE for Javascript, Python or even PHP!

In fact i have been an "texteditor-only" type in the past, but coding C# in Visual Studio has really been a revelation for me.


I know. I was blown away by VS when I was researching what others were doing in this space. Their approach is also very clever -- there's an interesting talk about it at http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/DEV...


Care to mention what you found clever in their approach?


They basically run the scripts, instrumenting their Chakra JS engine to automatically abort overlong loops and overdeep recursion, and preventing all side effects outside of the DOM/JS runtime. And then use the actual types that occur in this run to do the completion. Plus, I guess, some added tricks that the talk doesn't go into, but which are necessary to make sure execution actually reaches the part of the program where you are trying to complete something.


Interesting. I wonder what they do to prevent side-effects. Perhaps it just knows to avoid any call that hits network or filesystem.


Does it ever get the types wrong? Just curious, I assume one wouldn't want to see the kind of code where VS gets the types wrong.


I was able to create situations where it failed to find any type for a variable, and when you have variables that may contain multiple types it appears to only find one type, but I wasn't able to make it report any actually wrong types. (But I haven't used it very much.)


"In fact i have been an "texteditor-only" type in the past, but coding C# in Visual Studio has really been a revelation for me."

The fact that application X is "just a text editor" is not a justification for X having poor editing functions. In fact, you'd expect a specialized text editor to have better editing functions that an IDE, since an IDE can have other selling points, such as an integrated build system, a version manager, a profiler or a debugger, whereas an editor can only impress you solely by its usability for...well, editing.


Yep you are right, i meant this more in a way of working style. In the past i thought its the best approach to only use a text editor and do everything by hand, know your Code, work like a pro etc. But just simple things in VS like "Jump to Definition" or "Find Usages" combined with powerful IntelliSense and Refactoring functions is such a joy to use. I didnt even talk about the debugging tools, but well i am an IDE guy now, at least for large projects.


Well, that looks really nice. I am not a IDE type, but I do enjoy nice coding helpers when I write. This, well integrated into say, Vim, would make Javascript programming really comfortable.


The cloud9 ide's open source javascript-based editor, [Ace](http://ace.ajax.org/build/kitchen-sink.html) can mimic vim mode.

Though ternjs's developer created CodeMirror, the platform would be agnostic of editor and could easily be ported to that.


upvote for vim bindings, that would totally rock!


"Tern is not currently open source. I'd like it to be, but I have to pay my bills. So I'm running a crowd-funder where interested parties can pledge money. If successful, Tern will be released under an MIT license."

Very odd model... take your code.


Your development of Redis is sponsored by VMWare afaik (which is awesome and so is redis), so whats wrong with crowd-sponsoring this guy ?

Sure it might be a trust issue, and it might be better to release the code first and then ask for money, but as it looks this guy has a good reputation in the community so i dont see too much of a problem.


I talk from a general point of view of my ideas, not as the Redis developer. Anyway for 1 year I worked at Redis for free, and it was open source since day 0.


do you really think these two projects are comparable, or for that matter, that their code-licensing models are comparable?


What do you mean?


I mean that from my point of view "gimme money if you want that open sourced" is very bad approach.

Either build your closed source business, or try to earn from an open source product to pay the bills.

1) What is the current state of the source code? It could be a mess.

2) The value of open source is mostly in continued developments, support, community, not just in releasing the code itself.

3) If you have this mindset, who guarantees me that tomorrow you'll write plugins that are closed and ask again for money to release?


As for trust, the JavaScript community knows me as the maintainer of CodeMirror, and apparently likes the way I'm handling that project. This seems to lead people to believe that I won't deliver a horrible mess, and that I won't try to rip them off after the fact.

Starting up a project with a crowd funding does not make it impossible to later fund continued maintenance by selling support and such. It is a way in which I'm safeguarding my initial investment.

In short, I still fail to see the problem.


I agree that trust is not at stake, but the implication bothers some people because it cuts against the culture of OSS (rightly or not). You may just be one of the early pushers of a profit model that hasn't had time to normalise. I'll be interested to see.

EDIT: cut down for brevity


The point is, this is not a model at all IMHO, since a model requires the ability to work in the long run.

So you know wrote code for 1 month, and you want to be crowdsourced. Ok, what's the plan for the continued development of the project? Code as it is is worth zero without bugfixes, evolution, and a community.


A) I have written some software

B) I'm debating whether to take the OSS or commercial route, since I do need money to live

C) I have a reputation for maintaining software in a serious way

So I'm asking people "If this is worth 10k to you, let's go the open-source route". So far, it looks as if it is worth that to people. Unless I'll turn around and act like a complete bandit, destroying my reputation, the model works. It does require the reputation part, I guess. But I'm quite puzzled why you are so hostile to it.


I'm not hostile about you, I'm hostile about your model, since I care about open source, and OSS for me is not a license, but a culture and a model for the development of the computers industry.

I think there are things that play nicely with the open source model, that is, ways to make money that don't interact in a bad way with the culture of free software. I don't think that to ask to be payed to open source stuff is in line with the OSS movement / culture.

Ok, now that the hostile bit is discussed, my argument is that it makes more sense IMHO if you say, there are N people willing to donate me 10$ per year if I open source this stuff? It's still wrong IMHO as a model, but at least makes sense, that is, you will get money to provide the software relevant, updated, documented in the future.

The una tantum system instead is broken, how you'll make money in the future in order to continue the development, since it is clear you don't write this software if you are not backed in some way?


He's already shown that he is willing to support his stuff without additional payment, he's done so with CodeMirror.

When taking on this project, he presumably factored it in, that he'd want to continue to support it. If not, well, those of us who chipped in probably won't chip in on the next thing he does. I'm willing to take that risk.

And even if he doesn't...so what? It's open source. Other people can continue the work, and if they want to do something ambitious enough to justify crowdfunding as well....more power to them.

You may be right that what he is doing isn't "in line with the OSS movement/culture." Richard Stallman would likely agree with you...he was never one for shades of gray. I would argue that if that is true, that the OSS movement/culture is the thing with the problem.


I've been doing something like that (try to get people to make regular payments) with CodeMirror, in the form of selling commercial support. I've found it hard to get people to continue to pay, and a major time drain to keep track of all the paperwork involved. A crowd funder driven by a short hype is simply much easier to manage.


Thankfully you're already on Gittip, I'll happily support what you're doing. I'm working on a similar cause. :)


I am puzzled by his hostility too. I hope you or others following your model don't worry too much about it. I'm chipping in.

I wish you luck in meeting the goal (it looks likely you will) and look forward to using what you've produced. I love CodeMirror, btw.


I agree with antirez point of vue. To write a software is one thing, you can be crowd funded for that, no problem. What Antirez is saying, as far as I understand it, is that your software is not valuable if you don't have a sustainable model in the long run. You'll still have to pay your bill the day the software will be released open source. In that perspective, crowd funding might not be a solution. So in the end, I think what Antirez is saying is that you probably should choose between releasing open source (and find something else to pay the bills) or go and make your project sustainable by making it something like licensed closed sources.


I'll point out again that launching by crowd-funding is in no way incompatible with being sustainable. It just eases the burden of the initial investment.


I think both have valid points, but in such a way that Marijn is right.

I did start cool open source projects without crowd-funding. It happened at certain points in my life when I didn't really need extra-money (or when I had sufficient free time — essentially the same thing). It is possible.

Today? I'm not sure I could start anything substantial today without funding. My life is not the same as it was 3 years ago. Things change, and somehow paying the bills gradually becomes harder each day than it was the day before—I don't know why life has to suck this way, but so it happens.

There's quite a narrow frame in everyone's life when one can start major free projects without any income — and I'm probably approaching the end of it. Kudos to Marijn for he manages to do so well, and still provide free tools of outstanding quality! (and in case you didn't notice, the demo is quite impressive — the thing is alive, not vaporware).

On the Antirez side now, it's true that a project without a community is as good as dead (he also mentions evolution and bugfixes, but a community is a prerequisite for that). I certainly have projects that could benefit enormously from having a community — but it just didn't happen, for some reason. (OK, I know why: Emacs and Lisp are Just Not Popular).

Tern is not likely to suffer from lacking a community, because it happens that JS is the most popular language on the planet and Tern solves a Hard Problem. You could think of Tern as the smarter big brother of JSLint. JSLint employs brute-force to find potential mistakes, while Tern employs smartness to help you find real semantic errors, or to improve the way you write code. It's unique. I don't think it'll suffer from lacking community—au contraire, I hope the community won't be as invasive as to murder this project by bringing into it tons of "I'd like my code to look that way" features — but then again, I trust Marijn for being able to trim down feature requests and leave in only what's meaningful, rather than particular use cases; and for particular use cases he will totally be able to make a living by providing custom support and development and this will eventually raise the quality of the project on the whole.


One time crowd funding might not be sustainable, but recurring crowd funding may be.


I'm sorry, I laid my sentiment over your point and ended up missing the argument. Bad conversation on my part.

You're saying, A value proposition worth paying for would focus on support, not software availability. Yeah?

I'm unsure whether that's always the case. And as the OP is pointing out, support is implicitly included by his need to maintain a reputation. I'm not sure the profit model has to explicitly include it.


> This seems to lead people to believe that I won't deliver a horrible mess

That, and View Source.


What does it matter?

Does it harm you in some way?

If it works, it works. If it doesn't, it doesn't. And either way, we've learned something. There's one one approach or set of approaches that are blessed and known to work 100% of the time.

I was more than happy to support it given the fine work that he's done in the past and how easy it has been to get answers from him about CodeMirror.

If this helps him produce more software or release some of what he's already written, then great. I'd rather he do this than get a more traditional job and have the fruits of his labor locked up.

But either way... what's the harm in trying a different approach? What's the harm in (potentially) giving him the opportunity to continue doing what he enjoys and does well?

If you don't want to give him that opportunity, that's fine. But there's little need to cast aspersions, right?


So don't donate. I think its awesome that he's doing it, and the fact that he did CodeMirror open source should count for something.

I think it's an excellent model. I hope it makes the target, so he doesn't have to go the closed source route with it. And I hope more people do things this way.

Even if he doesn't continue developing it (leaving it to others to do so) or if he wants to write closed source plug ins, so what? That's not what the 10k is for. If he wants to make a big enhancement to it in a year and crowd fund that, I say go for it.


Marijn Haverbeke has a stellar track record of work in this area, so this should be taken more seriously than usual.


Just to lend some more credence to this statement, we (LightTable) have actually contracted him to work on CodeMirror and have been nothing but happy with the results. He runs a tight ship and the output is great. CodeMirror is a fantastic editor (I say this as an ex PM on the Visual Studio editor) that continues to get better every day, it has been invaluable to our work.


Looks cool! How do you gauge the difficulty of adding support for CoffeeScript to this?

Re the indiegogo campaign: I think you should consider adding an extra supporter tier between 25 USD and 1000 USD. The 200 USD tier of CoffeeScript Redux http://www.kickstarter.com/projects/michaelficarra/make-a-be... brought in over 20% of the total amount pledged.


Interesting. Their 200 dollar tier is basically my 'all backers' tier (name in a readme file). But I can probably come up with something slightly more valuable to offer at ~250€.

As for CoffeeScript support -- the only major piece missing there is an error-tolerant CoffeeScript parser. Given that, one could simply run the CoffeeScript compiler over code, and analyze the output. There'd be some shuffling with source maps needed to translate source locations in the various representations of the code, but that's a solved problem. Well, and of course you might see some translation artifacts. The CS output code is semantically close to the input, but there are differences.


a signed copy of your book? :}


I don't know Marijn's hourly rate, but perhaps one or two hours face-to-face on Skype?


I find most of these attempts to code-completion in JS to be annoying, like bad speech recognition, if the accuracy is poor, it becomes frustrating. Not to knock their attempt, but I find that if codeassist isn't like 98% accurate, it often becomes more work to step through all of the wrong entries and not find what I want, then to just type it out.

The closest I've seen to something that works well is IntelliJ IDEA 12, when working with ActionScript, Closure annotated JS (JsDoc'ed libraries), or by comparison, the Dart editor.

With IntelliJ 12, if you're looking at a library with enough JsDoc on functions, the type inferencing seems to be a lot more accurate. Find Usages, Go to Definition, code-assist, all seem to be more pleasurable to use.

I don't like Flash, but ActionScript3 in IntelliJ is as close to the Java/C#/et al experience you'll get with respect to accuracy of assist. Probably wouldn't hard to port this over to JSX or Typescript which have similar syntax.


If you're using completion to verify that a thing has the type you thought it has, then yes, Tern won't help you much. If you're using it to save keystrokes, it certainly will.

Slightly related, I'm working on a feature where it distinguishes wild guesses from probably correct information by showing a different icon in the completion list.


I love autocompletion (even when it is half working, like intellij when the inheritance marking annotations don't always follow through, my cleverly optimized jsdoc markup for backbone and co broke down when switching to idea12). It saves me so much time looking stuff up and APIs, and if it can indicate the number and name of arguments required, i usually don't have to use the docs anymore.

And M-./find usages is very useful too, even when it is not perfect.

I pledged, and hope you will get enough funds together.


Another way to go about it would be to mark the keywords that seem mistyped or auto-correct them. That would be less intrusive for people who don't want to select from drop downs.


The newest PyCharm uses an interesting dynamic approach. You can run your app in their debugger and enable collecting of type parameter info (at a significant performance loss, however).

So when you have a function like: def foobarize(f): return f.something *2; then it will know what types f might have when foobarize is called. Now when you go back into the editor, it can give you a hint about it.

Other than that, it uses some type hints from docstrings (you can tell it type foo is YourClass and it will complete based on that) and light type guessing.


I disagree, I believe TypeScript/VisualStudio provides a closer experience than AS/IntelliJ. The inference and refactoring work quite well. And they are in their infancy, generics are coming very soon.


Can you give an example of where AS/IJ fail and TS/VS succeeds? IntelliJ's started supporting TS recently and will likely improve. Their whole brand is multilanguage support and they support more languages than any other IDEA. For example, WebStorm 6 added TypeScript, CoffeeScript, and Dart.


I think that anybody who works with JS should support this project and its author (Marijn Haverbeke of the Eloquent JavaScript fame.)

P.S. Works fine on Chromium Version 24.0.1312.56 Ubuntu 12.04 x64


IntelliJ's WebStorm has pretty JavaScript code completion and related tools. It also has plugins for popular libraries and frameworks, node.js and a variety of other HTML5 / latest-web-coolness stuff. Seems like a lot of folks in the AngularJS community have been using it it as well.

Disclaimer: I liked it enough to buy a personal license :), but am not affiliated with the folks who make and sell it.


Backed. Like everybody who touches JavaScript should do. Also. mmmm finally decent vim bindings for javascript?

I do wonder how it will compare to Eclipse Orion's JavaScript content assist which is using Esprima as parser.

http://contraptionsforprogramming.blogspot.nl/2012/02/better...


(I'm the author of Tern -- I'm obviously biased.)

It compares very favorably. The Orion approach, as I understand it (I only did some quick messing around with scripted, am not an expert) is very local, whereas Tern tries to do whole-program analysis. This should allow it to pick up much more information.


Is it able to track all dependencies in a web page for autocomplete? I mean, keywords defined in dependent files - do they automagically work?


Not magically. That part is, for now, in the scope of the IDE/editor plug-in. You can feed Tern a set of files to analyze, but Tern doesn't, for example, scrape HTML files to determine inclusions.

The one exception is requirejs-style dependencies. Those, if you give Tern some information on where to look, it will resolve and automatically include. I'll do something similar for node.js-style require calls in the future.


"whereas Tern tries to do whole-program analysis."

I suppose you're not doing live type feedback? Given a test suite for the code being edited, that would seem like a natural thing to do.


Just contributed, as I'm intrigued. Have you seen Chris Granger's LightTable? (http://www.lighttable.com/) I think there's some overlap, although his vision is much broader.


Chris commented above that Marijn is working on LightTable.


Not on LightTable itself, but on the editor component they use (http://codemirror.net)


Backed, I really love to see this working on SublimeText. I tired it with my own code and it managed to bring correct return types and object properties from all functions. I hope you release it soon. Thanks for the effort


On my Mac (10.6.8), using Firefox 19.0 I get the right mouse contextual menu when I use CTRL-SPACE in the first example with the Tern selections displaying behind it. I don't see this behavior in Chrome or Safari.


Curious how this compares to Brackets. I haven't played with their latest sprint yet, but they also seem to be working on adding auto-complete to JS in CodeMirror.


Amazing, but it could be even more awesome if you could provide API that could be integrated with other editors.


As NuZZ noted, this is the plan. It is already written as a library with a server-like architecture (you send requests and get JSON responses). The vision is to wrap it in a stand-alone HTTP server shim that understands .tern-project files that you can drop in your project directory, and then write editor plug-ins that talk to this server (and automatically start it up if it's not already running).


> But that is a proprietary system tied to a single IDE. If the crowd-funding succeeds, Tern will be an open system that can (and will) be plugged into a variety of editors and IDEs.

Hopefully, that will happen. Sounds very cool though, as my IDE, sublime text, is rather underpowered in the intelligence department I'm afraid.

I could imagine it applying .tmLanguage scopes to words in the document, where you could colorize different variables according to type (I would opt for different background shades, myself). Then, mixed type colors (prompting you to click it and see what Tern says) when you can't know. Damn, that would be helpful.


I typed "[[[[" and the script became unresponsive (hung).

Repeated by reloading the page. Same result.

FireFox / MacOS.


Should be better now. It was a change I made half an hour ago. Ad-hoc changes to sites that are receiving traffic always do that.

[You'll need to hard-refresh to get the fixed code.]


That's bad. I'll look into it right away.


Working fine on Chrome 24 on Linux/x64.


The browser tab hangs on Chromium 24.0.1312.56 on Kubuntu 12.10 (when typing [[[[).


Weird, I'm on almost the exact same version (24.0.1312.57) and it does nothing when typing any number of '['. I have the branded version of Chrome, though, but still, weird!


The problem is fixed now, so the fact that it works shouldn't come as a surprise.


The demo doesn't seem to work on Chrome 25.0.1364.152 m. I'm getting this error whenever I try any of the shortcuts (or when I select a command from the drop down):

Uncaught TypeError: Cannot set property 'curOrigin' of undefined (infer.js:489)

Looks interesting though!


That was another quick update that broke things. I fixed it ~20 minutes after I pushed it, but I guess you exactly hit the window where it was broken.


This is really great work. I'd love to see it for VIM.


Looks like VIM is one of his first priorities. From the indiegogo page:

> The funding goal is computed to allow me to work for three months at about half the income I make with my usual consulting work. (The other half is made up in the satisfaction of building the thing I want to build.) In addition, I'll spend some of it to engage a Vim expert to help me build the Vim plug-in in a way that fits the culture for that editor.

Definitely chipping in.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: