Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is there a way to play the role of Javascript with any other language like C#? One way came up in my head is, having silverlight installed, using C# instead of Javascript for all the client side scripting (Though C# is not a scripting language). Is it possible?

I am not talking about something like GWT(Java) or Script#(C#). Probably the question can be stated as- "With silverlight installed, can I do everything supported by Javascript(like DOM manipulation etc) with C#?" Hope it's clearer.

share|improve this question
2  
Why would you want to do this? –  Darknight Mar 29 '11 at 10:28
    
Comfort of working with known/expertise language –  Aditya P Mar 30 '11 at 5:05
    
C# and Javascript share the same C style; so your already starting off on a good footing... –  Darknight Mar 30 '11 at 12:29
1  
...and then you stumble horribly on things like block scope, hoisting or prototype inheritance. C-like syntax is the worst thing that happened to js. –  scrwtp Sep 24 '12 at 10:47
    
I love both C# and JavaScript, and I agree with scrwtp. JavaScript should have used a completely different syntax than the one it did. There's very little in common between C# and JS besides the "(){};" characters. –  Graham Sep 24 '12 at 12:20
add comment

8 Answers

You have a few options for using other languages in place of Javascript:

  • You can use any language that you can compile to javascript (like coffeescript, Java via GWT, etc),
  • You can use any language that you can interpret using a javascript interpreter (many templating languages use this technique),
  • You could use nativeclient to deploy your language (I'm unsure of the support for DOM interaction from nativeclient, so I'm not sure how viable this is), but in any case the take-up will be small,
  • You could add support for another language into a browser and struggle with next to no users.

Only the first two techniques are really to be considered. If you detest javascript so much, take a look at coffeescript.

share|improve this answer
    
It's hard to debug in the browser anything that isn't javascript. You can't use debugger in you coffeescript. If there is error in your coffeescript compiled to javascript, you may have trouble to find out to which line it corresponds in your coffeescript sources. The solution is something called "map sources", but it's not yet implemented in any of browsers. –  Czarek Tomczak Sep 24 '12 at 7:31
add comment

One way to do this is to compile code in language <put language name here> to Javascript. This has the advantage that the compiled code can run wherever Javascript can run.

Emscripten can be used for languages for which there is compiler(s) which produce LLVM bytecode (C and C++ are just 2 of these).

Emscripten works by generating Javascript code from LLVM bytecodes.

share|improve this answer
add comment

It is a little unclear on what you are after.

Can the browser interpret other languages than Javascript? No, but some "X to Javascript" compilers exist. For example GWT will allow you to write Java code and compile it into Javascript.

The browser can have plugins to allow other platforms to work within them. Such as Silverlight, Java, Flash and Unity. But you would need to get the user to install the plugin and the plugin to exist for your platform.

Why are you against Javascript? It may appear clunky to begin with but a fairly decent little language lives under the cloak of "bah it is a web language".

share|improve this answer
add comment

Unless all the major browsers implemented the language, or a plugin was provided for all the major browsers and you managed to convince your users to install it, then no, Javascript is the only option.

But really, what's wrong with Javascript? As a language, it's actually really nice and quite powerful. The biggest "problem" with Javascript is differing implementations of the DOM across browsers, and introducing another language isn't going to solve that problem.

share|improve this answer
    
using jQuery will solve many of the problems of the DOM. –  Zachary K Mar 29 '11 at 9:38
1  
@Zachary: Right, but jQuery doesn't really have anything to do with introducing a new client-side language... –  Dean Harding Mar 29 '11 at 9:42
    
no, but it does make Javascript a lot more enjoyable to use. –  Zachary K Mar 29 '11 at 10:18
add comment

Intresting question!

A bit of googling no offence :) found jsc, which lets you port C# to javascript.

What is jsc?

jsc is a decompiler or a cross compiler if you will. It is not a source-code parser nor an IDE. It is a command line utility like any other compiler. jsc was originally an anagram for csharp to javascript.

I need to do some web work and I know very little javascript, so I'll be trying this out.

share|improve this answer
    
You can check Script#- projects.nikhilk.net/ScriptSharp –  Gulshan Mar 29 '11 at 10:50
add comment

If you are into python, you can use Pyjamas .

Currently project name is pyjs. This is the description of the project:

pyjs is a Rich Internet Application (RIA) Development Platform for both Web and Desktop. With pyjs you can write your JavaScript-powered web applications entirely in Python.

pyjs contains a Python-to-JavaScript compiler, an AJAX framework and a Widget Set API. pyjs started life as a Python port of Google Web Toolkit, the Java-to-JavaScript compiler.

Interesting part for the OP will be the "python-to-javascript compiler".

share|improve this answer
add comment

With Silverlight installed, your client is coded in C# right?

You don't need DOM manipulation if you use Silverlight - Silverlight is a plugin that works inside the browser (similar to flash) and is a separate runtime. You can do things similar to DOM manipulations (for e.g. showing/hiding fields, animations, etc) but all this will now be done in XAML and C#, not with HTML and Javascript.

Hope that clarifies - a silverlight application has no need for Javascript features.

share|improve this answer
1  
I think he means to still use HTML, but to have an invisible Silverlight object doing DOM manipulation. –  Chris Sep 24 '12 at 13:37
    
why.. why... whyyyyy!!! –  Roopesh Shenoy Sep 25 '12 at 14:23
add comment

GWT is using Java to generate JavaScript code, so I think something similar would be possible with C#. However you probably can't just replace JavaScript on client side with other (scripting) language.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.