views:

1565

answers:

11

When should one use a scripting language over a more verbose, compiled language like C++. C# or Java?

And to make the question a little more interesting, let's answer the questions like this:

You should use a scripting language when... BLANK...

When you need A use scripting language X.

When you need B use scripting language Y.

When you need C use scripting language Z.

+15  A: 

You should use a scripting language when speed of development is more important than speed of execution.

Paul Stephenson
How about the second part to the question dealing with specifics, like A, B, or C?
Alex Baranosky
I assumed your request was for answers to be in one of the suggested formats, not all of them. I thought I answered the question as asked: "_When_ should one use _a_ scripting language?" (Not "_Which_ scripting language should you use.")
Paul Stephenson
This about sums up any real reason I can think of to need a scripting language.
Daddy Warbox
A: 

How about, whenever you want to?

Ubersoldat
+1  A: 

This is slightly a religious issue. I use a scripting language for ad-hoc tasks, such as:

  • looking for a specific item in a ten-thousand lines log
  • Generating a performance graph
  • Data reduction - transforming a text file into a needed format
  • Getting a specific subset of data from a database and packing it as a text file

All of these can also be done in a compiled language, but for me it is faster and easier to do them in a scripting language (I use ruby, but PERL and python are just fine).

Yuval F
+1  A: 

I find scripting languages very useful obviously when there's a specific task that fits the language's strengths (i.e. string processing with perl, web development with ruby, or whatnot). In particular with web-development scripting languages have the property of showing you results of code changes faster.

There are some cases where you mix compiled languages with scripted languages - like in some games. It's useful to do that when you can express a smaller amount of behaviour faster, cleaner and simpler in a scripting language than in the compiled language. C++, for example, is a very expressive language - but it's development costs are higher than, say, lua.

mstrobl
A: 

I use scripting language to mine data and feed them to database as a cron job. It's easier because i can easily set them using windows scheduler or crontab in unix and i find it easier to write due to some key features like regex in perl.

Plus the millions of modules that are made availble to me from CPAN...

melaos
+8  A: 

Adding a scripting language as a component of a larger compiled system is a common pattern: the compiled part of the system is optimized for speed of execution, but is harder to modify (because it must be compiled and reloaded), whereas the scripted part of the system is optimized for flexibility, it will run slower but can be quickly and easily modified by anyone with a text editor.

You would use this pattern if you wanted to make part of the functionality of your application easy to customize.

Michael Mathews
+2  A: 

I tend to use scripting languages for rapid prototyping, experimentation, and data wrangling. For example if I have a bunch of text files that I need to preprocess and build into database fixtures as a one-off operation, I'll generally script that.

However, these days the line between 'scripting' and 'compiled' is becoming blurred, with languages like groovy and ruby. For the task mentioned above, I'll use ruby but then I'll also use it to build a production webapp with rails. I'll write desktop apps in java but groovy allows me to blend in scripts as well. Even when writing in C/C++, I found a useful pattern was to embed a domain specific scripting language (e.g. tcl, though I don't much like that language).

The actual choice of language is I think a religious choice, though there are some tradeoffs that are obvious (readability for example - perl is useful, but is too easy to write cryptic scripts in. In some ways it is a 'write-only' language :-). In the past I've used bash+awk+sed, some perl, ruby, etc etc...For one off tasks it is mainly a matter of what you and the rest of your team are comfortable with. I make a conscious choice to use ruby these days even if I'd be somewhat quicker doing the same thing in bash/awk/sed, but this is just to improve my ruby skills by doing as many tasks as possible in it.

frankodwyer
A: 

Use a scripting language when interactive operation is important, e.g. a command-line shell, or you are exporting functionality for other users to use in simple operations. (They shouldn't have to compile; scripting is enough)

Jason S
A: 

I dont't think theres a general rule when to use a scripting language. Scripting languages are easy so develop but sometimes they are hard do maintenance, especially when the script should run under different platforms (operating systems).

The pros of scripting languages are of course:

  • You can give the user (or customer) the possibility to change something in your script by himself.
  • It's easy to develop - the most scripting languages are not type-safe, what it makes much easier to develop in small applications, of course
  • But - it's platform independent...

Contras are:

  • It' s open source - everyone can see your code and can use your knowlege in their own competiting products...
  • It's slowly at runtime...
Robert Wismet
+1  A: 

Here's my hierarchy:

Try it using grep.

If you can't do it with grep, use sed.

If sed isn't powerful enough, use awk.

If awk isn't powerful enough (or starts to get really nasty-looking), use C, C++, or the other full-blown general purpose programming language of your choice.

Notice there's no "scripting language" in between awk and C. That's on purpose.

T.E.D.
A: 

Scripting language if you plan on either writing once, or keeping it simple. A stongly typed language is much better once your project becames larger and you really need to do complex exception handling, logging. Think about it, how much time is spent on a large project with intital development versus integration and maintenance. Would you rather have to maintain a large script or a strongly typed language?

Zombies