What Programming Language Should You Learn?


Collapse Content

Java vs. C# vs. Swift vs. Python vs. Ruby vs. JavaScript vs. PHP

Beginners often worry what language to learn first, but you can pick any modern popular language and get started. However you may as well pick a language that fits your goals, so see this chart which I recently updated:

Programming-language-chart

Interested in creating websites? Check out my Kickstarter!

For a short discussion of these languages see my updated post The Different Programming Languages. For an overall comparison of each language, its philosophy and environment, see this new table:


Table of Popular Languages


Java C# Swift Python Ruby JavaScript PHP
About name & original purpose Named for Java Coffee, created for interactive TV Named after C++ and the musical note. Microsoft's Java competitor Implies faster coding,
"Objective-C without the C"
Named for Monty Python, created as a scripting language to bridge the gap between the shell and C Named for the gemstone, created as a true object-oriented scripting language Named after Java as a marketing ploy, created (in 10 days) as a scripting language for Netscape browser Creator made it for his  own Personal Home Page and it evolved from there
Appeared 1995 2000 2014 1991 1995 1995 1995
Language Principles
(official or otherwise)
Robust to catch errors  
Secure  
Portable to run anywhere  
High performance  
Multithreading  for concurrency  
Dynamic  
(See Design Goals of the Java)
Strong type checking  
Robust & durable   Programmer productivity  
Source code portability and programmer portability  
Internationalization  
Run on hosted and embedded systems, distributed environments, large to small
Builds on the best of C and Objective-C, without the constraints of C compatibility.

Systems programming language that is as expressive and enjoyable as a scripting language.  
Modern, functional, easy to experiment with, safe and powerful. 
Readability counts.  
Explicit is better than implicit.  
Flat is better than nested.   Sparse is better than dense.   
Special cases aren't special enough to break the rules. Although practicality beats purity.  
Errors should never pass silently. Unless explicitly silenced.  
There should be one - and preferably only one - obvious way to do it.  
If the implementation is hard to explain, it's a bad idea.  
Make programmers happy
Principle of least surprise 
There's more than one way to do it
Concise and succinct
Helps get the job done
We are the masters, computers are the slaves
Scheme-like language using Java-syntax.

HTML needed a 'scripting language', a programming language that was easy to use by amateurs and novices, where the code could be written directly in source form as part of the Web page markup. We aimed to provide a "glue language" for the Web designers and part time programmers who were building Web content from components such as images, plugins, and Java applets.
"I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way."

PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
Used for creating Android apps, large websites Windows apps, large websites (Unity games) iPhone and Mac apps Math scripts, wesbites Ruby on Rails websites Anything that runs in a browser (and beyond) Applications built on older scripts like Wordpress 
Used especially by Large companies
(Banks, eCommerce, Google, etc.)
Large companies
(Microsoft, healthcare, etc.)
iPhone developers Academics, startups, Google Startups
(Airbnb, Github, Scribd, etc.)
All websites Older companies, Facebook.
Pro / Unique Feature Well-optimized Java Virtual Machine for running code. LINQ for easily querying and updating data.  Easy to try out code with Interactive Playgrounds and REPL.  List comprehensions for creating lists based on other lists. Pass around Blocks of code to get stuff done concisely.  Only language that runs in browser.  Quick to set up server and web host. 
Cons / Tradeoffs Strict rules help catch errors but reduce flexibility and brevity. Requires more boilerplate code than others. Primitives.   Similar to Java. Integrates well with Windows,  but not yet as well with other platforms.  May be harder to find answers when coding in a new language. Still has some issues with performance and bugs.  Somewhat slow. Using whitespace looks nice, but may cause occasional issues. Language split between Python 2 and 3. Slower run-time on a computer.  Multiple ways to do things can make reading code a little harder.  Its flexibility sometimes leads to inconsistencies, bugs or surprises. E.g. there's one global namespace for all code. Messy syntax and some inconsistencies and quirks. Makes it easy to create something quickly, but also to follow bad practices and leave security holes. 
Java C# Swift Python Ruby JavaScript PHP
How language is executed Compiled to run on the Java Virtual Machine so you can "Write once, run anywhere". Compiled to run on the Common Language Infrastructure (part of .NET platform) which is primarily used on Windows but will become more cross-platform. Compile to run apps on the Mac and iPhone. Commonly executed on CPython, the official Python implementation written in C.  Commonly executed on MRI, the official Ruby implementation written in C.  Runs within any browser from source code; well-optimized for a scripting language. Commonly executed on the official Zend PHP implementation. Facebook's newer HHVM compiler can execute PHP faster.
Jobs 
(Indeed, AngelList)
14,800
900 (Android: 800)
3,340
150
105
150 
1,650
1,120
1,505
340 (Rails: 1,020)
2,070 for both 2,400
690
Top Web Framework Spring MVC ASP.NET MVC n/a Django Ruby on Rails Node.js for server, many for front-end Laravel, etc.
Hello World program
class Main {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}
public class Main
{
   public static void Main()
   {
      System.Console.WriteLine("Hello world");
   }
}
println("Hello world")
print("Hello world")
puts "Hello world"
console.log("Hello world");
echo "hello world";

About the languages

Many of the popular 'modern' languages actually appeared in 1995 (Java, JavaScript, Ruby, PHP). While some recent languages are gaining traction (i.e. Scala and Go), it's safer for a beginner to pick an established language with lots of learning resources and online answers. (There's one exception though - someone interested in creating iPhone apps should probably go with Swift, since it's considerably more beginner-friendly than the old Objective-C.)

The largest differences between these languages are between the compiled languages (Java and C#) and the interpreted languages. The compiled languages are compiled by the computer to a lower-level of code before they are executed, while the "interpreted languages" were traditionally executed directly from the source code the programmer wrote. Nowadays, this distinction is less clear-cut since languages can be executed in different ways, and it's usually somewhere in-between compiled and interpreted anyways. However, Java and C# still very similar, sharing a similar syntax and approach. Note that JavaScript was named after Java for marketing reasons, but is pretty different except for some syntax similarities.

Python and Ruby are both focused on flexibility and programmer productivity. The main difference between them are their ecosystem and their approach to choice - Python feels there should be "one right way to do it" while Ruby believes "There's more than one way to do it". If you're interested in creating web apps, Ruby is a good choice since Ruby on Rails is written in Ruby. Ruby on Rails is a very popular framework for creating websites and has a large ecosystem around it.

Interested in learning web development with Ruby on Rails? Check out my Kickstarter project!

Real Sample Program

To compare the languages beyond a "Hello World" program, see the samples below. Based on Rosetta Code.
Note: Not all variations below are due to language differences.

Task: The computer will choose a number between given set limits and asks the player for repeated guesses until the player guesses the target number correctly. At each guess, the computer responds with whether the guess was higher than, equal to, or less than the target - or signals that the input was inappropriate.

Java

import java.util.Random;
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        long from = 1;
        long to = 100;
        int randomNumber = random.nextInt(to - from + 1) + from;
        int guessedNumber = 0;

        System.out.printf("The number is between %d and %d.\n", from, to);

        do
        {
            System.out.print("Guess what the number is: ");
            guessedNumber = scan.nextInt();
            if (guessedNumber > randomNumber)
                System.out.println("You're too high!");
            else if (guessedNumber < randomNumber)
                System.out.println("You're too low!");
            else
                System.out.println("You got it!");
        } while (guessedNumber != randomNumber);
    }
}

C#

using System;     
class Program
{
    static void Main(string[] args)
    {
        const int from = 1;
        const int to = 100;     
        int randomNumber = new Random().Next(from, to);
        int guessedNumber;     
        Console.Write("The number is between {0} and {1}. ", from, to);
        while (true)
        {
            Console.Write("Make a guess: ");
            if (int.TryParse(Console.ReadLine(), out guessedNumber))
            {
                if (guessedNumber == randomNumber)
                {
                    Console.WriteLine("You got it!");
                    break;
                }
                else
                {
                    Console.WriteLine("You're too {0}.", (guessedNumber > randomNumber) ? "high" : "low");
                }
            }
            else
            {
                Console.WriteLine("Input was not an integer.");
            }
        }     
        Console.WriteLine();
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}

Swift

import Cocoa
 
var found = false
 
let randomNum = Int(arc4random_uniform(100) + 1)
 
println("Guess a number between 1 and 100\n")
 
while (!found) {
    var fh = NSFileHandle.fileHandleWithStandardInput()
 
    println("Enter a number: ")
    let data = fh.availableData
    let str = NSString(data: data, encoding: NSUTF8StringEncoding)
    if (str?.integerValue == randomNum) {
        found = true
        println("You got it!")
    } else if (str?.integerValue < randomNum) {
        println("You're too low!"")
    } else if (str?.integerValue > randomNum) {
        println("You're too high!")
    }
}

Python

import random
 
inclusive_range = (1, 100)
 
print("Guess the number between %i and %i.\n"
      % inclusive_range)
target = random.randint(*inclusive_range)
answer, i = None, 0
while answer != target:
    i += 1
    txt = input("Your guess(%i): " % i)
    try:
        answer = int(txt)
    except ValueError:
        print("  I don't understand your input of '%s' ?" % txt)
        continue
    if answer < inclusive_range[0] or answer > inclusive_range[1]:
        print("  Out of range!")
        continue
    if answer == target:
        print("  You got it!")
        break
    if answer < target: print(" You're too low.")
    if answer > target: print("  You're  too high.")
 
print("\nThanks for playing.")

Ruby

number = rand(1..100)
 
puts "Guess the number between 1 and 100"
 
loop do
  begin
    user_number = Integer(gets)
    if user_number == number
      puts "You got it!"
      break
    elsif user_number > number  
      puts "You're too high."
    else
      puts "You're too low."
    end
  rescue ArgumentError
    puts "Please enter an integer."
  end
end

JavaScript
non-browser version (Spidermonkey)

function main() {
    guessTheNumber(1, 100);
}

function guessTheNumber(low, high) {
    var num = randOnRange(low, high);

    function checkGuess(n) {
        if (n < low || n > high) {
            print('That number is not between ' + low + ' and ' + high + '!');
            return false;
        }

        if (n == num) {
            print("You got it!");
            return true;
        }

        if (n < num) {
            print("You're too low.");
        } else {
            print("You're too high.");
        }
        return false;
    }

    print('I have picked a number between ' + low + ' and ' + high + '. Try to guess it!');
    while (true) {
        putstr("  Your guess: ");
        var n = parseInt(readline());
        if (checkGuess(n)) break;
    }
}

function randOnRange(low, high) {
    var r = Math.random();
    return Math.floor(r * (high - low + 1)) + low;
}

main();

PHP
(HTML not included below)

<?php     
session_start();

if(isset($_SESSION['number']))
{
   $number = $_SESSION['number'];
}
else
{
   $_SESSION['number'] = rand(1,100);
}

if($_POST["guess"]){
    $guess  = htmlspecialchars($_POST['guess']);

    echo $guess . "<br />";
    if ($guess < $number)
    { 
        echo "You're too low";
    }
    elseif($guess > $number)
    {
        echo "You're too high";
    }
    elseif($guess == $number)
    {
        echo "You got it!";
    }

}
?>

Challenge

Practice different languages by solving a simple problem. Write program that prints the sum of each given pair of numbers. (Print each sum on its own line.)

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Contact Us
Sign in or email us at [email protected]