Developing on the go
Orbitz - orbitz - August 19, 2005One benefit to using erlang compared to more traditional languages is the development cycle. Generally you write code, compile, debug, write, compile, debug, until you have something you want to use. In between compile and debug you run the program. In traditional languages you shut down the application then restart it to debug again. In erlang we can skip the ‘restart’ and simply load the new code in. This is assuming no bugs in the code didn’t cause the entire application to crash horribly.
So basically, what is going on is, if you have a logic problem or what not in your application that you wish to fix. Outside of your running application, you edit the appropriate .erl files and recompile. For example, your application consists of a.erl and b.erl. In b.erl you have a function called mogwai.
So in our example. a.erl calls b:mogwai, and b:mogwai has some sort of error in it that does not cause the application to crash but you want to fix, regardless. You fix b:mogwai’s error and you want to load the new codebase in your running application. Recompile b.erl then in the shell to your application you simple do:
nl(b).
This loads the new version of b into your application and now calls to b:mogwai will use the current version of the function. For certain applications this certinaly provides a more elegant development cycle. I think this style also alters the structure of ones code. For instance, if one writes an application knowing that errors in the code can be fixed on the fly, no longer do they necesarly have to exit nicely. Rather, the application can provide a means of restarting the portions that have crashed. The application can continue working without the crashed process/code or stall until the required portion can be brought back. I’m under the impression this is a feature supervision trees offer you. A supervisor simply restarts a process if it crashes, and reports it. By restarting, a new codebase can be loaded that fixes the error.
One final note on how code replacement works. Erlang only attempts to load a new module if the call is in the form of: module:function. For instance, if you have a process in a loop something like:
loop() ->
receive
Something ->
loop()
end.
If you reload the module that this loop is defined in, the call the ‘loop()’ will not load the new codebase. The common idiom is something a long the lines of:
loop() ->
receive
restart ->
?MODULE:loop();
Something ->
loop()
end.
This will load the new codebase. On a final note, any function called as module:function must be exported.
Erlang certinaly provides some interesting features. Certinaly somethign like code replacement is possible in other languages, such as python (which provides a reload function to reload a module) I think erlang provides a more elegant solution. For instance I don’t think Python provides a means of a module to reload itself, especially in the middle of an event loop.
However this is not a contest between code replacement in various languages. I have modified my irc bot to allow code replacement more seemlessly, however I have not allowed a decent means of bringing an irc bot back if there is an error which causes a crash. I’ll have the new code online later if anyone is interested.
Categories: Blogs Orbitz
Comments
I have modified my irc bot to allow code replacement more seemlessly, however I have not allowed a decent means of bringing an irc bot back if there is an error which causes a crash. I’ll have the new code online later if anyone is interested.
Posted by vista error on 24 Jan 2010 at 12:18What happens if there are bugs that make the system crash? I would love to have the new code so that there isn’t an error which cases a crash. In meantime is it best to install some sort of disaster recovery software in case it crashes? I have been shopping around and can’t decide what to get. What are your opinions on this one: http://www.neverfailgroup.com? Or do you have any other suggestions. Thanks, and I look forward to getting the new code.
Posted by Claire on 19 Mar 2011 at 16:56I’ll have the new code online later if anyone is interested. nike free run sale
Posted by nike free run sale on 24 Feb 2012 at 19:05
Add comment
Erlang on Twitter
» winda_lestari63 (winda cliquers): gg usja di pikirin prins ank itw gjhe..RT:@Prinsia_2140
@Erlang_ABNIC @ji_bero @erlang_abnic @rb_120511
» ErlangSolutions (Erlang Solutions): Want to join the best of the best of the best? ESL is hiring 40 engineers! Join our Linkedin Group to keep updated http://t.co/CDB7qYeI
» Prinsia_2140 (˘⌣˘ pRiNsiAH ˘⌣˘): @Erlang_ABNI : http://t.co/j61ODMNv
» Erlang_ABNIC (Erlangga .A): JERA :) RT @AgnesMonicaFanz: #acakhuruf A-R-J-E . klue : kapok,lagu. jawab yuk NIC !
» Fedora_Updates (====================): Fedora 17 Update: erlang-misultin-0.9-1.fc17 http://t.co/u3ABUDkz
» HornedKavu (Max Riveiro): RT @shwars: Вчера в докладе career.ru на #itedu были озвучены новые востреб.профессии на IT-рынке: Haskell-, Lisp- и Erlang-программист!
» phyrexianengine (Vasily K.): RT @shwars: Вчера в докладе career.ru на #itedu были озвучены новые востреб.профессии на IT-рынке: Haskell-, Lisp- и Erlang-программист!
» Erlang_ABNIC (Erlangga .A): @cjerikho829 selamat shooting ♈o kak.. Nitip salam buat kak @Bellaudya829.. ☺ Semangat (งˆヮˆ)ง
» dessyrosalia (♡pesek mancung♥ ): Erlang ke rumahku donk kangen nih
» si_erlang (Erlangga Adhitya): 75% dalane jahanam
Statistics
Number of aggregated posts: 10498
Number of comments: 2115
Most recent article: May 15, 2012
Latest comments
» cheap soccer jerseys on Memory Models in Erlang vs Java: Nice discussion here,you are doing a great job. i was looking for this information. i found it on your page…
» mandesejohn on Couchbase Meetup at new HQ: Thanks for sharing experience. It should be really a great post. It should be knowledgeable and informative. Keep it up. flower delivery columbus ohio
» vermaseo on Scale means Skills: I’m surprised people are still commenting about this. George has been moved on to bigger and better things with the president for awhile now.ledikanten