Skip to content

Commit

Permalink
Removed outdated information from best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
sridatta committed Sep 12, 2011
1 parent 6f3e3ce commit 9f62700
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions doc/public/best_practices.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
Coding Patterns and Best Practices
==================================
The NowJS syntax and semantics are intended to integrate naturally into your application's existing coding patterns. However, there are some coding patterns and best practices that you may find useful.

The "broadcast and receive" pattern
-----------------------------------
When building chatroom-style applications, it is common to broadcast a single user's action to all connected clients. This is commonly done like so:
**On the client**:

now.receiveBroadcast = function(message){
//Render message in the UI or process it some other way
}

**On the server**:

everyone.now.sendBroadcast = function(message){
everyone.now.receiveBroadcast(message);
}


Efficiency Considerations
-------------------------
It is the goal of NowJS to make the shared namespaces as carefree and easy to use as possible. However, if your application is running slowly or you are coding with performance in mind, here are a few considerations.
Expand All @@ -26,7 +9,7 @@ It is the goal of NowJS to make the shared namespaces as carefree and easy to us
Setting or modifying variables that lie inside multiple levels of nested objects and arrays is inefficient. NowJS must traverse these deep structures to watch for changes, serialize the structure when a value is changed, deserialize it on the receiving end, and traverse it again to merge the changes on the receiving end. Keep your structures at most 2-3 levels deep.

2. Sync values using remote function calls rather than using synced variables.
As described above, some amount of traversal is required to synchronize variables in the `now` namespace. If you need to rapidly set a value on one client and then immediately use that value on the other clients, consider using the "broadcast and receive" coding pattern. Function calls are much faster than using variable syncing.
As described above, some amount of traversal is required to synchronize variables in the `now` namespace. If you need to rapidly set a value on one client and then immediately use that value on the other clients, consider broadcasting this using function calls. Function calls are much faster than using variable syncing.

3. The Internet will always be slower than the local machine
We try to make remote functions and variables as natural to use as local ones. But the reality is that the latency for any remote action is 6 orders of magnitude longer than the same action done locally. Try to execute things locally when possible.
Expand Down

0 comments on commit 9f62700

Please sign in to comment.