views:

971

answers:

10

I'm interested to know who uses JScript.Net and for what sort of applications. Whenever I'm reading MSDN .Net documentation, I always notice the JScript samples but in all the years I've been a C# dev I've never actually known anyone to use it.

What sort of applications are people using this for, and how does it measure, in terms of flexibility, power and general usage, to C#?

[Edit: Just to clarify - I'm not asking what JScript.Net is, I'm asking what people are actually using it for - i.e. interested to know actual usage scenarios and how people have found it to work with]

A: 

The JScript.NET Wikipedia page is pretty explanatory: http://en.wikipedia.org/wiki/JScript%5F.NET

In short, it seems to be JavaScript with the .NET library.

vrutberg
Hi vrutberg, thanks for taking time to answer, but I wasn't really asking what JScript.Net *is*, I'm asking what people are actually using it for (in the wild), and how they find it in comparison to other .Net languages, especially C#.
Rob Levine
I don't think I'm capable of answering that question. However I guess I could make a sort of educated guess. Since it needs CLR to run I don't think you could use it very efficiently on the web (if at all), so we can put aside client side web programming. With that in mind, I think the answer is pretty close to what Shimmy wrote: "it could be awsome for web developers who're used to write in plain JScript and want to get the benefits of .NET without need to learn a new language". So I think that's part of your answer, web developers who want to try out desktop application programming. :)
vrutberg
I'll be honest - I'm kinda interested to see whether anyone actually replies and says "I use JScript.Net". I've just never known anyone to actually use it in anger.
Rob Levine
I've once used JScript.NET to very quickly write a simple tool to complement the main application, on-site, when the customer asked for this functionality and it was urgently needed right there and then.
Pavel Minaev
-1: This doesn't answer the question.
John Saunders
"I've just never known anyone to actually use it in anger" LOL
Liao
A: 

JScript .NET is a modern scripting language with a wide variety of applications. It is a true object-oriented language, and yet it still keeps its "scripting" feel. JScript .NET maintains full backwards compatibility with previous versions of JScript, while incorporating great new features and providing access to the common language runtime and .NET Framework (from JScript.NET).

Besides, you might find this stackoverflow post helpful as well: Can JScript.NET be used to script a .NET application?

As for who is using, I am honestly not aware of (I am pretty sure there are out there).

Read Introducing JScript.NET.

My personal thought was that it could be awsome for web developers who're used to write in plain JScript and want to get the benefits of .NET without need to learn a new language, or for those who want to have all their code written in one language.

Shimmy
It should be noted that, with respect to "providing access to CLR and .NET Framework", JScript.NET is somewhat dated. For example, it doesn't know anything about generics, and won't let you reference generic types, or call generic methods. In terms of implementation, it uses reflection heavily with no additional optimizing layers (like DLR), and so is rather slower than e.g. IronPython. Given that it hasn't been updated since VS2005 (and seemingly isn't updated in .NET 4), it seems that IronPython is the official .NET scripting language of choice now.
Pavel Minaev
@Pavel, definitely agreed, was just trying referring to the OP's request; I am with you on the same page.
Shimmy
In addition to what Pavel has stated, JScript.Net has not only stagnated since VS2005 - it has been, for the most part, deprecated. JScript.net also does not support ref/out arguments, which is a major pain if you stumble upon it. Fortunately, replacing it with IronPython is quite simple (we use JScript.Net/IronPython as a scripting interface into our apps).
Kevin Pullin
@Kevin lol, yes right... No Generic support, no Entity-Framework support, no linq no nuttn, I think it's basically a .NET 'scripting' language, rather than a "CLR" language, even it still is.
Shimmy
+14  A: 

Rob - I have used JScript.NET in anger in one place in my code, which is essentially to expose the functionality of its eval method. Here is a cut-down version:

static public class Evaluator
{
    private const string _jscriptSource =
        @"package Evaluator
        {
           class Evaluator
           {
              public function Eval(expr : String) : String 
              { 
                 return eval(expr); 
              }
           }
        }";

    static private object _evaluator;
    static private Type _evaluatorType;

    static Evaluator()
    {
        InstantiateInternalEvaluator();
    }

    static private void InstantiateInternalEvaluator()
    {
        JScriptCodeProvider compiler = new JScriptCodeProvider();

        CompilerParameters parameters;
        parameters = new CompilerParameters();
        parameters.GenerateInMemory = true;

        CompilerResults results;
        results = compiler.CompileAssemblyFromSource(parameters, _jscriptSource);

        Assembly assembly = results.CompiledAssembly;
        _evaluatorType = assembly.GetType("Evaluator.Evaluator");

        _evaluator = Activator.CreateInstance(_evaluatorType);
    }

    static public object EvaluateToObject(string statement)
    {
        try
        {
            return _evaluatorType.InvokeMember(
                "Eval",
                BindingFlags.InvokeMethod,
                null,
                _evaluator,
                new object[] {statement}
                );
        }
        catch (Exception)
        {
            InstantiateInternalEvaluator();
            return null;
        }
    }

You can obviously create overloads for other return types. I can't claim the original idea for this was mine! Uses for this would be, for example, to evaluate a string expression like 3 + 4 to 7 without expression parsing.

David M
Great snippet David!
Shimmy
Since you are using the JScript compiler here, how is this any simpler than creating a C# snippet and compiling that using the CSharp compiler?
bruceboughton
C# doesn't support the eval method
David M
Cool, but is this really using JScript.NET, or just connecting a C# project to the JScript.NET interpreter as a scripting engine, similar to the DLR? I was under the impression the question was what "applications" the language was being used for.
brianary
@brianary - "application" has more than one meaning. This is not using it as a scripting engine - the JScript is compiled once and then run as any other compiled .NET code.
David M
Yep that's what I've used it for, the eval. Very very useful since the days of .NET 1.0
Mike Gale
There is a *much* easier way of doing it : just put the Evaluator class in a source file, compile it with jsc.exe, and reference the resulting DLL. That's also more efficient...
Thomas Levesque
+1  A: 

I don't know how it compares performance-wise, but I know that JScript.NET is one of the languages you can use with Unity 3D.

rossisdead
Unity3D exposes a JScript like language called UnityScript, but it's not JScript.NET that is used behind. It's the Boo compiler with a JScript frontend.
Jb Evain
+1  A: 

I'd just assumed it was used by Microsoft to inflate the number of languages .NET supported at launch for marketing purposes.

brianary
-1: Doesn't answer the question, and besides, they _implemented_ the language! That's a lot of work for marketing purposes.
John Saunders
I think it does answer the question if at least one of its uses is as a bullet point somewhere. Besides, it isn't as if they didn't have several JavaScript implementations laying around already. ;)
brianary
The question was who uses it, and what for. The fact that you have made assumptions is not an answer.
John Saunders
Who uses it? Microsoft! What for? Selling .NET! The fact that no one has yet responded (in much more time than it took SO to generate a superior algorithm for leettime generation, surprisingly) with anything other than simple JScript.NET exercises, and that it is missing basic .NET features like "out" params certainly makes it the most likely answer to the question, doesn't it?
brianary
Seriously though, there are some useful answer posted all over this question. Even from some people that say they used to use it before iron python. All of which posted before you. So what was your point again?
Kevin Peno
brianary
I have to say I'm pretty disappointed in the downvotes and the overall level of discourse. So far this the only reply that answers the question, by essentially saying "none" to the question of real-world JScript.NET application development. For some reason, that has angered some folks who would, I guess, like to shoot the messenger.
brianary
@John Saunders: I won't say this is a good answer, given that the questioner asked for "What sort of applications ... terms of flexibility, power and general usage" but the actual, rather than declared, purpose of a language is a useful thing to bear in mind when evaluating a language. So -(-1) from me
Charles Stewart
+5  A: 

JScript .NET is one of the languages supported for writing application extensions for Sony's family of media editing products. Sound Forge & Vegas.

In particular Sound Forge has a window that you can use to edit and run scripts to manipulate audio files.

It turns out the Microsoft made it pretty easy to add scripting to your application using one (or all) of the .NET supported languages. VB, JScript & C#. Just just have to expose some objects from your application and hand those objects (assemblies actually) to the compiler along with the user's script text.

They have a web forum for script writers for Sound Forge

John Knoeller
Would you say it's easier to mess with audio thru JScript.NET than with VB.NET or C#?
Shimmy
@Shimmy: I think JScript and C# are about equal, while VB.NET is a bit less capable due to the fact that VB has no native unsigned integer types.
John Knoeller
+3  A: 

With the Business Process Management tool Metastorm BPM you can use JScript.Net to extend your workflows. For example you can add custom .Net .dlls to the engine and interact with them in your processes using JScript.Net.

My experience was quite positive. I've implemented just some small glue scripts but I'd prefer scripting with JScript.Net to VBScript (the second supported Scripting Language) anytime.

David Klein
+2  A: 

I'm late to the party here, but I want to add my take:

I see JScript.NET being useful for server-side code. It's pretty natural to use something server-side that is essentially the same as what you use client-side. Also, it makes working with JSON that much easier so can be a boon if you're creating a web service that communicates via JSON.

I wrote a web service where I work in C# but am thinking of migrating to JScript.NET because of those reasons.

Bob
+2  A: 

I use it quite a lot, almost exclusively, for ASP.NET and related web-stuff.

You can use it for pretty much all the stuff you can use the other .NET languages for. It makes MSIL, just like the others ;) Compiled with the "fast" option which turns of some of the native javascript traits, like prototype extensions and eval, it performs just like any other code on the CLR.

It's certainly not a full-fledged member of the family, in the sense that it seems somewhat left behind in .NET 1.1 in terms of features, the tool support is non-existant, and the documentation is downright appaling. That's part of why I like it so much, actually, makes me feel like I'm programming.

If you have a lot of (j)scripts lying around that needs to be converted to .NET, this is the obvious choice as you will usually need very little rewriting for that to work. Otherwise there's no particular reason for choosing JScript.NET over any other .NET language, and many reasons not to.

It all comes down to personal preferences since it all ends up as the same CLR code, regardless of language. I find JScript.NET easy-going, natural to write and with a flexible simplicity like no other language I tried, so I use that until I encounter a problem that the language just can't handle. Hasn't happened yet.

Torben Poder
Thanks for the answer Torben - that's interesting stuff.
Rob Levine
+1  A: 

Well, I'm trying to use it. I can't say I've been successful.

I've not done a lot of web coding in any environment, but here is my 2 cents.

I wanted to expose some database tables to a web page, so I threw together a quick Classic ASP (yeah, yeah, I know) page that pulled the data from SQL Server and returned the table as a JSON object. Rather than locate a JSON serializer for VBScript I just wrote both sides in J(ava)script and imported json2.js on the server to provide serialization. It worked great; honestly it took less than an hour to have it spit back a nice JSON representation of the table, 50 minutes of which was a fruitless attempt to get JScript to import json2.min.js directly rather than throwing <% %> wrappers around it and renaming it json2.min.asp.

But everyone says it is sick and wrong to use Classic ASP in this day and age, so I'm trying to replace my quick & dirty ASP + Jscript + ADO implementation with ASP.NET + Jscript.NET + ADO.NET. After some head-pounding-keyboard moments I have ASP.NET v4.0.30319 up on IIS6 and have a "hello, world" page that does some simple loops javascript via the <@ language = "JScript"> directive. So far so good.

I were following Best Practices here I'd be wrapping everything in a class etc, but as I'm just try to get out of the driveway I tried doing a quick port of my existing code, which imports various useful bits of Javascript from other files using ASP include statements.

Including some simple stuff using <--#incude file="somejsconstants.asp" --> worked fine and let me access constants from that file. But my attempt to pull in the JSON serializer with<--#incude file="json2.min.asp" --> didn't work, and firing up a version of json2.js suitably modified to be a standalone aspx page and threw the same error. (The compiler error is Objects of type 'jscript_aspx' do not have such a member.) JScript.NET seems to be unhappy with the use of closures, a near-omnipresent construction in today's javascript libraries.

From postings above it's clear there are plenty of ways to serialize JSON objects in the .NET platform, but my gut feeling is that if JScript.NET barfs on Javascript written by Douglas Crockford, then it is a quirky, incompatible rathole not worth investing my time in. I might as well follow the ASP.NET masses and use C#.

Robert Calhoun