Although in previous posts I talked about the Raspberry Pi and Erlang together, and even though I have been using the RBP as a platform for learning Erlang, this post does not really related to the RBP at all.
I’ve been working my way through Learn You Some Erlang… and I finally got to the chapter on Concurrency. It was great. There are only three things to remember:
- The spawn() function takes as a parameter a function and runs it as a new process
- The ‘!‘, (i.e. bang symbol) operator is used to send messages to processes.
- The ‘receive‘ statement inside a process receives messages sent to the process.
I remember thinking. That’s it? That’s all I need to know? This is going to be easy. My mind fairly danced with possibilities. All of the processes I was going to create. All of the messages I was going to send (and receive).
Ah but then I read on…
Processes may need to hold a state, and recursively call themselves to keep running. What if you don’t want to wait forever for a message that might never come, better implement a timeout. What if another process sent you a high priority message? Shouldn’t your process receive that one first? Make sure to hide creating and sending a message inside a function. Wouldn’t want to expose a developer to that ugly syntax. Maybe you should link dependent processes. If one dies you want the other one to die to, don’t you? Hey, wait! You can’t just kill a bunch of processes without telling anybody, throw a monitor in there for good measure. Aren’t PIDs clunky? Why don’t you give your process a nice name. What about errors?
Yes, I still have much to learn about implementing concurrency in an acceptably Erlang fashion. I’m going to hold off on creating a clouds of processes and webs of messages for a bit, and dive into the chapter on the Open Telecom Platform, otherwise known as OTP. I can’t wait. Really.
This brought to mind the book: Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages. Which I confess, I never have read. Is it really worth studying a programming language for only a week? Does that make any sense? I can’t believe that’s enough time to become proficient enough to contribute in a production environment. I suppose if you were hunting for a new PL to learn, that might make some sense, but I don’t think you would you spend a week on each one before deciding.
Why do we learn new PL’s anyway? I would guess, that for the vast majority of developers it is required. In school, it is assigned as part of the class (A little pun. Very little). In the working world, in exchange for receiving a paycheck you must develop software in the language chosen by your employer. I think fewer would learn a new PL, not because they have to, but as a stepping stone or gateway to a new job or even a new career. Then there is (Again just my opinion here.) an even fewer number that learn a new PL out of sheer curiosity, not because they have to. Finally, just for completeness there are the handful of smart brave souls that create a whole new language, that never existed before. But even then, I doubt if a solo developer could develop a new language that survived in the wild, without some help, and then the circle is complete, as companies hire and compensate employees to support and develop the new PL.
I think back on all of the PLs I have learned to various degrees of proficiency in my own career: Assembly, C, SQL, PL-SQL, C++, C#, Java, OpenSpan, Apex. All because I had to. Not that I don’t enjoy learning new things, but I’m learning Erlang now, because I want to.
How about you? Have you ever become proficient in a PL, not because you had to, or for a paycheck, but just because you wanted to?