views:

311

answers:

4

This is my first post. Please be gentle if in ignorance I violate accepted norms... I did spend significant time in the FAQs. ;-)

Until recently my knowledge of XSLT was enough for my simple, straightforward needs. But a more advanced requirement sent me to reference material when "just trying stuff" didn't work. It was actually fun starting over at the beginning. I initially learned XSLT in the middle of deadline pressure and in 20/20 hindsight "working" was clearly more important than "understanding."

I was surprised to read on page 33 of Michael Kay's book that XSLT has its roots in Scheme. Wikipedia says,

Scheme is one of the two main dialects of the programming language Lisp.

Maybe I know (or will soon know) more about functional programming than I thought I did. Searching SO for posts like Is XSLT a functional programming language? and following its working links show there are several opinions whether or not XSTL is a functional language. From the post Which functional programming language should I choose as first functional programming language? I got the advice to learn F# first because I come from .NET and I like to get to useful programs quickly.

My first question is, if someone knows XSLT 2.0 very well, how much of a "real" functional programming language such as F#, Lisp or Haskell does the person already know before learning F#, Lisp or Haskell? For purposes of discussion assume a person who "Knows XSLT 2.0 very well" learns very few new concepts the first time she reads the XSLT Cookbook. Instead her reaction to unfamiliar information is, "Of course that's a good way to do that. I should have thought of that!"

The second question is, are there parts of XSLT 2.0 / XPATH 2.0 I should make sure I understand very well to make learning F# / Lisp / Haskell easier?

Third, are there parts of XSLT that are best ignored if one plans to eventually learn F# / Lisp / Haskell / etc.? That is, does XSLT have concepts analogous to GOTO, ALTER and ON ERROR RESUME NEXT that are not appropriate in "real" functional programming languages?

Brief answers are fine because learning a functional programming language is an unscheduled future project for me. Thanks!

P.S. Several hyperlinks removed for lack of reputation. Drat! ;-)

+1  A: 

I'm not quite as qualified as I'm sure some answerers will be. I have used Haskell, Scheme, and XSLT, though I learned them in the opposite order -- Scheme, then Haskell, and then using XSLT for basic stuff. I found that the thinking processes I learned using Scheme and later Haskell definitely helped me understand the high level concepts of XSLT programming. All the details, of course, still had to be dredged from reference guides and such.

I imagine that you'll find the same effect in reverse.

(I also found that XSLT, like other programming-languages-in-XML, is a painful way to process an XML file, and that just writing a script in Python was easier, faster, and more flexible).

Scott Stafford
+4  A: 

I have played around a little with XSLT, and have delved deeper into the functional languages Lisp, Scheme, and Haskell. From what little I've seen, I'm not sure that XSLT as it's commonly used will teach you that much about functional languages. You may learn a few tricks, but in my opinion, JavaScript is a better analogue to what you'll see in untyped functional languages.

Wikipedia backs me up on this one:

As a language, XSLT is influenced by functional languages, and by text-based pattern matching languages like SNOBOL and awk. Its most direct predecessor was ISO DSSSL, a language that performed the same function for full SGML that XSLT performs for XML. Many of the standards committee that developed XSLT had previously worked on DSSSL, including James Clark. XSLT can also be considered Turing-complete template processor.

In other words, it borrows a lot from functional languages, but also borrows from templating languages like awk and SGML. So yes, it's a functional language, in the same not-entirely-obvious way that C++ templates are a functional language. But there's no easily-mapped line from learning XSLT to Scheme or Haskell.

Also, don't underestimate how different functional languages can be from each other. Lisp and Scheme are both so loosely typed as to feel essentially typeless. I think of these languages as being like the Mandarin Chinese of programming languages, with an essentially fluid, context-based syntax. Haskell, on the other hand, is so strongly typed that it confuses even experienced programmers. It also reaches beyond its lambda-calculus roots to borrow concepts from abstract algebra and Category theory, making it a bit mind-boggling to learn for non-math types.

But none of this is meant to discourage you. By all means, learn a functional language. They will change your approach to programming in ways you'd never suspect.

rtperson
+4  A: 
Norman Ramsey
+1  A: 

I believe XSLT is in fact a good first pure functional language: http://blogs.msdn.com/ashleyf/archive/2007/04/11/xslt-a-pure-functional-language.aspx

Robert Hedrick
The linked article explains it well in few words. Thanks.
Mark Jerde