Which scripting language do I start with?

  • Thread starter loom91
  • Start date
  • Tags
    Language
In summary, the conversation discusses the speaker's experience with different programming languages, particularly those considered "industrial" such as C, C++, and Java. They express interest in learning a scripting language and mention the variety of options available, including Perl, Python, Ruby, and PHP. The conversation then delves into a debate over which language is best for web development, with some advocating for PHP's simplicity and others arguing for the versatility of languages like Python. The conversation also touches on the different syntax and features of each language, with a focus on Python's dynamic and concise nature compared to Java's static and verbose syntax. Overall, the conversation offers insights and opinions on the various scripting languages and their strengths and weaknesses.
  • #1
loom91
404
0
Hi,

I've been programming for some time now, and I've learned the so-called industrial languages, like C, C++ and Java. Now I want to pick up a scripting language, but I'm getting confused by the variety. Even if I take the most well-known options, there are Perl, Python, Ruby and PHP. Which of these is better to learn first? Thanks.

Shish
 
Technology news on Phys.org
  • #2
Having used all four, I'd say:

Python is the simplest, it is also the most java-like. I would suggest starting there.
 
  • #3
I was also leaning towards Python a bit. Why is PHP preferred for web development?

Molu
 
  • #4
Hi loom,

I probably shouldn't try to speak for other people, but there are two reasons I think why PHP has such incredible popularity for web development these days.

One is that PHP files actually are basically HTML files with embedded code, like JSPs. So like

Code:
<html><title>A random number between 1 and 10</title>
<?php echo rand(1,10) ?>
</html>

is a PHP program. I think a lot of people find this approach to web programming easier than having to litter their code with PRINT statements or whatever.

The other reason is that PHP is extremely easy to learn, especially for people with no previous exposure to a programming language. Its data types and basic structures are extremely simple, and subtly molded to the tasks you're most likely to encounter in day-to-day web programming. Someone who advocates PHP over, say, Python might argue that Python expects a bit too much of you, that it is too strict or makes things too complicated if you are just writing a simple CGI script. With PHP you just pick it up and you're moving immediately.

The problem, in my experience, is that PHP does not scale up-- it makes the easy things super easy, but it makes difficult things in some ways more difficult. Someone who has previous experience with a C-like programming language may find PHP too simple, simplistic maybe. The same tools that seemed sublimely convenient for the basic construction of a web page turn out to behave in occasionally strange and frustrating ways when you start using them for more complex tasks. Then there is the question of versatility. Although Perl, Python and Ruby have healthy communities using it for a wide variety of applications including but not limited to CGI, PHP basically doesn't exist outside of web programming. There are a wealth of libraries and frameworks for using PHP for web work, but if the scope of your PHP program starts to broaden to something not normally part of web programming, you may find it difficult to find adequate support or libraries to implement that part of the program; if this happens you will have to do it yourself, and you will be doing it in a language that is in some ways unhelpful when you go outside of the simple web programming tasks it was sculpted for.

This is my opinion at least.
 
  • #5
Coin said:
The problem, in my experience, is that PHP does not scale up

I agree with your analysis. I learned PHP and wrote some simple programs (webpage commenting software, with security of course) and found it very easy to use. But for anything beyond basic projects it becomes a real pain.
 
  • #6
I've been programming for some time now, and I've learned the so-called industrial languages, like C, C++ and Java. Now I want to pick up a scripting language, but I'm getting confused by the variety. Even if I take the most well-known options, there are Perl, Python, Ruby and PHP. Which of these is better to learn first? Thanks.

Depends what you want. I suggest the phrase "scripting language" is misleading, as it doesn't describe a language as much as a particular way of using it. It's hard to argue, for instance, that python isn't an "industrial" language suitable for extremely large applications as well as small scripts. (Ask YouTube).

Perl is probably the best for working with text data, although as a whole it is a badly designed and severely broken language. I think largely obsolete for general-purpose programming. Its syntax is very odd, which partly explains its steep learning curve. Ruby is related to Perl, and shares a large subset of its syntax in common. Its implementations are very poor, though. Python is an extremely good general-purpose language with no major flaws, and I'd recommend it over the other two.

Python is the simplest, it is also the most java-like. I would suggest starting there.

Python is absolutely the opposite of Java. Python has dynamic type inference, as opposed to Java which infers types at compile-time and requires static type annotations. Python has dynamic objects, which can be modified at run-time (creating new variables, defining new methods, etc.) Without static typing, there is no formal method of class inheritance: "duck typing" replaces the notion of "is a" with "can function like a". Python supports functional programming, treating functions as first-class objects: functions as arguments and return values, functions which manipulate functions, dynamically-defined functions (closures), and so on. Python's syntax is designed to be very concise, whereas Java is famous for being verbose: Python does not use curly brace block delimiters, nor semicolons for expressions; it has native syntax for lists, strings, hashes (not class syntax); it has no type annotations; it does not require explicit 'return's, and so on. Python is an interpreted language: programs can be run interactively in a "read-eval-print" loop, which completely changes the nature of debugging.

Java isn't anything like this:

Code:
Class Cat:
   def meow(self):
      print "meow!"

kitty = Cat()
kitty.meow()  # meow!

def bark():
   print "woof!"

kitty.bark = bark
kitty.bark()   # woof!

print dir(kitty)   # ['__doc__', '__module__', 'bark', 'meow']

Or this:

Code:
def twice(f):
   def ff(x):
      return f(f(x))
   return ff

def square(x):
   return x*x

print twice(square)(5)  # (5^2)^2 = 625

Or this:

Code:
def integrate(f, low, high, res):
   dx = high - low
   if (dx < res):
      return f((high+low)/2.0) * dx
   return integrate(f, low, high-dx/2, res) + integrate(f, low+dx/2, high, res)

def square(x):
   return x*x

print integrate(square, 0.0, 1.0, 0.0001)  # 0.333333333023

import math
print integrate(math.sin, 0, math.pi, 0.0001)  # 2.00000000077

Or this:

Code:
print reduce(lambda a,b: a*b, range(1,11)) # 10! = 3628800

Or this:
Code:
a, b, c = 10, 20, 30
print b  # 20
I was also leaning towards Python a bit. Why is PHP preferred for web development?

PHP was designed for web development, but its being the most popular is mostly a historical accident.

One is that PHP files actually are basically HTML files with embedded code, like JSPs... I think a lot of people find this approach to web programming easier than having to litter their code with PRINT statements or whatever.

No one uses "PRINT" statements: every language used by web developers has templating systems analagous to PHP's, where one embeds dynamically-created content in a "skeleton" of HTML. Here's http://www.djangobook.com/en/beta/chapter04/. (Non-framework) PHP is actually much weaker with templating, because it mixes the application logic with the template - there is no distinct templating system. Often PHP programs combine application logic and display logic in ridiculous spaghetti code - usually with SQL, CSS, and javascript mixed in as well. I would recommend starting web programming with a framework, as opposed to raw PHP (PHP has frameworks too). A framework actively enforces abstraction barriers, avoiding bad habits. Something like the Django framework for Python, or Rails for Ruby.
 
Last edited:
  • #7
Wow, thanks signerror and Coin, really helpful replies. It seems to me from your examples that a lot of Python's power (apart from the convenient syntactical sugars) comes from it allowing a functional programming approach. So I think I'll start learning Python after I pick up a little purely functional programming with Scheme from The Structure and Interpretation of Computer Programming.

Molu
 
  • #8
Oh, it's not just functional programming - that's just a tiny part of it, and not even that good. (They actually scaled it back in Python 3, relegating some of the features to modules). The dynamic nature - dynamic type checking, dynamic, run-time modifiable objects, introspection (objects that can examine their own structure) is the big strength. Nice syntax, overall language consistency and design, all together it's a very good language.

Scheme is a much stronger FP language, and it is also much smaller (it's designed for academic use). SICP is an extremely good book, although I should warn you it's written for university computer science majors, and as such is much "heavier" than your usual O'Reilly programming language book. It's not about functional programming either.
 
Last edited:
  • #9
I'm not really worried about the heaviness, I'm sure I can handle SICP after having dealt with the abstraction of real analysis. But signerror, why do you say that SICP is not about functional programming?

Molu
 
  • #10
Because while it is immersed in the functional style, that is not its main focus.

Don't forget, the full text is free online:

http://mitpress.mit.edu/sicp/
 
  • #11
If you can avoid PHP, do. It's a monstrous but occasionally useful language. Perl always looked like a bit like Scientology: normal people avoid it, there are a ton of horror stories, and a few rock stars who think it's awesome. Python and Ruby it is then.

I love Ruby a lot. Do a lot of work in it. The Ruby 1.8 interpreter isn't very quick, although Ruby 1.9 is apparently a lot better, as are the Ruby-atop-VM solutions like JRuby (for Java) and IronRuby (for .NET/Mono etc.), plus Rubinius (aka. 'rbx') is meant to be very good.

I'd say that Ruby is the purer of the languages: it has a nicer syntax, and, in my experience, requires a lot less time looking stuff up in books and docs - it's just natural. Python, on the other hand, is a bit quicker, has proper Unicode support, and is institutionally a safer choice - with a lot more large companies (Google), universities and so on adopting it.

Here's some Ruby code I wrote recently:
Code:
(1..49).to_a.sort_by{ rand }.slice(0..6).sort
It's basically a lottery picker. It picks six distinct integers between one and forty-nine and returns them as a sorted array. The (1..49) is a Range object, and the .to_a is a message being sent to that object, which returns an Array object. The sort_by method is being called on the Array - it's inherited from Enumerable - and for each value in the array, it is passed to the Proc - { rand } - Ruby's implementation of lambda. Each time { rand } is called, it returns a random number which is used as the sort value for the array. It returns a new array sorted. Then the slice method takes the first six items from the list and returns them as a slice of the array. Then they are sorted and returned.

If I wanted to print this lot, I would simply prepend it with "puts " and append ".join(" ")

Object-oriented one-liners. Awesome, no?

I know Python, but hardly ever use it any more. I tend to code small hacky stuff in Ruby, and use it for prototyping. I use Python for stuff where there are libraries only available in Python - rdflib for example, Z39.50 hackery and so on. Stuff that needs a bit more performance tends to get rewritten in the Java language. I've got a large corpus of text that needed processing. I prototyped a solution in Ruby which was taking about five seconds for each iteration, and it had just under 78k iterations - the whole thing would take four and a half days (given five seconds * 78k). Rewrote it differently in Java, and the whole run took eight minutes on a not-particularly-nippy old Linux server. The difference between eight minutes and four days is important: it allows mistakes. If I screw something up, I can change it, recompile and re-run in in a way I can't if I have to wait for it.
 
  • #12
Got an e-mail notification saying signerror asked how I know that the { rand } proc gives a uniformly random permutation? Answer: I know it doesn't. It's not very random at all, and if it were for anything other than picking six lottery numbers, you'd want to use something that was. This post on eigenclass.org describes the problem and the solution.

I find that I've never needed to worry about the absolute randomness of the selection, since I don't build anything which needs it. If I wanted something more random than sort_by.{ rand }, I'd probably use JRuby and Google "java randomness". ;)
 

Related to Which scripting language do I start with?

1. What is a scripting language?

A scripting language is a type of programming language that is used to write scripts or small programs that automate tasks or control the behavior of applications. It is typically easier to learn and use compared to traditional programming languages and is commonly used for web development, system administration, and game development.

2. Which scripting language is the most popular?

The most popular scripting language is JavaScript, which is used for both front-end and back-end web development. Other popular scripting languages include Python, Ruby, and PHP.

3. How do I choose which scripting language to learn?

The best way to choose a scripting language is to consider what you want to use it for. For example, if you want to build dynamic and interactive websites, JavaScript would be a good choice. If you want to focus on data analysis and machine learning, Python would be a better option.

4. Is it necessary to learn multiple scripting languages?

It is not necessary to learn multiple scripting languages, but it can be beneficial. Different languages have different strengths and are used for different purposes, so learning more than one can expand your skillset and make you more versatile as a programmer.

5. How long does it take to learn a scripting language?

The time it takes to learn a scripting language depends on several factors, such as your previous coding experience, the complexity of the language, and how much time you dedicate to learning. With consistent practice and dedication, you can learn the basics of a scripting language in a few weeks, but mastering it may take several months or even years.

Similar threads

  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
7
Views
874
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
12
Replies
397
Views
14K
  • Programming and Computer Science
Replies
11
Views
2K
Replies
3
Views
574
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top