42

I know Lisp and Haskell are logic and functional programming languages respectively, but what exactly does this mean? How do they differ from other languages? I've heard that learning these will make you a better programmer and improve your logic. Is this true, and if I go learning Lisp or Haskell to a competent level will my programming improve and will I be better at handling any problem in any language? I just wanted to know to see if they are worth the effort of learning. Also are these languages useful in areas such as GUI and graphics or are they just useful for console applications?

Logan545
  • 635
  • 1
  • 6
  • 5
  • 37
    Using LISP and Haskell will make you a better LISP and Haskell programmer, I guarantee it. – Neil Sep 09 '13 at 16:10
  • 3
    The people who say this usually are Lisp and Haskell programmers pushing their own agenda. All of the useful features of Lisp are already in common use in mainstream programming languages. But if these languages really were so much more useful, people would be using them. When's the last time you used a program (*any* program) written in Lisp or Haskell? (Do any programs written in Haskell *even exist?* I know Emacs exists, on the Lisp side...) – Mason Wheeler Sep 09 '13 at 16:21
  • 3
    @MasonWheeler fair point. But I think that the fact that there are not many Lisp/Haskell programs is due to the platform/ecosystem/culture/adoption rather than the languages . Those things are really independant. Regarding existing haskell programs, there are very mature backends for web applications. – Simon Bergot Sep 09 '13 at 16:30
  • 3
    A Fortran programmer can write Fortran programs in any language, believe me! (See http://www.codinghorror.com/blog/2005/04/you-can-write-fortran-in-any-language.html) – Doc Brown Sep 09 '13 at 16:31
  • 18
    @MasonWheeler I have to say; there is a lot in Haskell's type system you won't find in any other language, and LISP macros are nowhere to be found in any mainstream languages. Both of these things are worth learning because they *do* make you a better programmer in your working language. At least this has been my experience; Haskell made me a better enterprise C# developer. I know techniques for implementing separation of concerns cleanly that I never would have otherwise, and parsing problems will forever be much simpler for me than before I learned Haskell. – Jimmy Hoffa Sep 09 '13 at 16:36
  • 6
    Erlang is a functional language. Rabbit MQ is written in Erlang and Rabbit's used in lots of places to do lots of mission critical heavy lifting. Functional languages teach you to think differently about programming, and that's a nice extra tool to have at your disposal. While it's true some of those concepts have made it into more popular languages (e.g. lambda expressions in C# and C++), you still approach problem solving in a very different way when using a functional language. – Binary Worrier Sep 09 '13 at 16:42
  • 3
    See also [why should I learn a new programming language](http://programmers.stackexchange.com/questions/136133/why-should-i-learn-a-new-programming-language) –  Sep 09 '13 at 16:48
  • 8
    @MasonWheeler There are perfectly good reasons a language may be more useful than the rest, but still not widely used. I can think of many: existing user base, too radical a change, when "good is good enough", and also... when the better tool requires programmers who are more formally trained. So _popularity_ is not a good measure of _usefulness_. – Andres F. Sep 09 '13 at 17:13
  • 5
    @MasonWheeler To use an analogy, mathematics is a hugely useful field in real life. So why aren't more people proficient at maths? Why are a lot of people scared of it, and think it's black magic and not really all that useful? – Andres F. Sep 09 '13 at 17:14
  • @JimmyHoffa Heh heh, well, I never said _I_ didn't think it was witchcraft ;) – Andres F. Sep 09 '13 at 17:22
  • 1
    @MasonWheeler Lisp macros are an incredibly useful feature of that language. Can you name a mainstream language with an equivalent feature in common use? – WolfeFan Sep 09 '13 at 18:15
  • 5
    Haskell is not a logic programming language and neither is Lisp. – Isaac Kleinman Sep 09 '13 at 21:06
  • I think you should instead ask what functional programming is. – Dima Sep 09 '13 at 21:26
  • Pedantic note, it's Lisp, not LISP nowadays – daniel gratzer Sep 09 '13 at 21:27
  • @IsaacKleinman, of course Lisp is a logic programming language. See http://norvig.com/paip.html for details, take a look at cKanren and alike. – SK-logic Sep 10 '13 at 10:32
  • 1
    **I would like to remind everybody to attack the argument and not the person. Rude comments and revenge flagging will not be tolerated. Thank you.** – maple_shaft Sep 10 '13 at 13:03
  • Lisp is not even a language nowadays but a class of languages with extremely similar uniform syntax, together with things that obviously fit well such syntactic setting, such as macros and "code is data". – Erik Kaplun Jan 07 '16 at 11:44

3 Answers3

38

It is very much like learning math will improve your analytic skills and learning latin/classic literature will improve your writing skills.

People who designed those languages have thought hard about what does writing a program means. And those languages are the results of those researches.

That said, learning Java will also make you a better programmer. And learning C. The real benefits comes from learning languages with different philosophy. Then you can have your own opinion about the way a program should be written.

Edit

I realize this answer is not so useful for people who have not yet learn haskell and/or lisp. Here are some examples to explain further what I mean

LISP

Lisp believes that syntax should be minimal, and that everything should be either a list or a primitive (Lisp stands for List Processing). Even programs are mainly list containing other lists and symbols. Lisp allows you to manipulate programs as list, and to generate new programs on the fly. Hence the whole code is data and data is code motto.

The direct consequence is that the Lisp languages allows you to define any interface you want. A nice exemple is compojure which is a clojure web framework. Here is what a routing function look like

(defroutes app-routes
  (GET "/" [] view/page)
  (GET "/api" [] (wrap-aleph-handler api/socket-handler))
  (route/resources "/static")
  (route/not-found "page not found"))

Another nice exemple is the hiccup templating framework:

(html [:ul
  (for [x (range 1 4)]
    [:li x])])

As you can see, the result is as terse as in DSL like mustache, but allows you to use the language features such as (for [x (range 1 4)] block). Even nicer, you have all the tools to abstract and structure your code.

In other languages, the syntax is more complex. You cannot read a Java program as a bunch of lists. But by using Lisp, you get a better idea about what an ideal interface should look like, and what in your code can be abstracted away as data. It also helps you to see your favorite language as a big data structure, and to better understand its semantics.

Haskell

Haskell believes in strong static typing and purity. Pure functions are like mathematical functions: they are defined on a set of values, and map them on another set. Function don't have side effects, and values are immutable. Purity is interesting because it is not something a multi-paradigm language can have. A language is either pure or not.

One consequence is that you cannot perform IO action whenever you want (haskellers believes that this is a good thing). IO actions are defined as transactions, which are themselves pure values. The main value of a haskell program is a IO transaction executed when you run the program.

You have to deal explicitly with the data flow in your program. You cannot make two component communicate by writing & reading stuff in a global variable. You have to build and pass values.

Another feature mentioned by Jimmy Hoffa is the rich type system. While other languages have static typing, in haskell you can have things like:

length :: [a] -> Int (function from a list of a's to an int)

map :: (a -> b) -> [a] -> [b] (function that takes a a to b transform and a list of a's, and returns a list of b's)

The nice thing is that I don't need to explain what those function actually do: you already understand their behavior. What's more, functions with those signatures cannot really anything but compute the length of a list and map a transformation over a list.

In other typed languages, class hierarchies combined with the mutability make dealing with those types a nightmare. You have to understand things like covariance and contravariance, which are impossible to get right from a language perspective (ie simple, powerful and safe).

Either you take the safe path (like scala) and end up with a really complex language, or you take the simple path and get something which is either limited (google go generics limited to list and maps) or unsafe (dart generics which are always covariant).

By using haskell, you mainly learn about the benefits of purity, and how to write pure code.

Simon Bergot
  • 7,930
  • 3
  • 35
  • 54
  • Just being a little pedantic on the last point. While I'm sure knowing assembly has its advantages, I very much doubt that it would make you a better programmer. If you adopted any techniques from programming in assembly, it would most assuredly make you a worse programmer. – Neil Sep 09 '13 at 16:36
  • 1
    @JimmyHoffa I think that actually deserves its own answer, because this is what people tend to overlook. There are problem domains best solved by functional programming that people don't even realize exist until they've at least dabbled in those domains outside of their comfort zone. – KChaloux Sep 09 '13 at 16:42
  • 2
    I don't know about Assembly, and I didn't mention it either. However assembly can help you understand how your programs are running. There are great post on SO of people who are able to analyse a piece of generated assembly in order to explain a performance issue. – Simon Bergot Sep 09 '13 at 16:43
  • 3
    @KChaloux I would write the answer but this question should be closed (I close voted accordingly). Simply put I could write my opinion and experience in an answer, but it would be no more right or wrong than the other answers, which is the problem is language-recommendation questions, and why I voted to close. – Jimmy Hoffa Sep 09 '13 at 16:44
  • I think this answer is great, *The real benefits comes from learning languages with different philosophy. Then you can have your own opinion about the way a program should be written*. Also you don't need to learn a programming language to find out what is good for, there are a lot of resources you can review in order to do that. – jsedano Sep 09 '13 at 17:53
  • +1 for the skills analogy – Thiago Silva Sep 09 '13 at 19:04
  • 7
    OMG, @Neil knowing what the computer is actually doing *most assuredly* will make you a better programmer. I haven't written assembly in years but regularly read it (across a bunch of platforms) and if you care about how your program actually works, it's critical to know at least the basics. – dash-tom-bang Sep 09 '13 at 20:45
  • 1
    @dash-tom-bang, yes, but does it make you actually code your programs better? If so, I'd like to hear an example of that. Even if you find an example of that, does that outweigh the heavy tendency you gain to program with spaghetti code? – Neil Sep 10 '13 at 07:46
  • 4
    @Neil, in what case is being a worse programmer a benefit? What makes you bring up spaghetti code? What does spaghetti code have to do with assembly or being a good programmer, except in the fantasyland of not knowing assembly and needing a rationalization to avoid learning it? If anything, being a *good* assembly coder makes one *highly aware* of bad coding practices. – dash-tom-bang Oct 31 '13 at 07:17
  • 1
    @dash-tom-bang In the same way that someone who started learning how to program using basic cannot easily transition to object-oriented code, likewise starting to code in assembly must have its share of disadvantages. Apparently you are one such programmer, and if you are an exception, good for you. Let me make this clear: it was not a personal attack on your programming skills. – Neil Nov 04 '13 at 08:52
  • 1
    @Neil we have strayed from the topic at hand. Nobody said anything about _starting_ in assembly anyway. Learning a foreign language doesn't make you less proficient in your native tongue and in fact sometimes it can give you insights into communication that make you more effective with your native tongue. At worst, it gives no benefit. (Besides- programming aptitude is not determined by the first language one sees; some people understand pointers and recursion and others don't, regardless of first language.) – dash-tom-bang Jan 08 '14 at 06:21
  • @Neil you asked an example of how knowing assembly does make you a better programmer. Even though I am almost didn't programmed in assembly, but mostly just hacked a simple shareware, to me it very useful. When I was learning Basic, next Pascal, and C, I didn't understand what lies underwear. I haven't see what is variable, why «Integer» could be of a different sizes. When I learned assembly, I become able to see a difference of alike lines of code, I can suppose, how would it look like in the machine code. I can optimize much better with this understanding, I just see how it works. – Hi-Angel Jan 23 '15 at 23:05
15

tl;dr Learning new stuff can only make you a better programmer, but being a better programmer is not about the languages you can write code in.

What are the advantages of using LISP and Haskell?

LISP:

  1. Homoiconic code. This allows structured self-modifying code.
  2. Syntax-aware macros. They allow rewriting of boilerplate code.
  3. Pragmatism. CL is designed to get stuff done by working professionals. Most functional languages aren't, as a rule.
  4. Flexibility. It can do a lot of different things, all at reasonable speeds.
  5. Wartiness. The real world is messy. Pragmatic coding winds up having to either use or invent messy constructs. Common Lisp has sufficient wartiness that it can get stuff done.

Arguably the only real reasons to choose against CL is that the standard libraries are dated.

I will go out on a limb and say that in the general case, syntax should not be an issue to a professional software worker.

From: Why is Lisp useful?

Haskell:

Haskell is a computer programming language. In particular, it is a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. The language is named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages. Haskell is based on the lambda calculus, hence the lambda we use as a logo.

You can read there a description of Functional vs imperative

From: http://www.haskell.org/haskellwiki/Introduction

Will they make me a better programmer?

Yes, of course, knowing more languages and paradigms can only make you a better programmer, but get this straight:

There is not a single tool, a single book, a single programming paradigm that will make you a better programmer.

Learning different programming languages with different paradigms definitely help you to be a better programmer, learning to solve problems with different aproaches also benefit your logical thinking greatly.

Being a good programmer is not much about the language, but about having the ability to solve any problem in any language. And when you don't know the language, the ability to learn that language quickly and use it effectively.

I think, that the more global your thinking is, the better developer you are.

For example, you may add useful comments to your code, care about the readability of your code, the maintainability. Pay attention to the little details. Think before typing!. Learn about desing patterns. Follow good practices.

Disclosure: This is shameless advertising of the worst kind, because it is from my blog.

jsedano
  • 440
  • 2
  • 14
  • 4
    Have you learned LISP or Haskell to any competent level? – Jimmy Hoffa Sep 09 '13 at 16:38
  • I fixed the broken link of my god-awful programming blog, and no, I don't know LISP or Haskell, those are tools I don't need right now, I could learn them for fun, but I am spending my free time developing my pet project. – jsedano Sep 09 '13 at 16:43
  • 1
    how does this answer the question asked? – gnat Sep 09 '13 at 16:46
  • @gnat I improved the answer. – jsedano Sep 09 '13 at 16:53
  • 10
    It's a little disingenuous to hear this from someone who knows near nothing of either language. You claim they aren't tools you need right now but you have no idea what they're tools for, so how can you know this? Also how can you advise someone what they will or will not learn from them, as far as you're aware LISP is a SQL derivative only useful in relational data analysis and Haskell might be a strict subset of Regexp. – Jimmy Hoffa Sep 09 '13 at 17:13
  • @JimmyHoffa **You claim they aren't tools you need right now but you have no idea what they're tools for, so how can you know this?** Maybe because my pet project is a video game app for iOS that I intend to develop in pure Objective C ???? – jsedano Sep 09 '13 at 17:15
  • 10
    This doesn't really answer the question. You succeeded at the impressive feat of giving a vaguely general answer to a question about two languages you don't know :/ – Andres F. Sep 09 '13 at 17:18
  • @AndresF. Yes, I can do anything when I put my mind in it, jokes aside, I have answered questions in Stack Overflow without knowing the language!, I have seen people answering questions on Parenting that doesn't even have children!. Remember this: is not about the programming language. But of course you need to read/research in order to know if that particular programming language suits your problem better, but the reasons why a programmer pick a special language for a specific task, can vary, for example: http://www.codinghorror.com/blog/2013/03/why-ruby.html – jsedano Sep 09 '13 at 17:25
  • 1
    @JimmyHoffa I think now you are just trying to be a troll, I said I want my app to be written in pure Objective-C, I want it to be native. Also, one doesn't need to know the syntax of a programming language to see if it suits your needs, how do you know http://en.wikipedia.org/wiki/Whitespace_%28programming_language%29 is not the right tool for a problem? do you learn to write code in it? or do you read a description of the language? – jsedano Sep 09 '13 at 17:28
  • @JimmyHoffa There is a new framework by apple for developing games called Sprite Kit, I want to use that. (And we better stop this now, because it's getting pretty long, if you want we can talk about this later on chat). – jsedano Sep 09 '13 at 17:49
  • 1
    @anakata How do you know it's not about the programming language if you haven't tried it? – Andres F. Sep 09 '13 at 18:01
  • @AndresF. Let me put this easily, I don't now how to program in Golfscript either, (http://www.golfscript.com/golfscript/) but I can see that is not the right choice if I want to develop a web app. – jsedano Sep 09 '13 at 18:12
  • 2
    -1 because this vaguely dances around **what** exactly Common Lisp and Haskell teach you. Examples: Code as Data data as code, purity, referential transparency, monadic abstractions, functional programming, language oriented programming, type directed programming, etc etc etc – daniel gratzer Sep 09 '13 at 21:21
  • 3
    Furthermore not knowing either language I don't think you can answer that question :/ Sorry – daniel gratzer Sep 09 '13 at 21:22
  • @jozefg Don't be sorry. And yes I don't know Lisp or Haskell that's why I used references for my answer, but I think, the most important thing to understand is that programming languages are just tools, in the end the hardware couldn't care less in wich high or low level language you're coding on, programming languages are tools for humans. We try to pick the ones that better suits our needs, and I think my answer does answer the question that the OP is asking. – jsedano Sep 09 '13 at 23:54
  • @jozefg You said it: **Languages are tools, this hurt a little to say. It's completely true, but it's still hard to accept.** and **If a language is making you focus on the language, not abstraction, algorithms, or data structures, it's a bad language for a beginner.** Great advice. – jsedano Sep 10 '13 at 00:55
11

When you learn languages that are outside of the paradigm that you usually operate, it will open your mind to alternative solutions in your day to day and may even help you understand some features in your language of choice better. Just knowing those languages aren't going to make you a better programmer unless you can take the lessons you learned from those languages and apply it to situations you see everyday.

That being said, it isn't limited to languages. When you read up on various data structures that you haven't seen or used before, it can help broaden the scope of you knowledge so the next time you encounter a problem you have one more possible solution.

Jetti
  • 5,163
  • 2
  • 26
  • 41