5

Just a quick query ...

I would like to ask people's opinions as to which language is most similar to javascript? I don't program for a living, but I have been learning javascript in my spare time. I would now like to have a shot at making a desktop application, and I think it would help to choose one which is most similar, if at all possible, to javascript?

e.g. python, ruby, C#, visual basic ... I have no idea and haven't had much luck googling this

Thanks

Matt

Matthew Klein
  • 51
  • 1
  • 2

8 Answers8

7

Why not use Javascript? Who says it can be used only for "online" programs?

There's a Windows Script Host on Windows that allows you to run Javascript programs from the command line or double-clicking in Explorer.

Other OS's have similar script engines.

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • +1. There's even OSes built around JavaScript: http://code.google.com/p/es-operating-system/ – back2dos Jan 03 '11 at 15:22
  • 1
    +1. I never understood all those "which language is most like X" questions. There is only one sensible answer to those types of questions: X. By definition, there cannot be any language that is more like X than X. – Jörg W Mittag Jan 03 '11 at 17:09
  • the twisted question comes from the false premise, that Javascript cannot be used for a desktop app. – Cheeso Jan 04 '11 at 01:29
6

It depends on what you mean by "similar". Syntactically, JavaScript is part of the syntax tradition derived from the B programming language (C, C++, Java, and C# are others in this syntactic tradition). But that's just syntax. JavaScript isn't much like those (although both C# and, to a lesser extent Java, are getting more and more "functional" features added to them). If you're writing for Windows, you might take a good look at C# (and a subset of it is supported on Linux, in the form of the excellent Mono project).

You might look at JScript.Net, which is a language for the .Net platform that's, well, I'll say inspired by JavaScript. Again, that's a bit Windows-ish although (again) Mono provides a good layer for Linux.

Visual Basic (.Net or otherwise) will not be a good fit. Fairly easy syntax (BASIC was designed for easy syntax), but not very much like JavaScript.

If you don't mind a syntactic departure, both Ruby and Python are dynamic languages like JavaScript, and both are fairly popular these days for desktop apps (at least on Linux).

You certainly could use JavaScript if you want to. Someone else mentioned Adobe AIR, but I'll throw out another one: Rhino, which is JavaScript for Java. That gives you access to the huge collection of Java libraries out there (as the JavaScript code can interact with Java code and vice-versa). Whether you want to do a desktop app using Java technology (even though writing JavaScript) is obviously going to be up to you.

For command-line apps, you can use V8 directly, or NodeJS which uses V8 but has a lot more (and on Windows, JScript with Windows Scripting Host).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
1

You can use Adobe Air to run Javascript + HTML + CSS.

David Murdoch
  • 87,823
  • 39
  • 148
  • 191
1

Although JavaScript can be used offline, I wouldn't use it unless I had to. The choice of language depends on what you want to write. If you want to write GUI applications for Windows, C# is a much better choice. If you want to write scripts for data analysis etc, there are good languages for that, like python.

Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
  • @back2dos Sure. C# has great built-in libraries for pretty much everything, and is very easy to program with because of the great Intellisense support in Visual Studio. – Ilya Kogan Jan 03 '11 at 14:57
  • If you're going to limit yourself to .Net, JScript.Net would, [as rsenna points out](http://stackoverflow.com/questions/4585257/offline-language-most-similar-to-javascript/4585473#4585473), be a better match for what the OP asked. ;-) – T.J. Crowder Jan 03 '11 at 15:06
  • 1
    1. This doesn't explain, why Python should be better than JS. 2. Regarding libraries, C# has no advantage over JavaScript. You can simply use JScript .NET (http://tinyurl.com/yyt324) to leverage the full .NET framework if you want. Also, there is **plenty** of JavaScript libraries for about any use. The mozilla foundation uses JavaScript for GUI applications (thunderbird, firefox etc.). There are many IDEs that use type inference to provide autocompletion. If Visual Studio doens't, then this is Microsoft's fault. – back2dos Jan 03 '11 at 15:20
  • @back2dos No IDE I've tried even comes close to Visual Studio from the usability point of view, but I guess this is personal. – Ilya Kogan Jan 03 '11 at 17:21
1

If you're looking to create Desktop applications with little-to-no experience, it may be better going for an Express edition of Visual Studio, which comes in Visual Basic, C# and other flavours. You can create both desktop and web applications for free.

C#, C++, Java and JavaScript share a lot of syntactically similar language features; braces etc. You'll hopefully find once you get used to the syntax is easier to transition to another language too.

Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
  • Of the 3, I would say C# is the closest one. C++ is too complex (for a JavaScript only programmer), and Java lacks lambdas and the `var` keyword. – rsenna Jan 03 '11 at 14:39
  • 1
    @rsenna - Luckily C# isn't all about lambda expressions and `var` ;) – Matthew Abbott Jan 03 '11 at 14:40
  • agreed, even if not that relevant. :P In fact I also don't think that `var` makes such a big difference, but **lambdas** do - current JavaScript frameworks make extensive use of lambdas and overall functional techniques, so a JavaScript programmer would be much more "at home" when using C#, IMHO... Of course, C++ would also allow that (by using the functional extensions of the Boost library, for instance), but the syntax would be very harder to grasp. – rsenna Jan 03 '11 at 14:50
  • 1
    Luckily C# also isn't all about `class`. But how far would you get without it? – back2dos Jan 03 '11 at 14:51
1

Believe it or not, but one language that is very similiar to Javascript (although not syntactically) is Scheme. Take a look at this article by Douglas Crockford. It might not provide you out of the box tools for making fancy desktop applications, but it is a good language for learning important programming idioms.

darioo
  • 46,442
  • 10
  • 75
  • 103
1

And let's not forget JScript.NET!

(even if everybody else did).

Edit - another option for the .NET and Mono frameworks (and somewhat unknown to standard, non-game programmers) is UnityScript (but I don't even know if you may use it outside of the Unity 3 development environment). Seems to be JavaScript with classes and inferred static typing (maybe similar to ActionScript).

rsenna
  • 11,775
  • 1
  • 54
  • 60
  • **Big +1**. I was just doing something else and slapped my head: "JScript.Net!" Edited my answer, then thought: I'd better go check if someone's said that since I was last here and upvote them... – T.J. Crowder Jan 03 '11 at 15:04
0

Thank you for all the extensive replies. Sorry I was not able to check back sooner.

So as a sort of conclusion it was wrong of me to assume I cannot make desktop apps using javascript. Actually, shortly after posting my original question I stumbled across AIR myself. However, and correct me if I wrong, it all seems a bit "bloated" (hot air ?). To deploy it on some other maching it will require AIR to already be installed? Indeed, it would download as a .air file, and I don't think there is a way to make an executable. Some other, more knowledgable people also listed many of its limitations on another site.

I also investigated Rhino (thank you Crowder). However I could not find much of an explanation on the Mozilla site of how I could use it by just scripting in javascript? The example they offer for download was full of java code ! ?

Anyway, it seems at least that it is possible to make a .exe which can run in the console for, say, simple number crunching. I will have a go at this. I suspect that things will get more tricky if I want to make some sort of GUI.

Thanks again for all the excellent replies

Matt

Matthew Klein
  • 51
  • 1
  • 2