Tuesday, August 20, 2013

Learn You Some Erlang for Great Good! (a review)

Learn You Some Erlang for Great Good! (LYSE) is one of the best books to learn about the programming language and the system Erlang/OTP. This article includes a brief review about LYSE of No Starch Press version, my impression about the author Fred Hébert (Fred), and related miscellaneous things.

Fred is a young person. I assume he was born in the late 1980s. That itself makes LYSE extraordinary. The writing style of LYSE is purely casual and conversational; it's quite different from other Erlang classics, such as Joe Armstrong's Programming Erlang (I'm eagerly waiting for the Second Edition!) and Erlang Programming of Francesco Cesarini and Simon Thompson (I'm also eagerly waiting for a new book from the authors with Robert Virding this time!), let alone the first book of Erlang called Concurrent Programming in Erlang published in the 1990s. Those classic books are written by much older people, and they follow the traditional textbook format. LYSE does not. You will also be surprised by the illustrations drawn by Fred. Those drawings are so creative that I've even got distracted with them while reading the otherwise very technical and detailed contents. Maybe I've got too old. Nevertheless, you need to know LYSE is not an ordinary textbook.

I've seen no book on Erlang about the complete coverage of the language and the OTP library other than the online manual at erlang.org and the source code repository at GitHub. LYSE is not a manual either; it is rather a collection of live stories and practical examples of Erlang based on the hard-earned experience of Fred himself. It's written for those who actually write the code, develop the packages, and release the products. For those who want to study from the very beginning, I recommend Simon St. Laurent's Introducing Erlang.

I will avoid digging into explaining the whole contents of LYSE, because the explanation will take the same amount of words the book has. LYSE is a thick book which has approximately 600 pages, so it's not something for an easy reading. I have to confess there are many things I didn't know and I haven't tested yet in the book. The book hyper-comprehensively covers the necessary topics for dealing with the day-to-day tasks on Erlang/OTP development, from the language basics to gen_server, (the rage against the) finite state machines, package release, Mnesia and the OTP internal database modules, and a proposal of how to read all the Erlang punctuations in English.

In LYSE, the semantic details of the language and system elements of Erlang/OTP are meticulously well-written. One of the most impressive contents is about the intentional avoidance of tail-call optimization in the try-catch exception handling; Fred simply writes:

The protected part of an exception can't be tail recursive.
(Chapter 7, “Protecting The Right Thing")

I will not explain the reason here, but this sort of caremad attitude in the details makes LYSE a professional handbook, if not a textbook (and it is not, I repeat.)

Fred is a very talkative and energetic person. I really admire the level of his English fluency especially when he makes a thunderstorm-like (real) lightning talk. He is also helpful and has assisted a lot of newcomers as his erlang-questions mailing list articles show. The book represents his personality very well. If you are an experienced programmer, LYSE is also an interesting book as a general reading, because the book will remind you of how you have been self-teaching yourself.

I recommend LYSE to all those who want to learn Erlang and OTP, especially to those who want to experiment and self-learn the language and system. If you want to know the contents first, check out the free online version.

Appendix: about the book title

When I saw the title of LYSE first time, and when I saw the title of the cousin book of LYSE about Haskell called Learn You a Haskell for Great Good! (LYAH), I thought there was something severely wrong with the grammar, even from a speaker of English as a second language. I've learned at school that the verb learn will not take a person as the object, and so does my New Oxford American Dictionary built into OS X say. I had a hard time to explain the meaning of this sentence to some Japanese experts who are not familiar with this type of non-standard English sentence. And I have to confess the phrase “Great Good” looked non-standard to me too.

On the other hand, the title of LYSE looks much more understandable to me if I see it as a literal translation of a non-English Indo-European language. Fred is a proud francophone Quebecker, and he is also an excellent English speaker and writer. I can imagine Fred reads and understands the title of LYSE in a complete different manner than I do. So I will complain no more about the title of LYSE or LYAH.


I've been sent a review copy of LYSE from No Starch Press on January 2013. In this article I mostly refer to the No Starch Press version, though I also have read the online free version. Note well: I have ordered and purchased my own copy of LYSE from No Starch by myself before receiving the review copy!

I should also note that I've met Fred at least three times at Erlang Factory SF Bay Area 2011, 2012, and 2013, so this review may be heavily biased. (I hope this review is not too late, Fred!)


Thanks to Jessica Miller of No Starch Press for sending me a copy of LYSE and helping me about what to do with the 600 pages of paper :)

Wednesday, August 7, 2013

AM Radio: No Longer Practical?

Noise from modern electronic devices are killing the media

This is a popular article among my pieces of writing at Medium.com.

(Photo by Patrick Fitzgerald/Barelyfitz)

History tells the pollution has been the repeating problem which the civilization must solve. The radio airwaves are getting polluted too. I fear that AM radio broadcast will no longer be practical if modern electronic devices with the switching power supplies and computers become ubiquitous and necessary to maintain our lifestyle. Conversion or migration from AM to the FM radio will be an easiest way to solve this problem, at least for the dense population areas.

I’ve been struggling to listen to the AM radio inside my house for many years. I think the listening condition in my house might be still better than that of the other people. If I tolerate the buzzing tones,I will still be able to enjoy the programs. I have to keep the small radio receiver away from the cell phone units or anything running computers or other wireless devices, though.

I can no longer listen to the radio near my LCD displays, the laptop computers, and the tablet devices, without proper shielding of the radio and the external antenna outside the house in the open space. I can’t listen to the radio when I’m in the restroom equipped with a Washlet; the water spraying unit is driven with a switching power supply, which generates the noise effectively blocking the radio station signals.

AM radio, or the medium wave frequency broadcasting on 540-1710kHz in the Americas (531-1611kHz in the rest of the world including Japan), has been popular for more than a hundred years. The transmitter often requires nearly a few hundred kilowatts to cover the entire nation, but it works very well, especially during the nighttime when the ionospheric propagation enables the airwaves to reach much further than that in the daytime. For example, in Japan, NHK Radio Two Tokyo at 693kHz transmits 500kW from the antenna site in Kawaguchi City, Saitama, covers nearly twenty million households even during the daylight hours, and is heard very well regularly in Osaka and the other regions nationwide.

The AM in the AM radio stands for Amplitude Modulation. AM radio listeners only needs a simple equipment to convert the radio signals into the sounds. Crystal radio receivers, which have been widely used since the beginning of the 20th Century, are the simplest form of radio. They still work well when the transmission site is near enough. Most of the modern radio receivers convert the frequency of the received signals to the audio frequency range signals, however; superheterodyne receivers is the de facto standard since the transistors got commoditized in 1960s. You can even listen to the AM radio through the digital signal processing technology, on the software-defined radio receivers. So the technology is still alive and thriving very well.

The problem is, however, that more and more electronic devices emit various type of noises on the same frequency spectrum which is used for the AM radio, from the power suppies. It’s not just Washlet; it’s everywhere from the laptop computers to the LED ceiling lamps.

Modern power supplies use the technology called switching voltage regulation; the power supply acts as a high-frequency automatic switch to control the energy flowing into itself,and sends the energy to the devices. The output voltage is controlled by the ratio of the periods of turning the switch on and off. The switch is rapidly controlled to maintain the stable output voltage in the frequency of many hundred thousands times per second. This rapid-switching technology is essential to maintain high power conversion efficiency and low power loss, which cannot be achieved by the legacy power regulation technology called series voltage regulation, which does not use the rapid and abrupt switching, but generates considerably more heat and is much less efficient energy-wise for continuous voltage regulation.

Unfortunately, power switching causes generation of strong electromagnetic noise of the very wide spectrum, and the switching frequency itself is close to the one for the AM radio. The first switching power supply I saw was that built into Apple II computer in 1979. It was large, but still much smaller than the equivalent legacy series-regulated one. I immediately noticed that the sound coming out from the radio near the Apple II suggested how the CPU was working; computers then were not shielded well. I could also hear the power switching sound, emitted from the small voltage transformer inside.

The switching voltage regulation technology is so pervasive that now I see virtually all digital device around me are attached to the switching power supplies; the USB wall warts, laptop PC AC adapters, and the units built into various appliances from computers and even to the commercial and amateur radio transceivers, for more efficiency with less energy consumption. Reverting back to the age of series voltage regulation is simply impractical; no one will want to carry around a power supply which weighs many kilograms for a small laptop or a smartphone.

(Photo: http://www.flickr.com/photos/ndrwfgg/369002475/)

Modern radio modulation schemes are robust against various sources of noise. AM radio uses the voltage level, or the amplitude, of the airwaves to carry the information, and there’s no effective way to prevent the noise coming into the received signal. On the other hand, FM radio, whose FM stands for the Frequency Modulation, uses the pitch or frequency of the airwaves to carry the information, and the level of the signal is irrelevant unless it is very weak. So FM radio is more robust against the airwave noise than the AM radio and far less affected by the digital devices such as computers.

Then why don’t we convert or migrate from AM radio to FM radio? FM radio consumes much wider frequency spectrum to broadcast, and much higher frequency to broadcast about a hundred times of the AM radio (88~108MHz in most parts of the world; in Japan it’s 76~90MHz). Airwaves of that frequency range cannot use the ionospheric propagation, so FM radio stations do not reach as farther as AM radio stations do, and require considerably higher cost for the simultaneous nationwide coverage.

Let us get back to the original question: can we stick to the AM radio for direct broadcasting to indoor radio receivers, even under the condition that the number of devices emitting noise will be continuously increasing? My answer is no. AM radio will still be useful for serving outdoor and rural area listeners, and in case of disasters and emergencies, because the receiver cost is relatively low. For the urban areas, however, people will no longer be able to listen to the AM radio in adequate quality without erecting the external antennas; conversion or migration to the FM radio will be a practical and feasible plan.

Note that the AM-to-FM conversion is nothing new, especially for people in North America; many stations there have AM and FM simulcasting stations. And in Japan, especially on a coverage of important events, simulcasting between AM, FM and TV stations is frequently conducted. I am talking about the conversion, however, simply from the listening quality perspective, under the noise-bombarded radio spectrum environment in modern houses and buildings.

I’d like to propose providing simulcast in at least one FM radio channel for each AM radio stations in the urban areas. I think this is one of the most practical way to raise the listening quality of radio programs.


Note 1: some may claim internet radio stations will completely substitute the radio services over airwaves. I do not buy that idea because internet radio stations usually suffer a lot of delay of tens of seconds, which renders them useless for emergency or disaster warnings, unless another dedicated side channel is provided.

Note 2: some other people will also claim FM radio is very hard to listen to without an external antenna, which is unfortunately true. I think listening to the FM radio of quality sound is still much easier than to the AM radio based on my experience; FM radio antenna is smaller and less prone to electromagnetic noise inside the house, and is easier to erect.

Exported from Medium on August 7, 2013.

View the original