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.

I've been talking with a friend about the purpose of Javascript, when and how it should be used, etc. He quoted that:

JavaScript was designed to add interactivity to HTML pages

[...]

JavaScript gives HTML designers a programming tool

  • HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages JavaScript can react to events
  • A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element JavaScript can read and write HTML elements
  • A JavaScript can read and change the content of an HTML element JavaScript can be used to validate data
  • A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing
  • JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser.
  • JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer.

However, it seems like Javascript's getting used to do a lot more than these days. My friend also advocates against using Javascript's OOP functionality, claiming that "you shouldn't be processing data, merely validating." Is Javascript really limited to validating data and making flashy graphics on a web page?

He goes on to claim "you shouldn't be attempting to access databases through javascript" and also says " in general you don't want to be doing your heavy lifting in javascript". I can't say I agree with his opinion, but I'd like to get some more input on this.

So, my question: Has Javascript evolved from the definition above to something more powerful, has the way we use it changed, or am I just plain wrong? While I realize this is a subjective question, I can't find any more information on it, so a few links would be good, if nothing else. I'm not looking for a debate, just an answer.

share|improve this question
    
I was also wondering "who" is pushing it to do that and why? –  Emmad Kareem Mar 19 '12 at 0:18
    
I would place the source material for what your friend has come to understand about JavaScript at about 1998. –  Erik Reppen Mar 5 '13 at 15:52
add comment

3 Answers

up vote 15 down vote accepted

People who think JavaScript is not a programming language are people who's opinion on JavaScript you should not respect.

JavaScript is a language that has grown organically inspired by semantics of Scheme and syntax of Java. It's original purpose was not general but it has now grown to be so.

JavaScript as a language is suitable to do just about any task if it's fit for it. Take a look at examples like node.js where JavaScript has access to host environment consisting of IO functionality which allows it to be used for generic server side programming

My friend also advocates against using Javascript's OOP functionality, claiming that "you shouldn't be processing data, merely validating." Is Javascript really limited to validating data and making flashy graphics on a web page?

No, JavaScript is a programming language, if you want to represent data structures, algorithms and logic then use the tools the language offers. Specifically 1st class functions and prototypes are powerful tools.

He goes on to claim "you shouldn't be attempting to access databases through javascript" and also says " in general you don't want to be doing your heavy lifting in javascript". I can't say I agree with his opinion, but I'd like to get some more input on this.

Wrong, In the browser we have a database called indexedDB which we access with JavaScript. It's a database baked right into the browser and if you want to use it (and you should) then you use JavaScript.

Also note that both mongodb and couchdb allow you to use javascript to run adhoc queries on the database directly.

As for heavy lifting, he's partly correct. If your doing heavy lifting you should be doing it in C or erlang. Although note that the term "heavy lifting" is vague, for example I wouldn't encode or decode videos in JavaScript, I wouldn't do image processing in JavaScript (use C). I wouldn't no number crunching in JavaScript (use fortran).

Has Javascript evolved from the definition above to something more powerful, has the way we use it changed, or am I just plain wrong

JavaScript was written in a period of 2 weeks just to slap minor scripting functionality into HTML. Since then it has grown severely. Since ES3 (1999) it has been a powerful general purpose programming language.

share|improve this answer
    
That's what I thought, too. Now I just need to figure out how to convey that to my friend. –  Elliot Bonneville Mar 19 '12 at 0:26
    
@ElliotBonneville May I suggest a big foam cluebat? –  todofixthis Mar 19 '12 at 3:58
    
Hahaha, yes you may. :) That's hilarious. –  Elliot Bonneville Mar 19 '12 at 12:59
    
"powerful general purpose programming language" that is full of gotchas that will stay there forever because of backwards compatibility: codeproject.com/Articles/182416/… –  Den Aug 15 '12 at 8:34
    
@Den yeah it has some gotchas, but so does C, C++, PHP and Java. –  Raynos Aug 15 '12 at 20:47
add comment

The vision of your friend is effectively very obsolete, and misses everything which happened since Google released GMail.

Now, does this mean that Javascript developed beyond what it was originally designed to do? Sort of. But don't forget that the design changed meanwhile, and will change in the future according to the new needs from the developers. This is also valid for other popular languages. For example, when the first version of C# was released, no one would expect to allow dynamic code in the design. Now DLR is available for a few years.

share|improve this answer
add comment

Language always goes way over what we thought at the begin. Talk to anyone at the beginning of C (or C++), does someone thought that language will be found almost everywhere now. I don't think so.

Each language win to be learn more / push further.

I agree that Javascript was/still a under-appreciate language, your friend isn't the only one. The problem isn't think that the language X or Y is bad/useless, the problem is to keep this idea forever. In Computer Science / IT, everything change quickly, and it will still change a lot in the future.

That's why it's important to keep learn / think outside the box...

share|improve this answer
    
I don't think many people could reasonably say that JavaScript is still an under appreciated language. In fact, I think it's the world's most popular language. –  Jim G. Mar 19 '12 at 3:08
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.