![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 5
Rep Power: 0
![]() |
Functional Programming Languages
All of my programming experience has been in languages such as C++, Perl, PHP, and Python. Maybe it's because of Pugs (or maybe I'm just expanding out and trying to learn more), but I've been hearing a lot about functional programming languages lately, like Haskell, Scheme, OCaml and the like.
I've seen some examples of these, and as I've never been exposed to them before, find them pretty difficult to understand. Where as with Python and C++, I could look at some example code not knowing the language and piece together what each line meant. So, my question for you all of you is: Do you think there's a benefit to learning one (or more) of these languages? Of course I don't want to limit "these languages" to the ones I listed above as examples. There's also the question of usefulness. In what I've read on the subject, which is arguably not very much, I don't see functional languages being spoken of outside classrooms. My lack of experience with them leads me to believe that if I had to solve a problem using Perl and Scheme I'd have a completed Perl script and a fist through my monitor while working with the latter. |
|
|
|
|
|
#2 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
I'll give you a few examples. The solution I devised for a long term programming project I'm working on for my company has its roots in Haskell's function composition. In addition, the functor standard I created for it owes much homage to Haskell's functions and monad system. Another example is a javascript Ajax scroller system I was working on. I originally used the LiveGrid object from the Rico toolkit, but I found it to be poorly designed. I created my own, and in order to get the system straight in my head I took a bottom up functional approach, constructing a base until it was sufficiently complete that I could design my buffering algorithm without getting bogged down in the details of the problem. Of course I don't want to limit "these languages" to the ones I listed above as examples. There's also the question of usefulness. In what I've read on the subject, which is arguably not very much, I don't see functional languages being spoken of outside classrooms. Start simply to begin with, and work up from there. Functional languages are such a paradigm shift that you need to relearn basic concepts in order to work efficiently in them. But succeed in that, and you'll vastly expand your perspective. |
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4
![]() |
I'll second that. I hadn't touched any sort of functional programming until they taught us Haskell at University and it was a real brain twister at first, but it actually feels very natural after a while. It's a very pure kind of programming. With imperative languages you can grunt along through the steps without every really being a particularly good programmer but functional programming really makes you distill the solution before you start. Haskell didn't just make me a better programmer, it improved my maths dramatically and gave me a much better feel for the difference between an elegant program and one that just shuffles along like a zombie.
I think the main reason you don't see a lot of functional languages in use in the 'real world' of IT is that there just aren't very many good programmers out there doing it for a living to be honest. Companies would rather their software developers produced code that did the job, no matter how much it creaked, without being able to command too high a salary. Languages like Haskell, LISP and friends do see the light of day outside of classrooms, but apart from in the world of free software (where Scheme and LISP make several notable appearances) and academia there's more interest in brainfarts like VB than in the joy of good code. If you love programming, learn Scheme. A bit of a strange recommendation from me because I don't actually know it, but it's a descendant of LISP so I'm sure it's gorgeous and since it seems to give the GNU crowd wood it's probably not a bad horse to back in terms of practical usefulness either.
__________________
"I'm not a genius. Why do I have to suffer?" |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Dec 2005
Posts: 118
Rep Power: 0
![]() |
AFAIK python is a functional language too - only people don't notice it because it can also do things imperatively. Check out Python for Lisp Programmers for a comparison.
Some functional features python doesn't have: -Continuations: present in scheme and ruby, absent in common lisp -Tail recursion optimisation: present in scheme, absent in the common lisp standard (but implemented by some environments, e.g. CLisp) There is/was something called "stackless python" being developed to implement them... |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
The latest version of Python, 2.5, has support for continuations via the bidirectional yield statement.
I also wouldn't class Python as a functional language. It has features in common with functional languages, but Python is very much a procedural language. Python also lacks macros and parameter matching. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Nov 2006
Posts: 5
Rep Power: 0
![]() |
Thanks for the great replies. I found a free book on Ocaml, so I started to crawl through that.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Dec 2005
Posts: 118
Rep Power: 0
![]() |
I've been trying to learn some Lisp and the macros look pretty awesome - but do all functional languages have that feature?
What's parameter matching? (Google gives something about C++ which seems related to function overloading?) (And I think I misrepresented stackless - the site talks mostly about threads, and while continuations are mentioned as part of how stackless was written, I don't think it allows you to use them explicitly.) |
|
|
|
|
|
#8 | ||
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
Most languages are turn code into an AST (that's an Abstract Syntax Tree) before attempting to run or compile it. This allows the computer easier access to the contents of the code, without having to reparse the text over and over again. For instance, if a compiler came across the code "x = 2 * y + 1", it might convert it to the AST shown below: =
/ \
x +
/ \
* 1
/ \
2 y(= x (+ (* 2 y) 1) Because Lisp is essentially just an AST written out in text, one can manipulate the AST (and hence the syntax of the language) very easily. Macros can be written without much special syntax; other languages which support Macros have to resort to more complicated libraries and functions. Quote:
sum [] = 0 sum x:xs = x + (sum xs) The above function is equivalent to the following in Python: Python Syntax (Toggle Plain Text)
|
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What programming languages and programs do online casinos use? | Splashedwater | Other Programming Languages | 9 | Jun 6th, 2005 2:53 AM |
| What programming languages should I learn? | theduck | Other Programming Languages | 6 | May 28th, 2005 9:34 AM |