Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

pros and cons of serverside javascript implementation?

I just started experimenting with Aptana Jaxer server side javascript engine for my next project. And i have few quesions about that

  • By using server side JS, can we implement the whole web application without using any server side languages (like C#,java etc). Or server side JS sits in between the web server and other langauge stack.

  • Is it really a better approach ??

  • what are the advandages and disadvandages?

  • how this works well in terms of performance?

  • is there any real time implementation (public websites) only using server side JS(no other languages)?

  • what are the alternatives available over Aptana jaxer (open source)??

  • how well we can implement & maitain db transactions? can we do that in serverside JS..?

  • is it possible to develop RESTFul and SOAP services in serverside JS..??

i know this is too long (and naive questions). I am just hoping someone have already come across all these while implementing serverside JS.

EDIT:

As per Matthew & Ken comments, i have added some clarity to the question Is it really a better approach??

this is what i intend to ask..

Is it really a better approach than using server side languages (assume c#), how we can compare this with the c# implementation of a website (performance , language features)?? And which one is a better approach , using JS alone in serverside or JS in middle layer between other language stack and webserver??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am the developer for Myna (www.mynajs.org), an Open Source server-side JS platform based on Rhino and Java. I'll address the issues as they relate to Myna, but many of these points apply to server-side JS in general:

By using server side JS, can we implement the whole web application without using any server side languages (like C#,java etc). Or server side JS sits in between the web server and other langauge stack.

In Myna it is possible to write your entire app in JS. Myna already includes API's for Database access, Object Relational Mapping, crytogrophy, OpenID, etc.

Is it really a better approach than c#/Java?

With a Rhino based server it is trivial to drop down to Java whenever needed. You can easily install open-source/commercial/hand-coded Java libraries and then script them from JS. This means you get the rapid development of JS but maintain the advantages of the Java platform

what are the advantages and disadvantages?

pros:

  • Rapid development: In Myna you just create files in the webroot with an .sjs extension. This means you can create an edit-save-refresh browser cycle with is very fast for debugging/tweaking code.

  • Easy JSON: Having JS support server-side means moving complex structures is very easy

  • Shared code: If you need to perform the the same function on both the server and the browser, you can use the same code

  • Dynamic ORM: Statically typed compiled languages make it hard to alter objects at runtime. This usually means that ORM has to be defined in advance. In Myna building ORM is as simple as

    var manager =new Myna.DataManager("DataSource name").getManager("table name");
    

    You get an object that can do all basic CRUD operations without ever explicitly defining the DB tables. As another example you can insert a row with all the matching values from a form post:

    manager.create($req.data);
    
  • Functional Programing: If you have started playing with advanced JavaScript features then you will appreciate how helpful they are server-side. Because of the consistent server-side environment it is safe to use advanced features such as Array Extras, generators and iterators, destructuring assignments, and E4X

cons:

  • Tools: Statically typed languages like C# and Java have excellent IDE and developer tools. Dynamic languages like JS just don't have the tool support yet. Personally I find that the large reduction in boilerplate code and fussy type casting makes up for this, but this is still a big disadvantage if you have been doing a lot of development in IDEs. If you are currently using an IDE, consider using jedit for dynamic languages

  • Maturity/Standardization: Serverside JS is still a new paradigm, and there are many players and no clear winners. ECMA does not have any standards for serverside JS. As mentioned in Brandon's answer, the CommonJS group is attempting to form a serverside JS standard and Myna has experimental CommonJS support via Narwhal

how this works well in terms of performance?

In raw computational speed, few dynamic languages can match statically typed compiled languages like C# and Java. Having said that, it really doesn't matter. Any part of your application that is computationally intensive should probably be written in Java, or use an existing Java library. I wouldn't suggest that anyone write a Database in JS for instance. For real world web applications/SOA services, the primary cause of slowdowns isn't raw computational speed, it is inefficient code, especially database access. Myna helps with this by doing things like:

  • internally caching compiled JS scripts
  • Internally using cached prepared statements for database transactions
  • Query and output fragment caching
  • Database connection pooling
  • Automatic ETag hash support
  • Profiling tools
  • Lazy loading of metadata

how well we can implement & maintain db transactions? can we do that in serverside JS..?

If you mean transaction as in "a set of SQL statements that can be reversed or committed", then Myna does not yet support transactions. I am open to implementing this if there is enough interest.

If you mean "what kind of database support does server-side JS have?" then the answer is platform dependent. The Myna platform provides the following database features:

  • A web-based administration application where you can define "datasources", i.e database connection information. You can then query these datasources by name. Myna includes JDBC drivers for H2, MySQL, Microsoft SQL Server, and Postgresql, but any JDBC or ODBC datasource can be used
  • Myna.Database and Myna.Table provide database-neutral metdata access as well as table creation and modification.
  • Myna's Query object supports maxRows, paging, SQL parameters,custom row handlers, query-of-query, caching and more
  • Myna's DataManager object supports runtime ORM object creation

is it possible to develop RESTFul and SOAP services in serverside JS..??

REST and SOAP support are platform specific features. Myna's WebService object supports the following protocols:

  • SOAP
  • XML-RPC
  • JSON-RPC
  • Ext Direct
  • JSON-MYNA (a simple protocol that uses normal form posts and returns JSON. Easy to use from the browser)

Myna also understands the PUT and DELETE request methods and presents access to request body content in both text and binary form, so that it is possible to handle these RESTful methods in an application specific way.

Debugging

Traditional breakpoint debugging is a real challenge serverside. Although Rhino supports debugger hooks, using these from a stateless web app would be pretty involved. Personally I don't even use breakpoint debuggers even when they are available (e.g. firebug). Instead I prefer logging.

In Myna,

 Myna.log(type,label,detail)

will spawn a low priority thread to write an HTML log message to Myna's logging database. These logs can then be searched through the Myna Administrator. Logs also record timestamps and elapsed milliseconds for profiling purposes. Myna.dump(obj) can also be used to present an HTML table representation of any object. Myna also logs all un-handled exceptions with stack traces, source code context, and request details. Between dump(), log(), and the default error handler I haven't much difficulty debugging Myna code


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...