Re:The secrets of Node's success
by technomancy on Wednesday June 08, 2011 @02:56PM
(#2634515)
Ian Bicking does a great job of debunking the many of the alleged advantages of code sharing: http://blog.ianbicking.org/2011/03/30/js-on-server-and-clien...
[ Parent
| on HN ]
With the right abstractions the code for validating on the client and for validating on the server can be identical. For example take a look at Luna/Lunascript.
This is not easy by just using Node, and it's not necessary that the language you use is Javascript. A better approach IMO is that you have a language X that is nicer than Javascript, and compiles both to server side code and client side Javascript.
For the case of validation here is a hypothetical language (ignore the bad regex):
<form action="/foo/bar">
<input type="text" name="email" />
<%= if not email ~ "[a-z]+@[a-z]+.[a-z]+": invalid("Email is not valid") %>
<submit>
</form>
From this code you could generate real time JS validation and server side validation.