by seanmcdirmid · 12y ago · 0 comments
Or traumatize them forever away from the field of programming.
> Would they think Python was stupid or would they be grateful that all of a sudden they could use a for loop?
I would love to know the answer to this, regardless of my own biases. But Haskell really does require discipline to use, and the kids would probably appreciate the more lax nature of Python.
So, what made learning Haskell a good experience I think was mainly the strong type system. You could basically even early on use functions you barely knew what its name meant solely based on its type signature. It also made the progress of writing a program very nice, you write it and then it fails, you go back and try fix it, and when it compiles it usually worked.
There are some things to keep in mind though. Wild recursion is really the GOTO of functional languages, it's important to teach how to use the generalized folds and traversals early on. Secondly it is important to have simple analogies to concepts such as functors, monoids and monads etc. If you make sure to not care about these strange names then you can go pretty far by just trying to make the type signatures stick together, and it's not important for a beginner to grasp these directly either.
Python was quite smooth to learn coming from Haskell, the syntax is similar and it simply felt like programming in Haskell's do-blocks. It was very easy to get quickly going, I managed to write a little script talking to a JSON API almost directly after reading the official tutorial. I also digged a little bit into the realm of OOP, I wrote a simple game using Kivy. It felt quite nice actually, I could get some code re-use, although it was harder to get that (as newbie) than in Haskell.
EDIT: Something like typed Racket might been even better when I think about it, since Racket got a lot of resources for complete beginners. Then you get the benefit of easy to use syntax too, although syntax is probably not the biggest problem when starting out. For the record I usually recommend Python or Racket when people ask me where to start, because in the end I don't think it matter much what language you go with first, just make sure not to limit the paradigm of languages you learn afterwards.
In short, Scheme (Racket) is regarded as a superior beginner's language because of its simplicity, together with the ability to explore various paradigms (including OO).
Beginners in Scheme subsequently did better with Java than those who started solely with Java.
I think there's a deep lesson in that...
But Haskell really is functional programming, there is no way to accidentally create an easy to use OO-style library. And then there are the monads....
I remember the day I sat down, worked through some examples, and grokked monads. I said, "That's it?"
That's not to say that they can't be hard to learn. I just don't think that they're _inherently_ hard to learn, and I think that they're sufficiently different enough from 'more traditional' CS concepts that said other concepts can hamper your ability to learn them. I suggest http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/ba... if you're still trying to figure them out.
Fun story: one time I had to suddenly explain monads to an English professor, because she overheard me say the word and said, "wait, Leibnitz?"
That was a good 20 years ago, but I just ran into a current student who told me that's still the case, and they still hate it as much as we did.
On topic:
I sometimes wonder if the wins from FP languages are lost on the people not already scarred by the pitfalls of imperative programming. I wonder the same about someone starting with Python instead of something more wordy and cumbersome. I don't think you really can appreciate the ease of use if you haven't already written tons of boilerplate or type information because the compiler is stupid.
At the same time you don't know the price of the ease you're getting, so there is a warped perspective on both the ease of programming and the performance of languages.
Haskell, I think, exists in a sort of middle ground where it's actually really fast but extremely expressive. Maybe someone uninitiated in programming won't have as many problems formulating functional solutions to problems in Haskell too.
The reality was that the tools were slower and buggier than others, the programs different (and slower) but no simpler and the bugs different but stilly just as buggy.
When presented so mindlessly and categorically, any claims of superiority instantly lose credibility. When reality is taken into account, even more so.
No, there are plenty of people who will debate this, programming languages academics even. There is a vocal FP crowd that fawns over elegance, but there are plenty of other people who are more pragmatic about it.
> I sometimes wonder if the wins from FP languages are lost on the people not already scarred by the pitfalls of imperative programming.
Pity the poor programmers who get things done, write huge beautiful systems, all without worshiping lambdas? And by taking shortcuts ala side effects as a way to making things easier.
> Maybe someone uninitiated in programming won't have as many problems formulating functional solutions to problems in Haskell too.
It depends on how much math they have behind them. You take a mathemegician, sure, but a high schooler who is still having trouble with pre-calc?
The functional programming language is Opal, a language developed at the TU Berlin, it has barely any documentation, a compiler that only works on Linux and OS X, that is if it works because it has quite a few bugs, it further comes with a REPL that sometimes produces failures the compiler doesn't and tooling is non-existant.
So as a new CS student you have to learn using Linux and setup a development environment by yourself with barely any documentation to go on. You then continue learning only the very basics of programming such as what functions are, if statements, recursion, big O complexity, a little bit of parsing and though it's called differently: monads. At the end of the semester you then develop a renderer for a regular subset of HTML that includes only <html>, <head>, <body>, <title> and <p style="text-align: {left, right, center, justify};">.
On top of that the language has a couple of weird features: Every function can be used as any kind of operator if the number of arguments fits. This means that the parser has often problems figuring out precedence rules and you end up adding parenthesis around every expression just to be on the safe side.
Number literals also don't exist. There is a pre-defined set of functions which don't take an argument and produce a number such a 1-12 or so, n^10 for a few n, and a couple of 2^n for a few n. All other numbers have to be explicitly converted from strings. In practice this means you do the latter all the time so 1 turns into ("1"!).
Furthermore variables are defined by name and type. You can have two variables called foo in the same scope, if they have a different type and depending on how foo is used (Opal has type inference) one of the variables is chosen.
The prior feature is effectively necessary because Opal also doesn't have polymorphic functions. It has polymorphic "Structures". A Structure is file you can import, within that file you can define a set of variables that are polymorphic, the types of which are defined by however is importing it either explicitly or implicitly through type inference.
This is pretty much like how you might use the pre-processor in C to achieve polymorphism.
Have I mentioned by the way that a Structure is actually just a header like in C? In the Structure you only define the types of the API, the implementation is in a different file.
So a functions like map requires writing two separate files. Luckily it's in the stdlib.
Overall these features are fine, if everything works nicely but if you have an error somewhere, the compiler can emit massive difficult to understand errors, not unlike what a C++ compiler might produce for code that uses templates heavily.
The language and the choice to use that language is heavily critized by pretty much all students, functional programming however is not. In fact pretty much everyone would prefer if Haskell (which is the functional programming language closest to Opal) were used. The only reason it's not, is that the current prof for that class lead the team who developed the language.
So we were spared that particular disaster, which was and is sold using the same "unquestionable superiority" rhetoric. Instead we dealt with Hope. As in "I Hope it will finish in the next 15 minutes". "It" being a 10-30 line program. Usually it didn't, instead producing a largish coredump.
Our Sun 3-50 diskless workstations didn't help, but hey, Turbo Pascal could compile + execute a hundred lines of code in a second or two on the Z80 card in my Apple II+, a computer with several orders of magnitude less CPU/memory than those Suns.
Later we also used another language, I think it was Miranda. That introduced us to the joys of type inference. Magical when it works, completely inscrutable when it doesn't, especially since you don't get feedback on the cases that do work.
The big problem here is not that the tools were buggy and the languages less than fully thought out, that is fine, if presented that way. The problem is the complete disconnect between rhetoric ("perfection", "everything else is steaming pile of manure") and reality (sort of the opposite).
In the meantime, tools have certainly improved a lot (ghc/ghci on my MacBook Pro are quite tolerable), but the disconnect between rhetoric and reality is still there, because everything else has also improved.
Consider Opal itself: an FP language (so one of the domains FP is actually good at) in active development for more than a quarter of a century by teams using magical, all-conquering, flawless-marvels-of-correctness-producing FP unicorn-technology by teams of programmers that are experts in said technology. And it is, quite frankly, a steaming pile of manure.
EDIT: Hope: http://en.wikipedia.org/wiki/Hope_(programming_language)
Object thinking is easier to wrap one's head around than mathematical formal thinking, but that's just because the former uses the brain's innate linguistic hardware (we learn to talk without much effort) while the latter requires training and practice.
Here's the latest course description: http://media.collegeboard.com/digitalServices/pdf/ap/ap-comp...
Just had a look at the curriculum of the Portuguese university I graduated from, a couple of decades ago and they still teach OOP, FP, LP across multiple languages.
The same can be said about using Python et al as the first programming language. How many people quit an introductory course to programming because they didn't like (say) the style of programming in Python, but could get an interest in it if the language being taught was some FP one (or maybe a logic programming language, etc.)? It's kind of hard to tell, because students who get turned away from an introductory course on programming probably aren't going to look up (or even know about) "programming paradigms" and see whether there are alternatives.
Granted, how long would these people survive in the job market if they were able to be "traumatized" by some imperative language? There are certainly more imperative language jobs (or, they tend more to imperative style than FP style) in the job market, it seems. But even if they wouldn't like working as a programmer, they can still use it as a hobby if they like.