Originally posted by: lousydood
Originally posted by: degibson
Originally posted by: lousydood
Originally posted by: degibson
In a way, its too bad you're forced to learn it first, because imperative programming will seem quite alien to you when its dumped on you in subsequent courses.
That's the point of teaching it first. Get the good habits in first, make the bad habits feel "wrong."
I don't know what habits you refer to, probably because I know zip about scheme. There's very little about recursion that's good. Bad performance, bad readability, bad intuition. Prettiness != Usefulness.
This is the kind of attitude that I'm talking about. The one that views "recursion" as just some kind of weird alternative to iteration. Sadly, many professors teach in a way to leave this impression. Somewhere, the point is lost that recursion is fundamentally what allows you to compute with the same power as a Turing Machine, and that iteration is merely a degenerate form of recursion. The basic problem-solving skill of "Solve a smaller problem first" is the idea captured by recursion, and there are plenty of programs which must make use of this.
I think functional languages do a bad job of preparing would-be programmers for the eventual horrors they may/will face with imperative languages... lets face it -- the von-neumann model is imperative.
What functional languages permit is the use of formal reasoning skills, easily. This idea of reasoning about your program in order to demonstrate its correctness is what much of CS is about. You are then supposed to use those skills when writing your "imperative" programs, or at least think more about what you are doing.
To agree with smack Down in a slightly reworded fashion:
Recursion is definitely more elegant than iteration. Its elegant, powerful, sometimes even intuitive and useful. Its also nightmarishly slow on real hardware, and has very real stability concerns, especially when coupled with threading.
Elaborating my concerns on 'functional-first' teaching:
I have no objection to reasoning about problems at a high level and then dividing and conquering. The problem with functional languages IMHO is that the underlying hardware isn't functional -- its imperative. When you write functional code, you're writing something that is, at its barest essence, alien to the underlying machine (OK, I will concede that there have been functional machines in the past, but they are currently a $0 billion industry).
There is inherent, unavoidable inefficiency in writing non-toy code in a functional style, so if you ever expect a student to write non-toy code, you should teach them imperative reasoning, as well as expose them to all the horrors that go with it in a controlled environment (e.g. with a TA that can explain what the heck 'Segmentation Fault (core dumped)' means and what to do about it).
Lastly, I firmly believe that formal reasoning is on the verge of useless in a serious modern codebase (especially multi-threaded codes, which arguably will become the norm). Formal reasoning, as it stands today, breaks down in the presence of such rudimentary concepts as an
address, and stands no hope whatsoever of understanding such things as atomicity guarantees on bitfields in shared words, device interaction, even vanilla atomic operations.