views:

665

answers:

12

Some background about me, I work for a financial organsation, in a support job. Where we work 10-11 hrs a day in supporting applications, which doesn't require any new additional skill. But my work also demands me to spend 6-10 hrs of java (servlet/jsp) coding per week.

But after 9 yrs of experience, I feel passionate about programming and would like to become a monster in coding. Especially has lot of enthusiasm in solving some ordinary repeated problems in innovative way.

I could spend an hour in a day for learning new stuff. But my mind always a drunken monkey in concentration. So I need to choose a decision in what to learn (to master a new skill). Even if it is not going to help me in next 2/3 yrs in my current job, I would like to commit in learning to make it for future.

What to choose between "compiler construction (learning lexer, parser, LR, LL, GLR, LALR)" vs mastering functional programming?

Which one was difficult for you while you were learning? Which will make me to compete with the top notch programmers? Which one is tougher but highly revarding?

Please help me answering in the same order as my questions order.

I love this community, and stackoverflow :)

Note : I have some very basic knowledge about functional programming. Would like to master only one skill which should be very helpful.

+3  A: 

Functional programming is more practically useful, in my humble opinion. It's coming back into vogue, and finding its way into imperative languages. I only expect it to continue growing in popularity.

Chris
+1  A: 

In your order:

Choose whichever sounds more interesting.

Neither one was particularly harder to learn than the other; each had some moments up front where I had to learn to think about things differently than in the past. Once you get past that, it's just typing.

Neither one will make you compete with top-notch programmers, unless you fully master it after years of practice and study, or if you're naturally gifted (unlikely). In that case, either one will help you compete with top-notch programmers.

For me, neither one is all that highly rewarding. I get most of my productive work done in C/C++, but I'm beginning to see the advantages of prototyping in Lisp thanks to a very zealous coworker. I'm never going to write a compiler that is better than the ones that are available to me because I just am not interested in doing it.

We love you too.

jeffamaphone
A: 

Both are very different, it really depends on what you want to do with your knowledge when you are done. Probably functional programming would have slightly wider application, but compiler theory is pretty interesting (well to me anyway) and also a good skill to have.

In terms of whats harder, IMO thats too hard to answer, both are simple ;-) or hard... depending on your ability / experience.

Tim Jarvis
+8  A: 

Compiler construction in functional programming. Seriously, one of the most prominent uses of Haskell is writing compilers, and I've heard people who've written compilers in other languages and then Haskell say they'll never write a compiler in an imperative programming language again.

Write Yourself a Scheme in 48 hours can serve as a Haskell tutorial that teaches you both Haskell and some rudiments of writing a compiler (and Scheme, for that matter).

ShreevatsaR
+2  A: 

Compiler construction was my favorite class at University. I found great satisfaction in building up a code base that takes text and transforms it into executable code. Building a compiler is liberating, you are free to create your own keywords, syntax and style. Coding a compiler takes all the magic out of computing, it gets you in touch with the workings of the machine and offers an understanding about how and why programming languages are the way they are.

Functional languages are interesting, the type of problems and method of solution are worth understanding. But for me, in terms of pure comp. sci. wonder I say building the compiler tool chain is an experience worth having.

  • designing a language
  • generating IR code
  • running your first interpreter
  • executing you compiled code

Don't forget that you could build a compiler for a functional language. I suggest looking at a tool like Antlrworks as a great place to start. Oh and for your first go implement a simple language such as a variant of BASIC.

Paxic
+2  A: 

Functional programming involves learning a different way of thinking.

Compiler construction involves solving a set of interesting problems.

I'd say you'll get more out of writing a compiler as the skills you learn will be more broadly applicable as they will apply to more scenarios (in more languages, and to more problems).

After that, you can learn functional programming and try solving the compiler problems using those techniques.

Ryan Graham
A: 

Functional programming languages are slowly making a come-back, mainly because they allow for faster and easier parallelisation than other current languages. For example, erlang is used by telecomm's around the world to create massive PBX systems.

That being said, learning how to build a compiler is absolutely a blast and will help you learn many new techniques and will make you a better programmer as you realise that what you were doing before is not the most optimal way to program.

It really is a wash between the two, try both of them out, write a compiler in a functional programming language!

X-Istence
A: 

I can't say for compiler writing as I have only got my lexer done and started in on my parser generator.

However Functional programing is hard in an abstract way in that it is a way of thinking. I expect that compilers are much more of a technical problem involving a lot of details.

BCS
A: 

In my current work I have the privilege to work on a compiler and it is a blast, it full of moments when you have to think really hard about some problem and then get the rewarding YES! feeling when you solve them. Very energizing! There is also a severe lack of experienced compiler writers (especially in the field of optimization) so its a good skill to know.

Anders K.
+2  A: 

If you work in a Finance org writing software, then you already have a lot of the skills you need to write a compiler.

Writing financial software is basically about:

  1. Reading data in one form
  2. Translating the data into another form
  3. Doing some manipulations on the translated form
  4. Spitting the modified data out in another form

Usually it looks like:

  1. Grab a list of transactions
  2. Display the transactions in a UI and show it to an analyst
  3. Allow the analyst to make modifications to the data
  4. Save the modified data back into the database

A compiler works essentially the same way.

Basically you:

  1. Parse source code
  2. Run several phases of analysis on the parsed soure code
  3. Spit the data back out in machine-code or some form of IL

The biggest differences between a compiler and a finance app are that:

  1. The input data in a compiler is harder to read (it takes more work) than financial data
  2. The analysis is done by software, rather than by a human
  3. You need to know a bit more about algorithms and data structures to write a compiler then you do to write a finance app. Many finance apps get away with just using arrays to store everything. In a compiler you need to deal with character buffers, linked lists, hash tables, graphs, and trees. You may also learn a bit about design patterns too.

I would recommend that you learn how to write a compiler.

Learning a functional language is a great thing to do, because it shows you a different way to think about programming.

However, by itself, it isn't going to give you the same level of knowledge about computer programing that writing a compiler would.

All that data structure stuff is important, really really important, to being a good programmer. Once you write the compiler, then I'd look into learning functional programming.

Although some people might tell you to do both at once, i.e. learn how to write a compiler in a functional language, I'd urge you not to.

In order to appreciate the things functional programing gives you (and what it doesn't), you should understand all the stuff you have to do in an imperative language to write a large systems (like a compiler).

So my opinion would be that writing a compiler in an imperative language, and then learning functional programing, would be the best way to go.

Scott Wisniewski
I agree with your conclusion. But your example is a little funny, because the emphasis of functional programming is that all* problems boil down to (1) read in data (2) analyse and transform data (3) spit out data in usable form. So the OP's background is good for attacking both areas.*most. :)
Nathan Sanders
The reason I included that stuff was because a lot of people get intimidated by compilers, thinking there's just a bunch of black magic going on.I was trying to say "compilers really aren't that complex".
Scott Wisniewski
+2  A: 

I teach both functional programming and compiler construction. Your view of compiler construction is remarkably narrow and omits all the things which are difficult (code generation, calling conventions, register allocation, optimization).

Your questions:

  1. What to choose? Choose functional programming because it will significantly change the shape of your brain. Compiler construction is just another specialized technique in a world of specialized technique (although you could argue that it's more interesting and important than most other technique). Functional programming will change the way you think about everything you write. No contest.
  2. It was harder for me to learn compiler construction, but that's because I was using C, which is a crappy language to write a compiler in, along with yacc, which is a crappy parser generator.
  3. Both are hard and are probably about equally good at making you closer to a topnotch programmer. Maybe compiler construction has a slight edge because when you've built a compiler, it's obvious what you've done. It's not so obvious how you decide when you've become a good functional programmer.
  4. Both are tough---compilers because you have to manage a lot of details and functional programming because you have to think in new ways. Both are highly rewarding. Functional programming will start rewarding you earlier, as soon as you start to "get it". Compiler construction is not rewarding at first, but then you get a big reward when you finish your compiler and it works.

Since you are interested in both, I advise you to tackle functional programming first, then parsing combinators (functional parsing technique). Then if you want, write a compiler in a functional language. (Compilers are the killer app for functional languages.)

Norman Ramsey
A: 

Considering the number of NP-complete problems involved in compiler construction (both register allocation and instruction scheduling for example are NP-complete) I think we'll have to go with compiler construction.

Yeah, functional programming is different, but if you can program, ultimately it's just learning another programming language and depending on what you want to do and which language you pick, it may very well be easier than whatever you're currently programming in.

Whatever