4 ms·
Are you sure it isn't the functional paradigm of the language that is frustrating you? That is usually the hurdle for people and not the syntax in my experience
by Ixiaus 16y ago
Are you sure it isn't the functional paradigm of the language that is frustrating you? That is usually the hurdle for people and not the syntax in my experience - I luckily had quite a bit of experience with Scheme and Haskell so recursion and pattern matching weren't alien to me at all - the idea of taking the car of a list (or head in Erlang) and recursing on the cdr (or tail in Erlang) can be pretty mind boggling for new comers.
The syntax is actually pretty friendly IMHO - it's specifically meant to be as side-effect free as possible.
Keep plugging at it (like many things) and it will grow on you.
- SkyMarshal 16y agoIt sounds like it's more the syntax is the problem, but if it is indeed that kind of recursion OP is having trouble with, might I recommend The Little Schemer. Amazing short little book with a unique Socratic teaching style that specifically teaches recursing on the cdr of a list. They tried to teach us recursion in college using C, and I remember it just confusing me. Learning it in Scheme with TLS, it clicked immediately, and now I can implement it in any language.
- Lewisham 16y agoYeah, it's syntax for me. It's not functional programming (I do OK with Haskell), it's just this feeling like everything in the syntax looks like a hack. I can't seem to see the underlying consistency (if there is any). I generally feel completely lost when reading or writing Erlang; there's never been a point where I feel like I truly understand what's going on in the code, it's like I've just had some happy accident that seems to be performing the way I had hoped. I'm fairly intimidated to try doing anything bar what I'm told in the tutorials, and I've been plugging away for a fair while now.
- Ixiaus 16y agoThen my suggestion would be to tackle a real problem. It took me a while to know when Erlang was appropriate for what I as trying to tackle. About a year ago, I came across the need to regularly scrape websites from a list (pulled from a mysql DB) and get some very specific information from them (regex worked fine). I first did it in Python (non-threaded) and for like five urls in the list it was acceptable. Then the list started growing and the system started bogging down a lot. I then thought to myself, "okay, well I should thread the python script then..." and that's when another thought kind of barged in and said, "uhm...Erlang would be perfect for this..." So I implemented it in Erlang - it was the perfect first production Erlang program. I only had to do three things: 1. Query the DB and get the current list of URL's 2. Scrape the URL 3. Run my regex on the result and insert something in the DB So, I did it non-parallel style first to get a grip. Worked great. Now how do I go and make this a parallel program? Two major issues presented themselves: A) I want to (basically) map() the list of URL's from the DB and spawn a process per item in the list that handles the scraping and regexing of the item's URL. This was difficult for me but Armstrong's pmap examples in Programming Erlang helped a lot. B) Handle proper locking with the DB. It was immediately apparent to me that doing DB calls from inside the spawn'ed proc was probably stupid and hard. So I decided the spawn'ed proc would only do the work of requesting the site and regexing the result - it then had to pass the result as a message back to a delegator (that handled all communication between the spawn'ed procs and the parent program) which would aggregate the results and insert into the DB once all of them had finished/failed. So the pmap implementation not only had to split the list and pmap() on each item of the list, but had to also aggregate the results &c... It was complicated but so complicated I couldn't handle it. The whole thing took me about five days but holy god was it fast! I finally grok'ed Erlang too - I known now how amazing it is for programs that truly require parallel execution models and I also know how unproductive I would be trying to bend it to any project that didn't explicitly need that kind of paradigm. [EDIT] It was complicated for me because I didn't want to just pmap() down the entire list, I wanted to only pmap() on a set of 10. So the list had to be split into ten, map the items, then break off another 10 &c... The syntax is very familiar to me now after having written several other large production programs that we use (I can "read" Erlang) and it feels perfect for what Erlang is meant to do. I can't really imagine doing the same kind of thing so expressively in Python.