Home Download Buy Blog Forum Support

Javascript code generator quiz

Javascript code generator quiz

Postby ubuffon on Thu Dec 27, 2012 7:30 pm

Hi everyone.

I would like to write a plugin for JS code generation in addition to standard snippets.
It is always useful to be able to form your thoughts of future software architecture into some real code. Usually I grab a pen and a paper and start drawing entities, objects, relations, etc. But since I am developer, the code preview of future architecture is also very helpful.
To explain the idea more clearly, consider the following example (simple class creation):

Code: Select all
class Player with name:string, score:int, keys:array, enabled:bool, active = true methods someMethod, anotherMethod(a, b = 123)


and the plugin will expand it to:

Code: Select all
function Player() {
    this.name = ''
    this.score = 0
    this.keys  =[]
    this.enabled = false
    this.active = true
}

Player.prototype.someMethod = function() {

}

Player.prototype.anotherMethod = function(a, b) {
    if (!b) {
        b = 123
    }
}


After reviewing generated code I might bury it, modify or edit the original line ("class Player ...") for further generations. After forming the desired application skeleton the developer should proceed with editing using standard sublime features like snippets and other plugins.
The example is very straight-forward, syntax, generation format will differ in real plugin (or not :) ).

Please tell me if you would like to see such kind of a plugin and if so - I'll start working on it, taking further feature requests.

Thanks in advance.
ubuffon
 
Posts: 11
Joined: Tue Jul 24, 2012 10:57 am
Location: Russia

Re: Javascript code generator quiz

Postby olex on Thu Dec 27, 2012 7:52 pm

I think it's a nice idea for the plugin, very helpful one.

I'd gladly use it.
olex
 
Posts: 1
Joined: Thu Dec 27, 2012 7:45 pm

Re: Javascript code generator quiz

Postby agibsonsw on Thu Dec 27, 2012 8:43 pm

I know you have just shown sample code but.. JS statements are semi-colon terminated, as should be the prototype assignments.

Be aware: supposing I want to assign b the value of 0?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Javascript code generator quiz

Postby ubuffon on Fri Dec 28, 2012 6:42 am

agibsonsw wrote:I know you have just shown sample code but.. JS statements are semi-colon terminated, as should be the prototype assignments.
Be aware: supposing I want to assign b the value of 0?

It is really, really raw example, without any significant impact on the final result. I guess anyway I would use some kind of a required/optional flags to determine what argument should be skipped from testing. Or I would not include such kind of a functionality at all :)
The main question for now is - do anyone need this plugin or it is useless since developers usually just print the code right out of their heads :)
ubuffon
 
Posts: 11
Joined: Tue Jul 24, 2012 10:57 am
Location: Russia

Re: Javascript code generator quiz

Postby agibsonsw on Fri Dec 28, 2012 1:38 pm

I think you will find feedback a little hard to come by on this forum. If it is something that interests you then I would go ahead! In the process, it might encourage you to explore other ideas ;).
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Javascript code generator quiz

Postby ubuffon on Fri Dec 28, 2012 2:00 pm

agibsonsw wrote:I think you will find feedback a little hard to come by on this forum. If it is something that interests you then I would go ahead! In the process, it might encourage you to explore other ideas ;).

Yeah, seems to me it is the only correct answer :) Thanks!
ubuffon
 
Posts: 11
Joined: Tue Jul 24, 2012 10:57 am
Location: Russia

Re: Javascript code generator quiz

Postby agibsonsw on Fri Dec 28, 2012 3:25 pm

You might consider doing this for TypeScript. It has a more formal structure and, is therefore, more suitable for templating. Besides which it is very new and there is currently limited support for it in ST. Just an idea ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: mlf and 7 guests