This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
at:introduction [2007/04/07 11:50] tvcutsem added |
at:introduction [2008/07/15 12:19] (current) tvcutsem * |
||
---|---|---|---|
Line 6: | Line 6: | ||
* **dynamically typed**, which is **not** the same as being untyped: AmbientTalk //values// are typed, but // | * **dynamically typed**, which is **not** the same as being untyped: AmbientTalk //values// are typed, but // | ||
* object-oriented, | * object-oriented, | ||
+ | * flexible: like Scheme, Smalltalk, Self and many other languages, AmbientTalk embraces the use of elegant and expressive **block closures** to achieve a level of reusability far exceeding that of Java or similar languages lacking true closures. | ||
* event-driven: | * event-driven: | ||
- | * distributed: | + | * distributed: |
* **symbiotic**: | * **symbiotic**: | ||
- | A word of warning, though: AmbientTalk is **not** a stable development platform. Rather, it is a research artifact used as a " | + | A word of warning, though: AmbientTalk is **not**: |
+ | | ||
+ | * a secure distributed computing platform. | ||
+ | * a customisable or language-neutral distributed computing platform. | ||
- | ==== AmbientTalk in a nutshell ==== | + | ===== AmbientTalk in a nutshell |
Enough talking, let's delve into some AmbientTalk code by means of a simple example to see whether we can spark your interest in AmbientTalk. The demo program we're about to explore is an extremely simple instant messenger program. Each instant messenger runs on e.g. a PDA, laptop or cell phone. When peers join the ad hoc network, the instant messenger should issue a warning to the user that a new buddy is available for chatting. The user can then send simple text messages to that buddy. When peers leave the ad hoc network, the user should also be notified. Off we go. | Enough talking, let's delve into some AmbientTalk code by means of a simple example to see whether we can spark your interest in AmbientTalk. The demo program we're about to explore is an extremely simple instant messenger program. Each instant messenger runs on e.g. a PDA, laptop or cell phone. When peers join the ad hoc network, the instant messenger should issue a warning to the user that a new buddy is available for chatting. The user can then send simple text messages to that buddy. When peers leave the ad hoc network, the user should also be notified. Off we go. | ||
- | === Design | + | ==== Designing the Instant Messenger ==== |
Here is the skeleton code for the instant messenger: | Here is the skeleton code for the instant messenger: | ||
Line 31: | Line 35: | ||
// the interface to the IM for remote objects | // the interface to the IM for remote objects | ||
def remoteInterface := object: { | def remoteInterface := object: { | ||
- | def receiveTextMessage(textMessage, | ||
def getName(replyTo) { ... }; | def getName(replyTo) { ... }; | ||
+ | def receiveTextMessage(textMessage, | ||
}; | }; | ||
| | ||
// engage in peer-to-peer service discovery | // engage in peer-to-peer service discovery | ||
- | | + | |
export: remoteInterface as: InstantMessenger; | export: remoteInterface as: InstantMessenger; | ||
whenever: InstantMessenger discovered: { |messenger| | whenever: InstantMessenger discovered: { |messenger| | ||
Line 47: | Line 51: | ||
An instant messenger object is created by invoking a function called '' | An instant messenger object is created by invoking a function called '' | ||
- | Within the lexical scope of the '' | + | Within the lexical scope of the '' |
The '' | The '' | ||
- | === Implementation | + | ==== Implementing the Instant Messenger ==== |
Let's delve into the method bodies and see how the instant messengers engage in distributed communication: | Let's delve into the method bodies and see how the instant messengers engage in distributed communication: | ||
Line 69: | Line 73: | ||
}; | }; | ||
def buddyList := jlobby.java.util.HashMap.new(); | def buddyList := jlobby.java.util.HashMap.new(); | ||
+ | ... | ||
+ | }; | ||
</ | </ | ||
- | The '' | + | The '' |
+ | |||
+ | Also interesting is the initialisation code of the '' | ||
- | Also interesting is the initialisation code of the '' | + | Now let us delve into the details |
< | < | ||
Line 91: | Line 99: | ||
}; | }; | ||
}; | }; | ||
+ | </ | ||
+ | The '' | ||
+ | |||
+ | < | ||
+ | A small note for the language adepts: the '' | ||
+ | < | ||
+ | def if: cond then: cons else: alt { | ||
+ | cond.ifTrue: | ||
+ | }; | ||
+ | </ | ||
+ | This code should look familiar to Smalltalk/ | ||
+ | |||
+ | Most curly braces in AmbientTalk denote first-class blocks. These never denote hard-wired syntax as in C or Java. The only exception are the braces used to delimit a method definition. | ||
+ | </ | ||
+ | |||
+ | Let us look in more detail at the '' | ||
+ | |||
+ | < | ||
def remoteInterface := object: { | def remoteInterface := object: { | ||
+ | def getName(replyTo) { replyTo< | ||
def receiveTextMessage(textMessage, | def receiveTextMessage(textMessage, | ||
textMessage.printMessage(); | textMessage.printMessage(); | ||
replyTo< | replyTo< | ||
}; | }; | ||
- | def getName(replyTo) { replyTo< | ||
}; | }; | ||
- | | + | </ |
- | | + | |
+ | The protocol of the instant messenger is very straightforward: | ||
+ | |||
+ | Finally, here is the code for managing the discovery of instant messengers: | ||
+ | |||
+ | < | ||
+ | | ||
export: remoteInterface as: InstantMessenger; | export: remoteInterface as: InstantMessenger; | ||
whenever: InstantMessenger discovered: { |messenger| | whenever: InstantMessenger discovered: { |messenger| | ||
Line 118: | Line 150: | ||
}); | }); | ||
}; | }; | ||
- | |||
- | localInterface; | ||
- | }; | ||
</ | </ | ||
- | Notice | + | The '' |
- | < | + | |
- | The buddy list is actually | + | Finally, notice how AmbientTalk allows you to deal with //partial failures//: you can register two kinds of // |
+ | |||
+ | ===== Conclusion ===== | ||
+ | |||
+ | You might wonder what is so special about the above example. After all, it is simply an application that sends simple strings across the network and displays them on the screen. But keep in mind all of the things you did **not** have to do: | ||
+ | * no explicit thread management | ||
+ | * not having to prevent data-level race conditions, not having to define locks, not having to debug the ensuing deadlocks | ||
+ | * not having to manually serialize/ | ||
+ | * not having to manage low-level socket connections | ||
+ | * no need to setup a name server or similar lookup service | ||
+ | * no annoying configuration files | ||
+ | * not one XML document in sight | ||
+ | * not having to manage complex buffering to ensure messages sent to disconnected objects are not lost | ||
+ | * no need to write the boring Singleton design pattern to make your classes look like objects | ||
+ | * no need to generate stubs, skeletons or other kinds of proxies to manage remote objects | ||
+ | |||
+ | Of course, we are not claiming that AmbientTalk is a good replacement for distributed computing standards such as CORBA or Jini, which are much more flexible, at the cost of increased complexity. AmbientTalk is simply a lightweight alternative for doing experimental research. | ||
+ | |||
+ | ===== Moving on ===== | ||
+ | |||
+ | So, you read the introduction and are interested in all of the gory details of the language? In that case, you can go ahead and [[at: |