Live data from Hacker News

Ask HN: Where did you first come across functional programming?

news.ycombinator.com

1–10 of 18 posts

Re: Ask HN: Where did you first come across functional programming?

#3
My first programming course was CS 61A at Berkeley, taught with the textbook Structure and Interpretation of Computer Programs. I had tinkered around a bit with other languages before that, but hadn't got seriously into programming until that time. I consider myself very fortunate not to have been previously indoctrinated into imperative / stateful programming.

Re: Ask HN: Where did you first come across functional programming?

#4
post #3

My first programming course was CS 61A at Berkeley, taught with the textbook Structure and Interpretation of Computer Programs. I had tinkered around a bit with other languages before that, but hadn't got seriously into programming until that time. I consider myself very fortunate not to have been previously indoctrinated into imperative / stateful programming.

What language do you work in now? If it is an imperative language do you avoid state as much as possible?

Re: Ask HN: Where did you first come across functional programming?

#6
The first programming language I learned was Scheme - I read the little schemer by Felleisen but my second book was what really taught me to program. This second book was structure and Interpretation of computer programs. I’ve been using lisp ever since. Scheme is a a beautiful language but I’m a Common Lisp guy now a days

Re: Ask HN: Where did you first come across functional programming?

#7
Haskell course in 3rd year at university in the year 2000. It was only 5 weeks and I didn't fully appreciate it at the time. I did maths for a few years after that and only returned to programming later and rediscovered functional programming as it started becoming popular again. I haven't programmed in a functional language professionally but ideas from functional programming have changed the way I write code.

Re: Ask HN: Where did you first come across functional programming?

#8
My first exposure to functional concepts was, doh, mathematics! Functions are maps, not procedures that flip bits. There recursive definitions and such. Inductive proofs. The activity of doing derivation: you leave the old formula as is, and produce a new one from it by applying rules, which you should recognize as a kind of function.

Some of this stuff, you play with in "Blub" imperative languages. If you write a recursive factorial or fibonacci in Pascal, that's functional programming. Just not with higher order functions.

The C preprocessor is an example of functional calculation. (Though macros can be undefined and redefined, mainly they are just defined and called, and perform substitutions without clobbering anything.)

Unix pipelines : don't clobber anything other than the file being created or replaced at the end.

Parsing a grammar with Yacc and building a tree: basically functional. The imperative bits going on are hidden under the hood. $$ = make_node($1, $3) is an assignment, but it's boiler-plate; you don't think of it as assignment, but yielding the semantic value of the rule, which is constructed from the pattern-matched $1 and $3 pieces.

All those things teach you that it's useful and good to calculate a new value from an existing one, while leaving the original alone.

There is a lot of functional programming in the middle of imperative programming. E.g. constructing a balanced binary tree might not be functional (it can be, but often isn't in Algol-like languages), the queries on that structure are conductive to functional programming. Queries don't mutate the structure, and if recursion is used, don't mutate traversal variables.

A binary search of an array can be coded functionally via recursion.

Here is a functional version of strchr in C:

  const char *strchr(const char *str, int ch)
  {
     return (*str == 0) ? 0
            : *str == ch ? str
            : strchr(str + 1, ch);
  }
Lisp was something that clicked almost instantly. I came to that armed with a lot of experience and understanding, and was well-versed in recursion, plus all around systems programming as an experienced developer. The idea that, say, a tree could be recursively defined as a null value, or else a node with two children, was nothing new. Or that a recursive function could search that.

Re: Ask HN: Where did you first come across functional programming?

#9
Long ago I wanted to make a specific script for Gimp which needed to be written in Scheme. I didn't know anything about FP at the time and didn't really understand why things were done the way they were.

Over a decade later I decided to learn F# and now it makes sense.

Re: Ask HN: Where did you first come across functional programming?

#10
As a self taught developer functional programming is my original programming style. I never understood why anybody would choose OOP unless a language forced it on you. To me OOP is more complex and requires so much more decoration and ritual.
Post reply on HN