Rust is a horrible choice now, because it hasn't stabilized. When it has stabilized, it may be a suitable choice (at one point, it looked like it would be too large of a language to a be a great intro language, but since then its been getting smaller, so I'm less convinced that it will remain unsuitable for that role.)
Python's a pretty good intro language; as is Scheme, and Haskell might be, though I haven't seen any good intro-to-programming material built around it, and while I think a good intro should prefer a largely-functional style (as the best Python and Scheme-based courses I've seen have), I'm not convinced that a pure FP language is ideal for an intro to the field (though it certainly a good thing to learn in the course of an education in the field.)
The students move on to Java, C++, Perl, Prolog and others after that; not sure about Python.
I think a strict language in the ML family would even be nicer, because students wouldn't have to reason about laziness.
Also, a lot of colleges (at least the best ones) offer functional programming in a second semester intro course (Berkeley does Scheme I believe). My own institution uses SML.
Python 2.7.1 (r271:86832, Apr 22 2011, 16:34:07)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(5)
<type 'int'>
>>> type('hello world')
<type 'str'>
>>> type({'key': 'value'})
<type 'dict'>
>>> 5 + 'hello world'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
It just has dynamic typing.I could show this to my 80 year old grandmother and have her understand what it does with minimal help on my part.
word_list = ["hat", "dog", "cat"]
for word in word_list:
print(word)
The same example in Java isn't extremely hard to understand, but it definitely is a decent jump in complexity from the almost plain English syntax of Python. String[] word_list = {"hat", "dog", "cat"}
for(int i=0; i < word_list.length; i++){
System.out.println(word_list[i]);
}
EDIT: Forgot about Java's foreach operator, but even so with java you then have to explain what String[] means and the keyword "in" makes for an easier read than (String string: strings) and System.out.println vs print String[] word_list = {"hat", "dog", "cat"}
for(String word: wordlist){
System.out.println(word);
} String[] word_list = {"hat", "dog", "cat"};
for(String a: word_list)
{
System.out.println(a);
}
extra brackets but pretty identicalprint(word) means it's even easier for grandma to understand!
mapM_ putStrLn ["hat", "dog", "cat"]
I'd say the above is pretty simple if explained after: putStrLn "hello world"
You don't really have to go into Monads for this to be understood/used. You can just leave it at "you use functions ending with an M if they do something like print out to the screen or get stuff from a web page".The second piece is interesting: Is something of the sort "<mapfn> <printfn> <list>" easier to explain to someone who's new to programming than "<foreach> <print>"? I've always thought the latter was easier to understand, but I'm curious which one someone who has no previous programming experience would grasp more immediately.
The reason being that "<mapfn> <somefn> <list>" is more declarative, whereas the foreach loop is ambiguous. Something we often take for granted is how hard it was at first to come up with what exactly we need to do or mutate inside that loop to build the right result.
If nothing else, there is interesting discussion to be had ;)
repeat print ["foo"; "bar"; "etc"]
Types dont make things more complicated. Most languages have types and I prefer dealing with them explicitely rather than letting an interpreter do random coercion like Javascript.
Types lead to cleaner programming,instead of shoving random stuffs into an untyped list,a dev has to think about data structures.
Furthermore,as a non native english speaker,I dont find python more readable than staticaly typed languages like C# or Java.Especially when a codebase grows larger. I wish python was statically typed.
You're more than welcome to not think about what types you put into a structure/list. You'll quickly learn how to use that list/structure without hand-holding. For 90% of the problems out there, you don't need anything other than the basic data structures, and they're pretty straightforward to use without having to think about types.
Note. Please don't confuse Javascript's weak-typing with Python's typing, as Python is strongly-typed.
Once you've learned to think about types -- as most introductory courses, even those taught in dynamically typed languages, will teach you -- you can do that just fine in a language that doesn't put a gun to your head and force you to.
(And you can do so in ways that most statically-typed languages have too limited a type system to let you do, too.)
asList("hat", "dog", "cat").forEach(System.out::println)Transitioning first classes from C to go would make great sense, but it looks like a lot of schools already replaced C with Java and C++ as first languages.
Personally, I do think there is merit in teaching a primarily imperative language first, if only to appreciate other paradigms later and get an inkling of what is really going on beneath your code.
I won't say anything about Python.
> I won't say anything about Python.
I will try to learn from your wisdom.
SML worked well because it's more or less dead. All the documentation is basically on a single unsexy website. There aren't a bunch of blogs cluttering up Google results or even much on StackOverflow. Racket also has a single Canonical source and good clear documentation and not much noise.
I can't say the same about the Ruby ecosystem, where I saw this crazy construct in lieu of a call to super posted in a forum question. The TA asked how the person arrived at it. I knew the answer because I had landed at the same StackOverflow page from Google earlier in the week. Which is not to knock Ruby. I understand why people describe it as beautiful.
Really? I thought good old imperative programming was the best starting point. Concepts like assignment, branching, looping. IMHO goto is actually useful at that point and structured programming is an abstraction that takes a little while to wrap your head around. Perhaps it's due to the way I learned that I think some things are more basic (no pun intended). Either way I don't think high level abstract concepts like functional programming are even relevant in the real world of software development - abstract stuff is CS, basic stuff is for everyone else who has to take a programming course.
x = 1
x = 2
that's immediately very confusing for a beginner - are we saying that 1=2?If we stick to immutable values and recursion, and functions that are, well, functions, we get something that corresponds quite closely to first-year mathematics, which makes it easy to learn at the same time.
Using a modern imperative language doesn't prevent you from adding complexity a bit at a time, and -- especially initially -- getting the advantages of teaching things in a functional style.
[1] but not object fields, as objects are taught as containers of mutable state, usually late in the course.
Exactly! Intro courses are usually - with good reason - taught in functional style. Which suggests that a language where that style is more natural and appropriate might be a better fit for those courses than Python.
(Though OTOH I wouldn't advocate a language where IO is anything more complex than a function call)
This is nothing but FUD and you should be ashamed of yourself.
As much as I like static typing, I agree that showing people run-time errors seems to do a better job of teaching than letting them know ahead of time via the compiler that their code will likely blow up.
Functional still isn't that popular, in spite of a few vocal supporters. Even MIT went from scheme to Python for their sicp training.
Other Portuguese top level universities offered similar choices.
European computer science has traditionally been more theoretical than American computer science, but even in Europe you'll find that a lot of 101 courses teach in Python.
Rust would probably be too strict and annoying as a first language. Maybe the same is the case for Haskell, but maybe it isn't such a big deal for those that haven't been "spoiled" by imperative languages and thinking already.