views:

1678

answers:

21

I've been programming now for 30 years, BASIC, various assemblers, FORTH, Pascal, C and C++ in that order. I haven't learnt a new language in over a decade because from a work perspective C++ does everything I need. However, from a technology perspective, I'd like to bring my skills up to date, particularly in the areas of web development and use of scripting languages that let you do alot without too much programming. The languages I'm considering are Python, Ruby, Java and Haskell. In my position which would you go for and why.

  • One language per answer please, qualified with solid reasons rather than personal preferences.

  • If you can add a small canonical code sample of something the language does much neater than C++ that would be great.

  • Downsides of your chosen language would also be appreciated.

(Edit: Qualify your answers please. I will down vote unqualified one-liners)

+3  A: 

C# is language, which made an incredible development over the last 5 years. Originating as a pure object oriented language now it has lots of "functional" programming elements.

The world wide acceptance of the language is also growing up.

Michael Damatov
A sample showing advantages over C++ would be good. I know it's safer in terms of memory management and does web, but slower and bulkier than C++. What else? Qualify in technical terms rather than industry standards please, as this is more for fun / personal growth than work. Thanks, Shane.
Shane MacLaughlin
A: 

I'd choose Java because of it's similarities with Javascript. I'm not an expert or anything, but the fact that Java has automatic garbage collection would make things much easier than C or C++.

Edit by Cd-MaN: Java and Javascript are very far apart. The only similarity is their name. Aside from this:

  • Java uses static typing, while Javascript uses weak typing
  • Java uses "classic" OOP (class, interfaces, inheritance) while Javascript uses prototype based inheritance
  • In Javascript functions are first-class values, in Java they are not
  • Javascript has closures while Java doesn't (although there are proposals to include it in a future versions)

Conclusion: they are very different. The fact that they are similar, just because their names are similar is a misnomer.

Edit by Vito: Cheers mate, I was told otherwise. Thanks for taking the time to clear that up. :)

Glitch
[Fun mode="on] Java to JavaScript is as "car" to "carpet".
Michael Damatov
Perfecly agree michaeld - this is an unfortunate misunderstanding created by the name which is propagated again and again.
Cd-MaN
I don't get it .. The poster didn't list any experience with Javascript?
troelskn
+15  A: 

I would definitely go for Haskell. The reason is that since you already know C++, you're quite adept at object-oriented programming and have no problem with procedural programming.

Haskell is a functional programming language - a different thought paradigm altogether. It requires that you 'wrap your head' around new ideas and abstractions of doing things. Even if you don't use it for actual projects your mind is better off since you've got a new way of looking at things.

Take a look at this example for the implementation of Quicksort in Haskell. See how concise it is when compared to a C++ implementation. Haskell programs tend to be that way - very short, very declarative as opposed to C++/Python/Ruby/Java which are more imperative. Granted, all of these languages (well, maybe with the exception of Java) have some constructs that come from functional programming, but I would compare it to reading translated literature - when possible, I'd rather read in the original language for the various nuances that simply can't be translated.

A major downside for Haskell - although one that is rapidly disappearing - is the lack of libraries for practical tasks. DB Access, testing, GUI and so on - although some of these libraries do exist, they tend to be in a rather preliminary form. As Haskell gains more and more 'formal' status, I'm guessing, these problems will disappear. You will also have a shortage of viable IDE's for editing Haskell - unless you're familiar with Emacs/Vim for editing.

Hope this helps.

Yuval
Just what I was after, thanks.
Shane MacLaughlin
+1. A "pure" language like Haskell is good for learning a new paradigm, though once you've got the hang of it (monads are the hardest part) you can switch to a multi-paradigm language like Scala or Lisp.
finnw
+25  A: 

Python is a great language for getting into the "scripting" style languages. While you may be initially turned off by the indent-as-block-structure style, rest assured that this will become completely natural if you give it a go.

One of the incredible strengths of Perl/Python/Ruby/etc is the ease with which you can do operations on entire lists without writing a single for loop. For example:

$ python
>>> a = [4, 9, 12, 72, 2]
>>> print sum(a)
99
>>> print sum(a)/len(a)
19
>>> print max(a) - min(a)
70
>>> a2 = [x*x for x in a]    
>>> print a2
[16, 81, 144, 5184, 4]
>>> print [x for x in a if x > 10]
[12, 72]
>>> print sorted(a)
[2, 4, 9, 12, 72]

I first encountered this style when I learned Perl many years ago. I found it was so much more succinct to express what I wanted to do for so many cases where I would have written a loop in C++.

Other distinct advantages over C++ are fully garbage collected memory management, a comprehensive standard library, introspection, and probably more I'm not thinking of.

Greg Hewgill
As I mentioned in my post above, these are constructs that originated in functional programming where a list is a first-class citizen.
Yuval
Yuval: You're right of course, and I would probably recommend learning a functional language too. However, today I can give better examples in Python. :)
Greg Hewgill
Greg: And my best examples would be in C# and/or Perl... I did have the chance to write a small utility in Haskell though, and was VERY impressed with the productivity gain that I found.
Yuval
@Greg: `print` statements are needless at the interpreter prompt in this case. `>>> print a2` -> `>>> a2`. Bonus: modified examples will work in Python 3.0
J.F. Sebastian
J.F.: true, but I wanted to show an example that could be run both in the interpreter, and as a standalone program with no changes. There is that Python 3.0 difficulty though, but that's easy to handle once you have a grasp on Python!
Greg Hewgill
Python is useful for more than web development - the more I learn about it the more places I notice it in the background.
Colonel Sponsz
Too bad you didn't mention the first-class object-orientation.
S.Lott
+18  A: 

Ruby. Its syntax will be a breath of fresh air compared to the languages you know. Ruby has a substantial user base so you can get plenty of help online and in books and its "standard library" is full featured and has 3rd party libraries closely supported as ruby "gems".

What can it do? Crawl an entire site and list all urls. First, install a module:

sudo gem install spidr

then run a program

require 'rubygems'
require 'spidr'

Spidr.site('http://stackoverflow.com/') do |spider|
  spider.every_url { |url| puts url }
end
trenton
You might want to change your "it's" into "its" (its syntax, its standard library etc)
ΤΖΩΤΖΙΟΥ
Thanks. I'm usually the one correct other people!
trenton
Uhm, sorry, but it seems to me that your comment must be corrected... :)
Myrrdyn
Thanks. I'm usually the one correctING other people!
trenton
fortune cookie say: the problems we have with other people are usually our own.
ethyreal
+2  A: 

What I'm about to suggest is not on your list, but I think that if you're aiming at Web Development you should really consider PHP.

PHP is, at least for now, the most widespread language in the web environment.

It's a loose typed language with a good deal of capabilities.

With the new version 5 you have a very good OO implementation, with constructors, destructors, interfaces and exceptions.

The upcoming version 6 is going to be fully Unicode compliant and the Zend Engine, the power behind the language, is getting some more features.

If you are proficient in C/C++ you will not find the syntax that alien, in fact you'll even find it familiar. Well apart having to prepend a dollar sign to every variable :)

Here's an example of some code:

<?php
    class Mammal {
        private $feeding = 'Milk'

        public function getFeeding() {
            return $feeding;
        }
    }

    class Dog extends Mammal {
        private $say = 'Woof';
        private $name;

        function __construct($name) {
            $this->name = $name;
        }

        public function say() {
            return $say;
        }

        public function getName() {
            return $this->name;
        }
    }

    $MyDog = new Dog("Fido");
    echo $Mydog->getName() . " says: " . $MyDog->say() . 
         " when his belly is full of " . $MyDog->getFeeding();
?>

That piece of code only highlights a few things of what you can do.

PHP has loads of features built in the Standard PHP Library(SPL) to deal with Iterators, XML and much more.

Not to mention all of it's pluggable libraries that will give you from Database access to PDF editing and so much more.

Gustavo Carreno
You're quite right, PHP should have been on the list. My bad.
Shane MacLaughlin
Heheheh, no problemo mate!!
Gustavo Carreno
You mean it has the minimum to at include an object system in the list of features?
Mikael Jansson
+3  A: 

I'd go with Haskell or Prolog.

You need to learn a new paradigm. Any Computer Scientist would tell you the importance of knowing other paradigms of programming. Haskell would probably open your eyes on a lot of things, even if you find you never use it. But the same would be true if you tried Erlang, Ocaml or Common Lisp. So from your list, I'd pick Haskell.

You should start by focusing on the language rather than the libraries. Learn the semantics of the language. When you have become somewhat fluent, you can begin pulling libraries off the shelf.

You must be aware, though, that Haskell is probably harder to learn for you than Common Lisp or Ocaml, say. The reason is that while CL or Ocaml have an imperative subset you can access when needed; Contrary, Haskell encodes imperative side-effecting constructs in the concept of a big-warm-fuzzy-thing (monad). The monad concept will take a bit of time getting used to.

jlouis
+1  A: 

I followed a similar trajectory over a similar time frame, although I also had a bunch of others, notably XSL-T and the ECMA scripting languages like JavaScript having done a lot of early web development. 5 years ago I added Java, two years ago I added ActionScript and MXML (Flex) and this year I added Python (with a side branch into perl and php).

Of these I think that python is the one I would recommend the most. The language is a pretty horrible step from where you are if you take responsibility for types and code formatting, but the elegance of the code makes it worth it and like anything, you end up getting used to it and actually liking it. The IDE I use (pydev in Eclipse) leaves a bit to be desired, but is plenty good enough to get started.

However the real kicker is the wide variety of high quality open source modules that are available and very much alive (numpy, scipy). There is almost no topic for which you will not find pre-existing code.

If you want a real paradigm shift then there is an intriguing variant of python called stackless which opens a completely different way of thinking about your code architecture. That's next for me.

Simon
A: 

As an alternative to Haskell, I'd recommend O'Caml, which is a functional programming language in the ML tradition (i.e. not not purely functional with lazy evaluation like Haskell) but with interesting additions. It has become rather popular and has a very efficient compiler implementation.

dkagedal
+4  A: 

I'm going to suggest Java, partly to give the Java fans something to vote for, but more importantly because I believe there are good reasons to choose it.

  1. You will get immediate access to a vast range of new domain areas to work in. Will you learn more (and have more fun) by playing with the syntax of a new language, or by working with libraries and fields that you have never tried before? Java is probably the richest framework (with C# as a competitor) in terms of libraries for Web, UI, XML handling, data modelling, messaging, reading and manipulating different kinds of data and many others. It is also one of the default choices for most third parties creating integration APIs - whether it's your local online payment service or a map-drawing API.
  2. You will learn it in no time. If you're a good C++ programmer you will be immediately familiar with most of the constructs - the learning time will mainly involve remembering not to use certain C++ keywords. I admit this means you won't challenge yourself as much in learning the language itself, but you'll move very quickly onto doing substantial, interesting things which will challenge you in other areas (see point 1).
  3. When I took up Java (12 or 13 years ago now, which I can hardly believe) it was the most beautiful thing in the world to me. I can hear the Ruby fans sniggering now. But Java made programming so simple and so solid, that I could focus on logic and not fixes 90% of the time. No more of the ambiguity of PHP - is my $name variable local, global, or an HTTP "name" parameter? Is $price being treated as a string because it was an HTTP parameter, or has it been converted to a number because I added it to something? No more of the feeling of 'ragged edges' in C - have I gone past the end of my malloc without noticing? Do I dereference or double-dereference that pointer? Java was like building a machine out of pre-made, well-engineered components instead of starting with raw steel and forging it myself. It just felt right.

There are of course a number of specific features that are useful in Java - it is cross-platform, it lets you dynamically plug in new classes at runtime (under some circumstances), it handles memory very well without your intervention, etc. But these are relatively minor in the context of your question.

Leigh Caldwell
A: 

Objective-C, because the iPhone app store appears to be currently making a metric truckload of money per day ;-)

Graham Lee
A: 

I also think changing to a new paradigm is a good thing

I would also however recommend either C# or Java for this reason

These languages enforce you to use OO principles in a way that C++ doesn't. The code loses much of the lower level stuff that can appear in C++ code and in doing this focuses you on the design of your classes. Working round the restrictions in these languages can really show you the benefit and more importantly the limitations of a purely object oriented approach. So the benefit is that you could learn one of these languages fairly quickly and it could improve the way you write C++ in a fairly direct way.

Of course it is possible that you already know this stuff with C++. Personally I made such a transition and learned a lot from Java's restrictive approach, though it is not even close to being my favourite language

Willbill
+12  A: 
Mikael Jansson
+1  A: 

PHP Why?

  • There's many open source application built up-on it
  • Most of Servers supports PHP for cheap prices
  • It's complete and had many frame works to create your application

    • Easy to learn
    • Many free lessons and tools
Omar Abid
+3  A: 

Nobody has mentioned Javascript yet. It should be real easy to pick up for a C++ developer and while it is arguably not a fantastic language it is quietly becoming very popular as it is THE programming language for client-side web programming.

This example code checks if the user has entered a name into the UserName field on a form before allowing the form to be submitted.

function validateUserName()
{
    var username = document.MyForm.UserName;

    if(username.value == "")
    {
        alert("Please enter a user name");
        username.focus();
        return false;
    }

    return true;
}
Adam Pierce
+2  A: 

CFML - great for RAD web stuff.

There are three main implementations (Adobe ColdFusion, Railo and OpenBlueDragon), each with the same core features.

The key advantage is lots of useful packages features which are nice and easy to use, plus a dynamic language that lets you write more concise and flexible code.

An SQL query with injection protection and bind parameters:

<cfquery name="EmailData" datasource="MyDatabase">
 SELECT name
      , email
      , something
 FROM user_info
 WHERE group = <cfqueryparam value="#Form.GroupId#" cfsqltype="cf_sql_integer"/>
</cfquery>

Then you can loop through all the results of that query and email it in one go:

<cfmail
 query   = "EmailData"
 to      = "#email#"
 from    = "[email protected]"
 subject = "Hello #Name#"
 >
 Hello #Name#, this is an email about #Something#.
</cfmail>

There are lots of similar tags and functions that are just a whole lot easier than every other language.

You can easily create PDFs with the cfdocument tag, or do image manipulation with the cfimage tag, convert videos between formats with cfvideo, and more.

There are also plenty of frameworks and projects for the various "best practices" - MVC, ORM, IoC, and so on (but you're not forced to use these).


On top of all that, ColdFusion, Railo and OpenBD are all built on Java, and can easily use any Java classes you might need.

For example, want to create a StringBuffer? Easy:

<cfset MyStringBuffer = createObject("java","java.lang.StringBuffer").init() />

(Note: There is a BlueDragon.NET available for people who do .NET stuff.)

The key benefit of CFML is that it makes everyday tasks easy to do, without preventing you from doing more powerful and flexible things.

Peter Boughton
+1  A: 

Mmm, there are so many languages today, lot of them in real use.
I would advise to choose a language quite different from those you know, it will broaden your perspective, and not confuse you with concepts subtly different.

Since I have to choose only one, I will advice Lua, for several reasons.

  • It has a nice, simple syntax, yet it is powerful. Fast yet lightweight. And very portable.
  • It has very few libraries out of the box, but an increasing quantity of 3rd party libraries: it is designed to be easy to embed in an application and to be extended.
  • It can be seen as a procedural language with some functional sides (functions as first-class values, etc.), but has a very nice meta-mechanism to extend and make it flexible: you can build a full OO system on it.
  • It can be useful for your work, should you need a scripting language for your applications! Or as a rapid prototyping language (I used it as a thin wrapper around a client-provided DLL to test its capabilities). Etc.
  • Free with a very permissive license.

And so on. I won't give you an example of Lua code, you will find plenty in the lua-users wiki.

OK, just a very short code, which I wrote recently to test the shuffle algorithm:

-- http://en.wikipedia.org/wiki/Knuth_shuffle - Knuth-Fisher-Yates shuffle algorithm
-- From http://www.codinghorror.com/blog/archives/001015.html - Coding Horror: The Danger of Naïveté
cards = {}
for i = 1, 20 do 
    cards[i] = i 
end

for n= #cards, 1, -1 do
    k = math.random(i)
    cards[n], cards[k] = cards[k], cards[n]
end

for i in ipairs(cards) do 
    print(cards[i]) 
end
PhiLho
A: 

Firstly, thanks to everyone who responded here. Many great answers that if anything showed that my question was probably way too broad. As such, many of the answers are as correct as each other, so I won't put an accept against any given one.

The language I'm going to try out is Haskell, primarily because I think the mental effort of the paradigm shift is probably going to be of more value than the specific functionality offered by any given language. I've started reading through Haskell for C programmers tutorial and plan to use the HUGS implementation as the learning tool.

If all goes well, and my brain hasn't melted, I'll probably repeat this exercise in a years time with a narrower list of criteria. Thanks again for all the input.

Shane MacLaughlin
You're quite welcome.
Gustavo Carreno
Smacl - glad to have helped... If you're so inclined (and are using Windows), I learned using the book 'The Haskell School Of Expression': http://www.amazon.com/Haskell-School-Expression-Functional-Programming/dp/0521644089. It did take a while to grok, but the sights you see when you get there...
Yuval
Thanks for the link Yuval. Being a C and C++ type, I'm enjoying the pace of the current tutorial and will move onto weightier tomes once I have digested the basics.
Shane MacLaughlin
+6  A: 

I'd check out the new D programming language. D is arguably the most powerful of systems programming languages, with excellent support for low level programming like pointers and inline assembler, coupled with powerful high level features like closures and template metaprogramming. See http://www.digitalmars.com/d/

Walter Bright
I do believe you're biased, but I happen to agree with you.
Brad Gilbert
You could add in small snippets of code.
Brad Gilbert
I think he's trying to be enthusiastic and accurate without making it look like hes advertising.
Rayne
I also think you're biased, but I like D and am eagerly awaiting D2.
Software Monkey
+1  A: 

There is only one way we are heading with all these multi processors and the requirement for true full thread safety - functional programming and for that reason I am going for F#.

This might not be the actual language in a few years but for it's functional way of programming it would be good grounding and insight.

That's the route I'm going!

c00ke
+1  A: 

There's some truth to the cliche "the platform matters more than the language." My advice is to think about what kinds of libraries you'll need. You'll find that some languages have more available libraries than others. In my opinion, this is biggest advantage of non-functional languages. Languages like Haskell are probably a little bit better in language terms. When you consider the huge amounts of libraries available for Python and Java, they start looking more and more attractive.

But if a functional language has what you need, I say go for it.

Jason Baker
Thanks for the response. My question in a sense was flawed insofar it is too broad. You're right of course that a rich library set is the solution to get real things done and hence learn technologies. I went for Haskell more for the personal academic challenge.
Shane MacLaughlin