Skip to main content
added 120 characters in body
Source Link
Rushi
  • 948
  • 5
  • 12
  • Those who think as above and prefer assignment-free3 languages are typically called functional4 programmers
  • Languages with assignment are called imperative languages (and from the pov above OO and classic imperative languages are much the same)

The answer is Yes: Using imperative programming in a first programming course 45 befuddles their thinking

4 "Functional" is actually a misnomer; something like "mathematical" would have been better.

5 Imperative programming of course must be taught; if it is done in a later course, there is no unnecessary confusion.

  • Those who think as above and prefer assignment-free3 languages are typically called functional programmers
  • Languages with assignment are called imperative languages (and from the pov above OO and classic imperative languages are much the same)

The answer is Yes: Using imperative programming in a first programming course 4 befuddles their thinking

4 Imperative programming of course must be taught; if it is done in a later course, there is no unnecessary confusion.

  • Those who think as above and prefer assignment-free3 languages are typically called functional4 programmers
  • Languages with assignment are called imperative languages (and from the pov above OO and classic imperative languages are much the same)

The answer is Yes: Using imperative programming in a first programming course 5 befuddles their thinking

4 "Functional" is actually a misnomer; something like "mathematical" would have been better.

5 Imperative programming of course must be taught; if it is done in a later course, there is no unnecessary confusion.

added 175 characters in body
Source Link
Rushi
  • 948
  • 5
  • 12

Peter Deutsch, the creator of the smalltalk implementation that inspired the javaJava-Jitjit (and much else), famously said:

Here are two identities $$a(b+c) = ab + ac \tag{distrib. law}$$ $$x^{m+n} = x^m x^n \tag{index law}$$

$$ \begin{aligned} a(b+c) &= ab + ac & \text{distributive law} \\ x^{m+n} &= x^m x^n & \text{index law} \end{aligned} $$

I guess everyone will agree that in the context of school math these are unproblematic? Almost trivial?

Lets special-case the above with $c=1$ in the first and $n=1$ in the second and we get $$a(b+1) = ab + a $$ $$x^{m+1} = xx^m$$$$ \begin{aligned} a(b+1) &= ab + a \\ x^{m+1} &= xx^m \end{aligned} $$

(Assuming that the answer to all the above is no,no,no) x 
Lets ask now:
Whats this to do with programming?

These can be trivially1 translated to haskell

  as

So after i=i+1i = i+1 does i == i+1 ?!

Lets ask our math-respecting executor Haskell:
Ok oneOne can writeeasily enough write

And no trouble...it seems

But when we ask what is x we get, almost literally, an explosion!

2mutation Mutation is actually much worse than assignment; in fact mutation messes up imperative programming as much as imperative programming messes up mathematics. A brief trailer

4 Imperative programming of course must be taught; Ifif it is done in a later course, there is no unnecessary confusion.

Peter Deutsch, the creator of the smalltalk implementation that inspired the java-Jit (and much else), famously said:

Here are two identities $$a(b+c) = ab + ac \tag{distrib. law}$$ $$x^{m+n} = x^m x^n \tag{index law}$$

I guess everyone will agree that in the context of school math these are unproblematic? Almost trivial?

Lets special-case the above with $c=1$ in the first and $n=1$ in the second and we get $$a(b+1) = ab + a $$ $$x^{m+1} = xx^m$$

(Assuming that the answer to all the above is no,no,no) x Lets ask now:
Whats this to do with programming?

These can be trivially1 translated to haskell

  as

So after i=i+1 does i == i+1 ?!

Lets ask our math-respecting executor Haskell:
Ok one can write

when we ask what is x we get

2mutation is actually much worse than assignment; in fact mutation messes up imperative programming as much as imperative programming messes up mathematics. A brief trailer

4 Imperative programming must be taught; If it is done in a later course, there is no unnecessary confusion

Peter Deutsch, the creator of the smalltalk implementation that inspired the Java-jit (and much else), famously said:

Here are two identities

$$ \begin{aligned} a(b+c) &= ab + ac & \text{distributive law} \\ x^{m+n} &= x^m x^n & \text{index law} \end{aligned} $$

I guess everyone will agree that in the context of school math these are unproblematic? Almost trivial?

Lets special-case the above with $c=1$ in the first and $n=1$ in the second and we get $$ \begin{aligned} a(b+1) &= ab + a \\ x^{m+1} &= xx^m \end{aligned} $$

(Assuming that the answer to all the above is no,no,no) 
Lets ask now:
Whats this to do with programming?

These can be trivially1 translated to haskell as

So after i = i+1 does i == i+1 ?!

Lets ask our math-respecting executor Haskell:
One can easily enough write

And no trouble...it seems

But when we ask what is x we get, almost literally, an explosion!

2 Mutation is actually much worse than assignment; in fact mutation messes up imperative programming as much as imperative programming messes up mathematics. A brief trailer

4 Imperative programming of course must be taught; if it is done in a later course, there is no unnecessary confusion.

Formatting
Source Link
Rushi
  • 948
  • 5
  • 12
a*(b+1) = a*b + a
a*0     = 0
a*(b+1) = a*b + a
a*0     = 0
x^(m+1) = x*(x^m)
x^0     = 1
x^(m+1) = x*(x^m)
x^0     = 1
 i = i+1
 i = i+1
 ? i
 
 ERROR: Control stack overflow
 ? i
 
 ERROR: Control stack overflow
a*(b+1) = a*b + a
a*0     = 0
x^(m+1) = x*(x^m)
x^0     = 1
 i = i+1
 ? i
 
 ERROR: Control stack overflow
a*(b+1) = a*b + a
a*0     = 0
x^(m+1) = x*(x^m)
x^0     = 1
 i = i+1
 ? i
 
 ERROR: Control stack overflow
Reworded
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
Wrong link
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
Rewritten
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
Tex equation
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
edited body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
added 7 characters in body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
added 22 characters in body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
edited body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
edited body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
added 6 characters in body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
added 6 characters in body
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
Formatting
Source Link
Rushi
  • 948
  • 5
  • 12
Loading
Source Link
Rushi
  • 948
  • 5
  • 12
Loading