What's the best language to learn programming with?

As usual, no poll because there’s too many programming languages to make one worthwhile. Obviously one of the best answers is usually “whatever is popular because it’ll make getting a job easier”, but for a university program, for instance that may not be true since a lot of schools will introduce you with one language, and then you’ll learn more languages as you advance in the program. I’m asking about the best introductory language.

I’m not sure I have a great answer. On one hand, I love C as a learning language – not because “it makes you do things the hard way” or whatever, but because it doesn’t hide things from you. When you use == you’re comparing two numbers no matter what; there’s no weird overloaded stuff where you can compare the string “123” to the number 123 and have it be true (I’m looking at you, PHP). It can be convenient, but it can also hinder learning because I think it’s important to realize at some level that everything you’re working with is arbitrary and just numbers under the hood – that prevents confusion in a lot of cases about why things do/don’t work (because no matter how good the language design is, you’re inevitably going to hit a problem that stems from two numbers not matching eventually).

On the other hand, I’d be remiss to not mention that C also has some weirdness – “bool” is just a handy alias for an integer (it’s literally just a typedef). If is especially wonky, because things like if (a = 4) can and will come back to bite you, and while you can explain it away with “everything is just numbers and if just does the test <value> != 0”, I can’t deny that it’s unintuitive. It also has the problem that “hello world” is too big of a program.



#include <stdio.h>

int main( void ) {
  printf("Hello, world!
");
  return 0;
}

I’ve had a lot more trouble than you might expect teaching the “simplest program”. At some point you have to introduce the technical term “magic” before you have to start explaining what a preprocessor is, what “void” means*, and why main has to return a value (which also would entail explaining functions on the first day) to a complete beginner. Compare this to Python’s simple



print "Hello, world!"

Straightforward, simple, easy to understand. It’s great, Python is nice to work with. I just feel like people who start with non-systems languages get themselves into holes when they inevitably run into what could be called a “language implementation detail”.

Perhaps the best approach would be to start off with Python because of how minimal the programs look, and then use something like C as an “intermediate” language that aims to ultimately explain why some of these weird bugs happen under the hood.

Opinions?

  • I (and most CS education people I know) actually tend to just omit the “void” in lessons because the compiler won’t complain without ANSI warnings explicitly requested; just to cut down on questions.

Pascal is intended for this purpose- a language to learn programming.

Once Pascal is understood, transitioning to C is much easier, and that leads to C++/java/the rest of the family.

There is no best. Simple interactive languages are a good start for many people, but there is no best among them even if you agree with that approach.

I agree, Pascal is the way to go for learning procedural languages.

First off, it’s strongly typed, which is a really good thing for a learning language- the learner can’t get lazy or confused by implicit conversions.

The criticisms are valid- the fixed-length string and array sizes make some things difficult, but IMO, Pascal’s really only useful for getting through the first semester of a Computer Science degree, and then maybe for data structures class if C isn’t particularly comfortable yet.

I agree with this. Languages are ephemeral, concepts remain. Programmers can learn any new language as long as they have knowledge of how to write code.

Whatever your first step - and Pascal is a very good general choice - I think that C has to be your second or among your other base proficiencies. It shaped/shapes SO much of modern programming and is still used in many niche applications. I think it’s as impossible to become a proficient modern programmer without a degree of fluency in C as it is to become a proficient modern linguist without a fluency in Latin.

Completely agree. C is absolutely a requirement for any serious programmer, eventually.
It’s the base for much of modern programming. And it’s the intermediate step to assembly language.

Modern BASICs are Pascally enough to be a potential first language.
But really, Pascal is the tool for the job. Its limits are a feature, not a bug.

While the concepts are the most important, I think the language used to present those concepts is also very important when dealing with a beginner. Languages that hide the underlying concepts create holes in peoples understanding, but languages (and libraries) with too much boilerplate distract from the concepts. I don’t think you can just present the concepts – I don’t think teaching lambda calculus is a substitute for teaching Haskell, having that immediate feedback of executing a program is more educational (in my opinion) that just having a bunch of scribbles on a sheet of paper.

Obviously different people learn differently, and no one language works best for everyone, but I don’t think that it hurts to discuss generalities and at a purely conceptual level the amount of knowledge required to operate a language (and thus the amount of information that needs to be presented while teaching it).

Every language leaves holes. People will tend to think some language is the best, perhaps their first, maybe something they learn later on, and then tend not to see the holes created from using that language. If you want to expand your understanding you’ll have to work in more than one language. Not just an introduction either, you’ll need fluency and experience tackling tough problems to appreciate all the concepts and the way different approaches can be used.

IMO the simplest language is the best way to get started, but that’s just a start.

I learned C++ in college and then became a C# developer. C++ is more low-level and gives you an appreciation for the tough stuff that C# (and also Java) hides from you.

I think anything not used in large projects today is a mistake. Java, C++ or C# would be fine, but I think Python or Ruby would be the best, because you could easily pick an open source project and pick it apart to illustrate almost everything you need to learn from beginner to advanced. And I think that sort of holistic approach where you learn from real programs in use rather than learning things in a perfect set order is better than the way most CS programs approach programming teaching today.

Java and C# are okay for that, but C++ is a terrible, terrible language if you want to “learn by reading open source projects”. I can program in C++ just fine, I’m fairly proficient at it, but hell if I can read the GLM implementation. It’s all complex template expansion. C++ has about a bajillion ways to write any given thing, but 90% of the time there’s a way that’s better than however you’re writing it. It’s almost impossible to be proficient at anything more than a subset of C++, and even that is after a few years of experience. C++ is one of the languages I dread to have to port to another language the most because you almost always encounter some exciting new feature that you have to decode.

Python sort of has the same problem sometimes, (you can almost treat Python as a functional language if you want to, for instance), but overall it’s much easier to figure out.

Of course, I’m personally biased towards minimalist languages.

C (well, who does C any more, C++) is a very comprehensive environment but for a beginner it has way too many little details you have to keep track of that may obscure the big picture.

C# is a thing of beauty both for learning and for rapid development. I have been programming in other languages and only started doing C# seriously about a year ago on a big project I am in the middle of right now - and I find that C# is one of the most well thought-out language implementations I have ever seen. It hides things that usually need to be hidden and exposes everything else.

That’s not to say that C# is perfect. But for a beginner to learn every concept of modern programming, it is very good.

FWIW, I was a fairly competent C and assembler programmer who stumbled badly when I poked into C++ (as did the entire team of professional programmers I worked with - I wasn’t/ain’t a pro)… but took to C# very easily. While I’d still suggest at least basic proficiency with plain-vanilla C, maybe my viewpoint is outdated and C# is the place for new, serious programmers to start.

Hey, I resemble that remark! But seriously, plain old C isn’t going anywhere. And it’s essential for learning. I generally divide what you need to know to be a competent programmer into a few categories:

  • Imperative programming: everything from your basic assembler up to very-high-level OO languages. The specific architecture of asm isn’t important (you can use a MIX simulator if you want.) But learning how to manipulate bits and bytes and how these crazy machines actually work under the hood is vitally important, even if you never do systems-level programming.

  • Declarative programming: things including SQL and Prolog and other languages where you have to say what you want and let the computer think for you. (It’s not always as easy as it sounds.)

  • Functional programming: my favorites these days are Scala and Erlang, but anything which implements lexical closures will work. (Yay for Perl!) Every year somebody rewrites Structure and Interpretation of Computer Programs for their latest favorite functional language so it doesn’t matter which one you pick.

  • OO Programming, which is a subset of imperative, but a big enough topic that entire libraries have been written about it. Java and C++ are horrible implementations of the idea. C#, Objective C, Scala, Python and Perl (with modern tools) are all much better for understanding what OO can do.

C#.

The amount of accessible, comprehensive resources for that language is second to none. It’s also a skill that can directly translate to money and work (unlike say pascal).

You want to create a video game? c# can get you to the point where all you need to do is create art assets MUCH quicker than anything else out there (short of using a prebuilt engine - and even then, most engines support C# or a c#-like scripting language).

Same goes for web applications, internet services, desktop and mobile applications… There is very little that Visual studio and C# (and possibly some third party libraries/wrappers) can’t do.

C# is somewhat hampered by being somewhat gimped on OS X and Linux, however. Mono gets around it somewhat, but when I looked into it I recall it being somewhat clear that even with Mono it’s extremely difficult to make multiplatform applications with it, and nigh impossible if you’re making things like games (or anything with graphics). That was a while ago, however, things may have changed.

That may be, but it doesn’t necessarily make it a good language to learn the art of programming on, and that’s what the OP is looking for, not “what’s the best language to learn?”

With the caveat that Pascal by itself doesn’t get used much any more, it is a good language to learn. When I was in grad school I taught fairly large classes all of Pascal in two lectures. All these people had used Fortran before (C was just starting) so they knew how to program, a bit, but Pascal is so limited and clear that it is really easy to teach logically in very little time. I got to help with and grade the code of these classes, so I can testify that most people actually learned how to program in Pascal fairly decently.

But I can see an argument for learning an OO language to learn it right the first time - but I’m not sure if someone who doesn’t know how to program will appreciate the benefits of the OO paradigm.

^^^ imho, Object Orientation is a whole 'other thing.
Learning Pascal and then C is like learning to read and write. Using those basic skills, you can then learn to write poetry.
OOP is about how you describe things, not the language you use to do so.