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?
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.
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 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 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.
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?
- Homoiconic code. This allows structured self-modifying code.
- Syntax-aware macros. They allow rewriting of boilerplate code.
- Pragmatism. CL is designed to get stuff done by working professionals. Most functional languages aren't, as a rule.
- Flexibility. It can do a lot of different things, all at reasonable speeds.
- 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 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
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.
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.