-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples in JavaScript and CoffeeScript? #65
Comments
Well, I know CoffeeScript is not to everyone's liking... so my goal is that Plugins can be written in JavaScript as well (+ any other language that can be directly translated to JavaScript. E.g. TypeScript, Haxe, etc). As for the documentation, I thought of it too, however I decided to postpone it until the API has taken its final form. (Right now, the API is at very good level, so I believe it might be time to start doing what you suggest :) ) |
Now, I've been re-thinking about the JS vs Coffee (and remembered the initial reasons that made me choose Coffee over JS). Have a look at this example case - the Haxe Linter builtin. This is what it looks like in CoffeeScript: https://gist.github.com/osxpeppermint/2acfee2179eb077ff2a2 Well, the second one is undoubtedly 100% pure javascript. However, to be perfectly honest, given the way plugins are (meaning: being a "class" offering its private methods, inheriting parent methods, and all that (which is not originally supported by JS)), I doubt if I myself could even recognize or debug my code... Don't know, perhaps it's a matter of taste. It just seems to me that the 2nd version looks much more complicated (unless I make a "simpler" model only for JS-based plugins - which I had done in the past, although it has to be revisited if we want to get this whole thing working). P.S. Surprisingly (or not), I've never been a JavaScript guru, so any ideas are welcome! :) |
Yes, in the end it is a matter of taste. IMHO every other language that transpiles to JavaScript is going to generate JavaScript in the end. And if you're tracing through code with a debugger, you're going to see JavaScript. Most developers who have learned a streamlined version of JavaScript started off with JavaScript. You can't very well have examples in every language based on JavaScript; but anyone can read JavaScript and translate that into their preferred language - whichever one that is. So, to me, put the examples/documentation/API in JavaScript plus CoffeeScript, if that's your preference. If someone writes in Haxe, doesn't know CoffeeScript, and has to read documentation in CoffeeScript, they have a problem. But that person probably knows JavaScript - much like someone writing in LESS or SASS knows CSS, |
I understand what you mean and I agree 100%. My main concern is that - given how Peppermint plugins work - I have to find a way to make the JavaScript version (if someone chooses to directly code in JS) more... user-friendly and not as complicated as it currently should be (in order to conform to the Plugin coding standard). To put it simply: JavaScript was not designed neither for Classes nor for inheritance. So, forcing someone who wants to write a pure JavaScript plugin, use all this "extra" code (just look at the JS version above) with "extends" and all that, doesn't sound good to me. A simpler function/object format would be a lot better. (But this would mean Peppermint would have to figure out the "extras" itself. And perhaps add them automatically. Otherwise, the plugin wouldn't be able to function as a Peppermint "plugin") |
Hmmm. Atom uses CoffeeScript/CSON by default. But in every case, JavaScript/JSON can be substituted and Atom just uses that instead. Seamlessly. |
Well, Peppermint can use JS too, right now - as long as e.g. the main script file is not a "script.coffee" but a "script.js". It will be processed correctly. |
So you're good to go? Show the API examples in JavaScript and everything just works? |
Yep, that's true. As you said yourself, JavaScript is the core language. So, even if there is some preference for CoffeeScript (purely for reasons of readability), all CoffeeScript plugins are - quite obviously - converted to JS before being executed. And in any case, JS was the way plugins were written at the very beginning. So, recognizing them in 100% JS is still included. (though not... showcased) |
I am revisiting a bit the idea of JS plugins. Now, here's what I believe is the simplest possible form of a JavaScript-only plugin. How readable/self-explanatory is it?
|
That looks pretty reasonable, to me. Is that how JS plugins work now, or is that a feature to come? |
Well, the way JS plugins would work now is a little bit more complicated. This is what it could be - to make it as readable as possible (and automate some of the not-so-readable part, from Peppermint - during plugin processing). I don't know. I'm still thinking about it... |
Here's another way JavaScript plugins could be written in the future (this is the general idea I'm probably going to use):
I think it's fairly straight-forward and as uncomplicated as possible. |
That's very clean and clear. Who could complain? I'd say do it. |
You got me thinking with your latest messages so... I've been thinking of ways to reach out to the JavaScript audience as well. And making it easy. Let's see... :) |
Another thing though would be ES6 (basically the next version of javascript). It's not supported by many browsers - yet (and Safari is not in the list). However, there is already a way of making it work and getting ahead (via https://babeljs.io/docs/learn-es2015/) |
True. And my partial understanding of ES6 suggests it brings many of the advantages of CoffeeScript to JavaScript, too. |
As of 1.5 beta 20, the main CoffeeScript alternative for Plugins will be the model exactly as shown in: #65 (comment) (the only thing needed is a ".js" extension for the script file, in a few words So, let me revisit plugin creation (this time for JavaScript)... General Plugin Structure My Plugin Title.ppPlugin/
"My Plugin Title" is the title of the plugin as shown in the Tools menu. info.json
The only required options are: "name" (the name of the class/function as described in script.js -- The absolute minimum required
|
And a more... complete example, showcasing the Plugin power:
|
P.S. Regarding what I was saying about ES6, Peppermint right now can support ES6 syntax (using Babel and script.babel files). However, until it is widely adopted and more stable, it will remain mostly experimental and undocumented). |
P.S. (b) I will keep this issue open, until I manage to make the documentation... bilingual... :) |
Plugin creation documentation - as an experiment - in GitHub Wiki: https://github.com/osxpeppermint/peppermint/wiki/Creating-a-Plugin I'm also planning to migrate this to the site + convert all API examples to JS (although to be honest, most of them will be like 100% identical). |
Looks good! Is beta 20 coming today? |
:) As for the next release, I have already done a lot of work (+ background work for core things coming at some later point), but I'm planning it for tomorrow until I iron out a few more details. |
I much prefer coding in standard JavaScript; can documentation examples be given in both JS and CS?
The text was updated successfully, but these errors were encountered: