Programming Erlang 314
gnalre writes "Every day it seems there is a new publication of a book on perl/python/ruby. Some languages however do not seem to get that sort of attention. One of those under-represented languages is Erlang, however for the first time in 10 years a new Erlang book has been published. As someone who had a brief flirtation with Erlang long ago, I was interested to see how the language had evolved in the intervening decade. I was also curious to re-evaluate Erlang to see what solutions it offered to the present day issues of writing reliable distributed applications." Read on for the rest of Tony's review.
Programming Erlang - Software For A Concurrent World | |
author | Joe Armstrong |
pages | 515 |
publisher | The Pragmatic Programmers |
rating | 8/10 |
reviewer | Tony Pedley |
ISBN | 1-9343560-0-X |
summary | Parallel programming the easy way |
Programming Erlang — Software For A Concurrent World (ISBN 10193435600X) is part of the pragmatic programmer series. As with all the books in this series, it is available in paperback or for a reduced cost you can directly download it in PDF format (which is always useful if you spend a lot of time on the move and you do not like carrying around a dead tree with you). The book's format and layout as with all the books of this series are clear and logical.
The book is written by Joe Armstrong, who co-authored the first Erlang book a decade ago. He was also one of the originators of the Erlang language and has been directly connected to its development ever since. We can therefore be assured about the author's knowledge and insight into the language, if not his impartiality.
The book itself can be roughly split into three main sections: Getting started and Sequential programming, Concurrent Programming and Erlang libraries and advanced Erlang techniques.
In Chapter 1 the author sets out his stall of why Erlang is worthy of your attention. It's clear from this chapter that the author feels Erlang's strength lies in applications requiring an element concurrency and fault tolerance. Another emphasis is made of running Erlang on modern multi-core processors, something that was only a glint in a hardware designer's eye 10 years ago, but is rapidly becoming an issue in all areas of programming. From this chapter you also get a feel on how the author approaches his programming in that he states that he wants the reader to have fun with the language, which is a refreshing change to some language text books whose main purpose appears to be as a cure for insomnia.
Chapter 2 goes through installing Erlang and the Erlang shell (a command line environment similar to ones with languages such as perl). The chapter also starts us into the strange world of functional programming, where variables can only be given a value once (e.g you cannot do i=i+1), recursion replace loops and pattern matching replaces assignments. Fortunately the Erlang language is remarkably concise. For example there are only 4 data types. However to those coming from a purely procedural programming background the learning curve could be a steep one. Saying that the Author does a good job of leading you through the languages intricacies with examples being compared to code from languages such as Java to help keep your feet on solid programming ground.
The next 3 chapters move on to writing simple Erlang programs. As a quick aside, for anyone new to Erlang it is well worth examining the quicksort implementation described in chapter 3. Its conciseness and simplicity was one of the reasons the language won me over when I first met the language.
These chapters also cover error detection and handling. It's worth noting that Erlang has a philosophy of ensuring programs fail hard, so that bugs can be weeded out at an early stage. This idea very much defines how Erlang error handling is defined.
One criticism of the first section is Chapter 6, which describes compiling and running an Erlang program. I would have preferred that this information be covered earlier in the book or be placed in an appendix because it is probably an area you will want to reference repeatedly.
Chapter 7 is where things really get interesting and the true power of Erlang starts to come to the fore. This is where Erlang's concurrency credentials are explained. This chapter begins by providing some useful metaphors of the Erlang concurrent model, but chapter 8 is where the fun begins by describing the Erlang concurrency primitives that allow the creation of processes and the process communication methods. The author here highlights one of the language features, the Erlang light weight process. These are true processes (not threads) but take up very little in the way of resources. Indeed it is not unusual to have 1000's of such processes running in an application.
The next few chapters expand on the available concurrency primitives and how to move from concurrency on your local processor to concurrency utilizing the resources of multiple machines either on a local network or across the web. It finishes the section off by showing the example of a simple IRC application.
Chapter 12 starts the next section by looking at how to interact with the world outside the Erlang environment. First it examines how to interface an Erlang program to applications written in other languages such as C. It then goes onto to look at file and socket handling in Erlang. Chapter 15 looks at two important Erlang storage primitives ETS and DETS before we get to the OTP Erlang libraries in Chapter 16.
The OTP libraries are the standard Erlang libraries and tools. In fact the OTP libraries are worthy of a book in itself. The author highlights the section on the generic Server module as the most important section in the whole book and one to be reread until its importance has sunk in. This is because here are encapsulated many of the lessons learned in writing industrial fault-tolerant applications, such the updating of a running applications code without causing that application to miss a beat. The section is finished off by describing the Erlang distributed database (humorously named Mnesia) and then finishing it off with the example of a simple server application.
The book finishes off by looking at Erlang on multicore systems including its support for SMP. As the author states this is the leading edge of present day Erlang and is still under development.
I would like to thank the pragmatic programmers for publishing this book. Erlang's profile has been in need of highlighting for many years and hopefully this book will help. The book definitely provides a great starting point for anyone who wants to get to grips with the language and takes them to the point where they can start writing useful applications. This book is a worthy successor to the last book published and does a good job of both updating the material and explaining some of the later developments such as SMP. Anyone who has a need for writing fault tolerant applications should at least look at this book. If nothing else you will never be afraid of dealing with recursion ever again.
In many ways the book cuts off just when things are getting interesting. There are hints in the book about real world Erlang's applications and it would have been good if some of these experiences could have been expanded. Hopefully this book is the start of increased exposure for Erlang. If so then someone may get around to writing another Erlang book describing some of the advanced issues about generating robust applications. I just hope it won't take another 10 years this time.
Tony Pedley is a senior engineer specializing in real-time embedded systems. In his spare time he likes to tease windows programmers and confuse managers by telling them it would be a lot easier if we wrote it in Erlang.
You can purchase Programming Erlang - Software For A Concurrent World from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Try it out (Score:5, Informative)
apropos erlang (Go Sweden!) (Score:3, Informative)
Re: (Score:2)
Re: (Score:3, Insightful)
And yeah it's like Prolog, except without horn clauses or backtracking. You know, just like lisp and java.
Re: (Score:3, Interesting)
Re: (Score:3, Informative)
Re: (Score:2)
Re: (Score:2)
First: I was completely wrong, Erlang is not a logical language. Prolog is.
Second: Really? How about this example (Prolog pseudo-code, inc() and dec() increase/decrease a positive integer by one):
Re: (Score:3, Informative)
This is quite bad Prolog. Try this instead:
Where s/1 is a successor operator, which may or may not be defined, depending on how you wish to represent numbers. Your second case is not required, although it can be used for a tiny speed boost. If you want to take this to its logical conclusion, then you can assert/1 each result that you've already unified with true. This technique is more useful in something like a Fibonacci sequence, however.
Re: (Score:2)
Re: (Score:2)
It's called static single assignment form [wikipedia.org]. It's arguable whether requiring the programmer to write in this formal style is better than letting the compiler convert the code though -- sort of like the holy war over manifest versus inferred types.
Re: (Score:2)
the bizarre contortions required to get between an object and its fields at runtime (in SXM's case, wrapping all fields in properties and using a runtime-generated subclass that overrides the setters and getters to monitor the transaction) feel more unnatural to me than SSA form.
Isn't that roughly what Ruby does, invoking an implicit accessor function if one hasn't been explicitly supplied? And I know that some commercial Java products use reflection and bytecode injectors to intercept attribute accesses, which requires no (manual) modification of the baseline code.
I'm not familiar with SXM, but based on what I've seen elsewhere it doesn't sound like it uses a terribly unworkable approach. That said, I have more of a desire to play with Erlang than SXM or other transactional mem
Re: (Score:2)
Assuming that Java/C# are the last word in programming language behavior is simply foolish. Sure, they're popular today. Sure, people will still be using them in 30 years (in the same way that people are still using Cobol today). But they'll get replaced just like
Re: (Score:2)
I didn't assume they're the last word, Erlang isn't either though. I said they're used a lot and we're stuck with them.
The deduction that they'll be replaced like anything before them isn't good though: computer technology was young before. Now it costs millions to port the vast amount of code written and interconnected with other code, to something else.
There are companies still out there
Re: (Score:2)
It's natural that software maintenance will never be in new languages. That doesn't prevent new projects, or even new components in existing projects, from being written in those new languages. One thing that's happened that's very interesting is systems like .NET being designed to support the easy intermingl
Re: (Score:3, Interesting)
You are right on reasonably short time scales (a year or two) at a single organization. O
Re: (Score:2, Insightful)
It's a bit rude to the authors and publishers to post copyrighted material on the Internet without their permission. The last I checked, the Pragmatic Bookshelf e-books used no DRM, so it's not like they're treating legitimate customers poorly either.
Re:Try it out (Score:5, Funny)
And, as I'm told, earn top dollar from merchandise like t-shirts, mouse pads and coffee mugs.
Great book creation process (Score:4, Informative)
I haven't had much time to play with Erlang (or the book) yet, but it was a really nice feeling to be able to get early access as long as I was willing to see unpolished content. Bravo, publisher.
What's missing from Erlang... (Score:5, Interesting)
The design issue, for me, was a lack of namespaces. I think it might have been that I can't have an atom with a namespace, beyond prefixing, which is a hack for languages that don't support namespaces.
The implementation issue was that you had to choose between performance and being able to reload functions later. I would very much like it to be able to JIT or even compile down to binary (x86_64 too, pretty please?), then be able to just leave it running, and have it reload functions as needed.
I'll have to think of what else I didn't like, but I don't think there was much, aside from some odd syntax. I don't actually have a problem with the somewhat functional nature of it, just certain syntax that looks ugly, but that's a matter of opinion, and something I can live with.
Re: (Score:3, Informative)
You can use periods and @s (and anything else) to namespace atoms, if you want. The module loader will even track down module foo.bar to foo/bar.beam... compiler support for it isn't great but it works. nobody bothers to use it though.
The syntax takes a while to get used to, but it becomes very easy to write.
What I've found
Re: (Score:2)
Atoms. They're used for some things I might use constants for in another language, I think. I'll have to get back to you with some code examples.
HIPE is sort of what I was looking for -- I remember BEAM being bad. But I still don't see whether I can dynamically reload HIPE the way I can dynamically reload straight-interpreted stuff.
As for performance, well, it'll at least thread, without you havi
Re:What's missing from Erlang... (Score:5, Informative)
There's basically a handful of languages that would meet your needs here. On the dynamic side, you've got Common Lisp. On the static side, you've got ML, O'Caml, or Haskell.
After that, your options trail-off significantly. The other dynamic languages are all much slower than Lisp (more in the league of Python than in the league of C), and the other static languages (C#, Java), are much lower-level/less productive.
Lisp, you say? (Score:2)
What are the options for compilation? Anything beyond simply distributing source code?
Re: (Score:2)
Re: (Score:2)
Some suggestions: If you're already an Emacs maven, SLIME is a good idea. If you're not, LispWorks has a free demo with IDE that's quite nice. If you're on Windows, Google "Lisp
Re: (Score:3, Interesting)
- Common Lisp was designed with a strong bent towards practical utility. It has a lot of features* and features that aren't necessarily clean**, but are included because of usefulness or backwards compatibility reasons. Scheme was designed first and foremost to be a very clean, pure language. It's easy to learn, and you can hold the whole thing in your head without much effort
Re: (Score:2)
Why does it matter if you use the same atom for different things in different places? Would namespaces for atoms even make sense? This seems like a case where you're thinking of them as "replacing constants" rather than "being atoms".
Re: (Score:3, Informative)
I'm considering Erlang for a project, so I honestly would appreciate knowing how this might be problematic.
Possibly the greatest programming book I've read (Score:5, Insightful)
All in all this is an excellent book about an excellent language and I would highly recommend it to any programmer, especially those concerned with the multicore future which will increasingly demand concurrent programming languages.
Re:Possibly the greatest programming book I've rea (Score:4, Interesting)
Re:Possibly the greatest programming book I've rea (Score:3, Insightful)
I'm still struggling, but I read the book with an application in mind, and have found its coverage is excellent... it brings you right up to the point that is needed for the other erlang documentation to be readable. (There are 60 some odd books on all the major components of erlang
Wings3D (Score:4, Informative)
It's an open-source subdivision surface modeler held to great esteem in the modeling scene
It is also an Erlang application....
Re: (Score:3, Interesting)
Review worth a +1 karma! (Score:5, Informative)
And in my opinion; If you are familiar with more common languages like C and Java you should take a deeper look into Erlang unless you prefer to study Prolog or Cobol. Just take a dip or a deep plunge, you never know when you end up in a project where knowing Erlang may prove useful - it is actually developed to be used in real applications and not as a theoretical study object.
And Erlang is designed to handle concurrent programming from the bottom, which is a real problem in large multi-user systems. You can of course use C or Java and solve concurrency problems with semaphores or synchronization, but the solution in Erlang may be much more elegant.
And for all of you that are familiar with the Eclipse development environment; There is a plugin called Erlide [sourceforge.net].
Re: (Score:2)
Huh? (Score:2)
I bought the book early in PDF form (Score:2)
I have been disappointed that none of my customers seem to be interested in Erlang development - I proposed using it for one application where 'share nothing' asynchronous communication seemed like a very good fit.
OOP to Erlang (Score:2)
Would a good analogy be that an Erlang process is comparable to an object instance, in that both are loosely coupled (ideally), focused on one task (ideally), but in Erlang they're all running asynchronously and the OS/runtime automatically handl
Re: (Score:3)
Needs more on common libraries (Score:2)
Yes, I do know about the Ericsson Mnesia manual and http://trapexit.org/ [trapexit.org]
Vik
ejabberd is written in Erlang (Score:2)
It's worth noting that ejabberd [jabber.ru] is written in Erlang.
For those who haven't heard about it, it's an open source, distributed, fault-tolerant instant messaging server (Jabber/XMPP), modular and very configurable and is readily available in most Linux distributions' repositories.
It's one of the most promiment erlang-based projects.
Check it out at the shootout (Score:2)
http://shootout.alioth.debian.org/gp4/benchmark.p
for the general performance of erlang. It compares unfavorably in those tests to lisp and clean, two other functional programming languages.
Full-time Erlang programmer gives his view :] (Score:2, Informative)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
What sort of uses of "for" did you have in mind, though? Erlang provides lists:foreach and lists:map in the standard library, which covers many typical uses of "for" in other languages.
CouchDB was written in Erlang (Score:2)
classic papers (Score:2, Informative)
http://www.math.chalmers.se/~rjmh/Papers/whyfp.htm l [chalmers.se]
Also, John Backus' Turing Aware lecture, "Can Programming Be Liberated from the Von Neumann Style?"
http://www.stanford.edu/class/cs242/readings/backu s.pdf [stanford.edu]
Perfect timing! Meet Nick. (Score:2)
An article on functional programming is the perfect time to introduce my new son, Nick, to Slashdot. Previous releases were in C [slashdot.org], Perl, and Python [python.org]. Since Nick's functional, this one [honeypot.net] is in Lisp.
Mod me up or my son will spit up on you.
IAAEP (Score:4, Insightful)
I am (well, was, at least) an Erlang Programmer. I was toying around with Erlang for some small projects [sf.net] with distributed programming.
I've been looking forward to Joe's book for a long time, as he's one of the few big names in the Erlang community, and has done a lot of work (both code and, even more importantly, documentation) for the community -- first that jumps to mind is his important look at Yaws vs. apache [www.sics.se].
There are serious problems with the Erlang language as a whole and the community, right now. The mailing lists are actually pretty good, but quite frankly, the documentation online is terrible and the Erlang interpreter is pretty rudimentary. Not to mention basic problems with the syntax and grammar of the Erlang language itself. When I was learning Erlang a few months back, I was pretty frustrated that about the only source of documentation was on erlang.org [erlang.org], and they.. weren't great. For instance, there needs to be a big warning right at the beginning explaining that atomic values always start with a lowercase letter and all other variables must begin with a capital letter. This must be a huge problem for other beginners (at least, I hope I assume I wasn't alone..) compounded by the unfriendliness of the error messages produced by the Erlang interpreter.
Now that I've switched over to doing as much as I can in Python, which has a great user community, wonderful docs, a healthy standard library, and a reasonably helpful interpreter.. I don't really worry about Erlang that much anymore. It would be wonderful if I could write, say, web crawlers (I work in web security) in Erlang. But the mysql support in Erlang looks alpha-quality at best, and AFAIK there's nothing even remotely similar to Python's urllib2 for basic web client functionality in Erlang.
I think it says a lot that so much attention is paid to a language that is so rough around the edges, unfriendly, and lacking in documentation. Even given all that.. the ease of use of the concurrency and message passing in Erlang is so fantastic that it almost makes up for the rough spots.
On a final note, I'd like to point out to anyone interested that I think there's a huge void out there for a language that's as easy to use and learn as Python, but with the concurrency and message passing in Erlang. It actually might not take that much work to build a network-transparent message passing interface as a Python module (I've looked into Pyro [sourceforge.net] a bit.. it looks rather cumbersome and makes easy things too hard, correct me if I'm wrong). Also, modern languages need basic support for splitting up the workloads of map() or similar trivially parallelizable functions across multiple processors/cores (I know the Perl6 group was thinking about this.. not sure if this works in Parrot now or what). Basically, modern languages like Python/Perl/Ruby should really think more about making simple modules to mimic the message passing that Erlang has. Really, a little bit of code could go a long way. The Google team put together sawzall [google.com] which looks kind of cool, on this note..
Re: (Score:2)
Re: (Score:3, Informative)
http://en.wikipedia.org/wiki/Erlang_programming_l
Re:The Seven Deadly Sins of Erlang (Score:4, Insightful)
1. Not a sin, not needed and shows you don't know what you're talking about wrt reliability. hard real time is irrelevant.
2. More FUD based on your lack of understanding of programming.
3. is a downright lie
4. Contradicts three!
5. Ok, now I'm thinking you're not just a troll but verifiably insane. Show us a language (one that exists outside your head) thats not "alkorithmic"
6. Contradicts itself- is it based on english or is it cryptic?
7. Asinine in the extreme, and of course contradicted by the other 6 points. erlang is not logo
Bottom line- you are just making assertions that make no sense. If you ever were a programmer, you never learned much about programming... and your constant bashing of erlang is just an attempt to get attention. COSA doesn't exist, except in your head, where it can be magical and change as is needed for you to make whatever "point" you want to make.
I guess its a sign that erlang is becomming mainstream that it has attracted a loon such as yourself.
Re: (Score:3, Interesting)
Re:The Seven Deadly Sins of Erlang (Score:5, Insightful)
Re:The Seven Deadly Sins of Erlang (Score:4, Insightful)
Re: (Score:3, Informative)
Postblablurb (Score:2)
Re: (Score:2)
But the Postmodernism Generator makes more sense than the Loon.
Re: (Score:2)
The blog you link (especially the authors reactions to criticism in the comments) show that he should really have been aborted when it was still possible.
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:3, Funny)
Please do continue posting as it's endlessly amusing, people like you are like digital clowns. After all every society needs a town idiot to make everyone else feel better about themselves.
Re:The Seven Deadly Sins of Erlang (Score:5, Insightful)
See, here's the thing: I can download Erlang and start to learn it right now. Where can I find COSA? That's right, it's vaporware.
Who knows, you may be on to something. I'd suggest writing fewer white papers and less name-calling of your detractors and get busy implementing your vision. Nothing will shut them up faster when you've got something that lets people develop systems that are more reliable for no extra cost.
Until then, you're in the same category as people who promise us perpetual motion machines and anti-gravity levitation.
Re: (Score:2)
Re: (Score:2)
Yes, that's right. I'm completely fanatical for a language I've never used. I'm rolling my eyes now... just in case the sarcasm went totally over your head.
Why do I have to fork up the money? You're the one with the extraordinary claims of dramatic reliability increases. If you're so much more brilliant than the rest of us, it shouldn't be terribly difficult for you to at least create something a little more sophisticated than something that looks like an OmniGraffle demo on stupid pills [sundman.infa.fi] in a few week
Re: (Score:3, Funny)
Or would be if it... you know, existed.
lol
I'm sure you're taking the Internet crank world by storm. Best of luck to you.
Re: (Score:2)
"Kurt Gödel (how could I forget him?) is one of the gods of the voodoo science pantheon. Gödel is certainly the most often quoted yet inconsequential mathematician of the world. He is known for his incompleteness theorem, the most non-scientific, chicken-feather-voodoo nonsense ever penned by a member of the human species. In 1949, Gödel announced to the world that Einstein's general theory of relativity allows time travel to
Re: (Score:2)
Did you know that Erlang cannot do fine-grain parallelism? That's right. There is no parallel quicksort algorithm in Erlang
That's very interesting, considering that when I gave a talk on Erlang a year ago one of the examples I gave was parallel quicksort. It fitted nicely on a single slide at a size big enough for everyone in the room to be able to read.
Oh, and in reply to your other comment about the amount of backing that Erlang had; the first version was written in Prolog in a week by two guys. It wasn't fast, but it was a good enough prototype to persuade people to invest in developing the full version. If you're loo
Re: (Score:2)
Talk's cheap why don't you just upload an implementation your quaint little language to a server and show us your parallel quicksort algorithm.
Re: (Score:3, Informative)
Re: (Score:2)
Its surely a dumb idea for applications written in languages like C and Java... but not for erlang.
Remember, systems running this language have had uptime on the order of many years, and that's with in-place code modification.
You're rejecting what you don't understand based on assumptions that are true for other contexts.
Downtime is a sin, not a virtue!
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Obviously you "modify on the fly" your test server first, and then once you've tested it (as usual), you "modify on the fly" your production server. I fail to see the problem here.
Re: (Score:3, Informative)
AT&T uses Lisp for some of their call routing equipment for the same reason. If you need to add a new feature to a switch, you cannot drop the call's it's handling to swap out the software.
There are also lot's of us
Re: (Score:2)
Re: (Score:2)
In fact, the company that I work for has done exactly this for C/C++ apps on four different hardware architectures. (There are restrictions....its basically impossible to modify an inline function, for instance.)
Re: (Score:2)
So while it may work for some special cases, I am saying it is just a bad idea to do deployments like this as a principle, you can't be sure what is running in production at some point.
Re: (Score:2)
4. Profit from selling Erland as another silver bullet that will save the day.
Re: (Score:2)
Re: (Score:2)
IF you consider yourself a serious programmer, you would do well to go download the free chapters of this book from the pragmatic programmers site and read up a bit.
I too had an advers reaction after 20 years of OO programming.... but I stuck with it and now I see the light.
Its worth the effort.
Re:I know why it's been 10 years (Score:5, Insightful)
There is nothing in the second example that isn't completely familiar to anyone who has ever programmed in LISP, one the world's oldest programming languages.
Newbies, feh!
Re: (Score:3, Informative)
You're computing a list, target, where each item is computed by F(G(x)), where x is an item from source_list, taken in order.
Note that stuff like "iterating over source_list", and "appending to target" are not really important. They are certain necessary steps in one possible implementation of what you're trying to accomplish, but they're just incidental --- they're not part of the end result.
Now, ma
Re: (Score:3, Informative)
At this point, I don't even understand what situations this could be usefully applied to.
Well, functional programs have a lot of other restrictions, but it boils down to this: with very rare exceptions (such as file or socket handling), functions don't have side effects. That is, they don't modify a program's global state, and they don't depend on global state. You can call foo(args) 100 times in a row and each time the output will be identical. My C++ is rusty, but imagine something like:
Any code that calls foo() will find i
Have you ever written a loop? (Score:4, Informative)
It's very different, but the big advantage is that it's higher level than the stuff you confess to understanding better.
The code in question (in Python? not a great choice for doing an example!) uses two very common higher-order operations in functional programming: map and compose. A map operation takes a complex data structure (most common example: a list), and a function that applies to elements of that data structure, and returns another structure, with the same "shape," where each element in the result is related to its corresponding element in the original structure by being the result of apply the function. Thus, if you have a list [2, 3, 5, 7], and a function inc that increments a number by one, map(inc, [2, 3, 5, 7]) evaluates to [3, 4, 6, 8].
In the case of a list, map is can be implemented by creating a new list of the same length as the original, looping over the list, applying the function to each value, and storing the result in the result list. This is a kind of task that imperative programmers find themselves doing all the time. The problem with this, however, is that if you're writing code like this all the time, you're writing at a much too low level, with the all the disadvantages of that:
Re: (Score:3, Interesting)
target = map (f . g) source_list
A minor shift in syntax, and dropping a lot of superfluous parentheses from the language and adding sugar (.) for function composition goes a long way to cleaning that up into something readable. =)
The main strengths of functional programming come when you start thinking about functions as first class values.
Here the function obtained by composing f and g became a new function that was usable just like the primitives you built
Re: (Score:2)
Reformulating in Ruby (a more neutral language), we get:
result = []
for item in source
te
Re: (Score:2)
result = map (\item -> f (g item)) source
Or, more idiomatically:
result = map (\item -> f $ g item) source
Re: (Score:2)
Re: (Score:2)
Re: (Score:3, Insightful)
Re: (Score:3, Insightful)
It's not a problem, because no functional programming language has a buggy map. There is no need to debug into map, it's a primitive like floating-point addition (which actually abstracts a much more complex algorithm than map!)
Re:I know why it's been 10 years (Score:5, Insightful)
Uh, if you don't know functional programming, then yeah. If you do, it's instant to understand, and can be maintained more easily because there is less of it to maintain.
Your argument basically amounts to "stuff I don't know is hard to understand". No shit. New notation and concepts have to be learned, yes, but there is a point to learning them. It makes things simpler and easier once you have learned them. Consider, why do people in signal processing do all sorts of Z transforms and Fourier transforms and whatnot on data? Surely it's _easier_ to just think of a sound signal as a series of amplitudes at discrete time intervals? The thing is --- it isn't. Once you learn all that math, you can do stuff with signals by hand that you couldn't even have dreamed off if you'd used a less powerful technique.
Re: (Score:2)
Re: (Score:3, Informative)