3 ms·
What's funny is that I was talking to someone just learning to program the other day, they were learning variables so I asked them if we have int x = 4; and the
by Homunculiheaded 16y ago
What's funny is that I was talking to someone just learning to program the other day, they were learning variables so I asked them if we have int x = 4; and then x = x + 1; what is the final value of x? Their intuition was that this does not make sense since x cannot possibly equal x + 1 in this case. I suddenly realize that Haskell's picture of programming in this regard may in fact be closer to the way people reason about problem before they learn to program.
- erez 16y agoOne should hope Haskel, and other functional programming evangelist come with a better element to display. The = operator is just syntax. Pascal uses :=, you could use ## for all the compiler care (as in x ## x + 1), or I could eschew all operators and have a x.assign(x.increment()), so no math student gets confused. There's great power in the idea of single assign, and the notion of immutable objects (be it variables, or else) is getting many programmers to rethink their ideas, but saying "this is right because it's like in math" is selling the idea short, and not doing any justice to the strengths of functional programming.
- T_S_ 16y agoIt's not just a matter of syntax. It's what some people call the difference between expression (which are mathematical) and statements (which are harder to manage mathematically). Check out Hughes' well known paper or some discussions about it. <http://weblog.raganwald.com/2007/03/why-why-functional-programming-matters.html> http://weblog.raganwald.com/2007/03/why-why-functional-progr...; I simply point out this feature because most people focus on language features and this is "programmer feature" that you might not think of if it wasn't pointed it out.
- silentbicycle 16y agoOr, put another way, statement-based languages vs. expression-based languages. Strictly speaking, they can be equivalent, but each pushes code in different directions by default. (And for the whole "= means mutate-variable" thing, I think "<-" is a good operator.)
- mahyarm 15y agoSqueak smalltalk has the <- character. It's actually the '_' character but displays as a one character width left arrow. You can also use :=