4 ms·
>There are very few things in the world of CS/programming where I can't follow along and grok what's going on, especially when laid out in a tutorial form like
by chongli 14y ago
>There are very few things in the world of CS/programming where I can't follow along and grok what's going on, especially when laid out in a tutorial form like this.
That's probably because most of the tutorials you've followed have adopted an imperative style of programming. It is easy for you to follow along because it really isn't all that different from what you are accustomed to. Functional programming really is a different beast entirely. It's often said (though I remain skeptical) that it's actually easier to learn functional programming as a non-programmer than to un-learn your imperative programming tendencies.
>The fact that I was totally lost when reading this is not a good sign when you're trying to get people to adopt your school of thought.
I don't think that's a fair assessment. You could say the same thing about starting from functional programming and switching to imperative; some people actually do this! They find the idea of mutating a variable to be completely counter-intuitive!
- cynwoody 14y ago> They find the idea of mutating a variable to be completely counter-intuitive! The notion of mutation is implicit in the definition of "variable."
- chousuke 14y agoExcept it isn't. Unless you learn imperative programming before you learn basic algebra, the first definition of a variable you encounter is that of an immutable one.
- Shorel 14y agoActually an algebraic variable is named that way because you can change it every time you do the exercise. So you don't change it during one exercise, but you can and certainly will change it when you change the exercise to another one with the same principle.
- chongli 14y agoRight, but you're not mutating it in the middle of your calculation.
- Gravityloss 14y agoIf you have a sum for example sum_{x=1}^{10}x^2, x definitely changes quite many times during your calculation.
- chongli 14y agoNo, that's an example of recursion. With recursion you aren't mutating the variable, you're shadowing its definition. This is a subtle, but important, distinction.
- Gravityloss 14y agoRecursion? The "function" is not calling itself at all. I'm quite sure that is not recursion, neither in the mathematical nor computer science sense.
- chongli 14y agoRecursion is how you implement a sum without mutation (an imperative loop is how you'd implement it with mutation). You've merely given me the function written in a declarative notation.
- Gravityloss 14y agoI think we are talking about different things. For example, if you integrate x^2 dx from x=0 to 10, x changes continuously. It's clear that x is not fixed to any particular value.
- chongli 13y ago
- balloot 14y agoI would love to meet this mythical being who understands functional programming but has no clue how to write an imperative program.
- wwweston 14y agoWhile going through a Math undergrad program in the mid-90s, I noticed that some number of my fellow students had a distaste for programming. As someone who'd done reasonably well with both and had thought of them as heavily overlapping areas, I thought this was interesting, so I tried to poke at this a bit. One of the concepts I got back from a talented classmate was basically a complaint about mutable variables -- that in an algebraic description of relationships for a given system what we call "variables" are less variable and more "unknowns" which represent fixed if unidentified quantities. Others similarly noted there was something absurd about writing out equations like "x = x + 2".
- tripzilch 14y agoI can see why they think that, but the important thing is that "x = x + 2" is not an equation. It's just an arguably poorly chosen operator (Pascal gets this right and uses ":=" for assignment). The trick is to stop reading that line (in your head) as "x is equal to x plus two", but instead "x is assigned the value of x plus two".
- wwweston 14y ago> It's just an arguably poorly chosen operator (Pascal gets this right and uses ":=" for assignment). That's one potential takeaway, but when I turned over the complaint in my mind, this was arguably another way of complaining about mutability. Also, given the timing, it's pretty likely that one of the languages they'd learned was Pascal: that was the language of the first few CS classes at my school in the 90s, it was also the language of any high school curriculum that led to the AP exam, and Borland's Pascal products were still pretty popular PC dev environments. They could've also been unlucky and received their first exposure by choosing to do a numerical analysis class in Fortran or C, of course. :/