You are currently browsing the category archive for the ‘Uncategorized’ category.

Answer by Fabrizio Moscon:

This isn't a trivial question so I think it deserves an articulate answer. Few points have been already expressed in other answers but I think listing all of them can help clarity:

1) fast and easy to prototype: makes extremely easy to prototype (almost) any kind of web application in a shorter time when compared with others like for example JAVA and LAMP. Just to mention some of the savings in time: node.js provides the web server module itself, so you don't have to own knowledge about setting up Apache or NGINX unless you want to integrate in the existing platform or you have a complex system architecture, and the very active node.js community provides ready-to-use modules and deep knowledge that can save you time when it comes to develop commodity features (Facebook-Connect, RESTful API, templating)
2) npm: is THE node package manager, it represents the standard way to share code with the community and to manage external dependencies. It is only 2 years old and the number of module present has (almost) overcome the number of module published on RoR gems. Using community modules like express,, mongoose, mocha, everyauth – just to mention few of them – provide you with a powerful toolbox to build a running application "LAMP equivalent" within a matter of hours. It manages all the nested dependencies for you, so you can concentrate to what is your CORE application logic rather than spending time developing commodity features which the community is maintaining in a collaborative and effective way for you. The easy configuration file syntax let you also fix a module to a specific version so you don't have to worry about future updates breaking your software.
3) cloud platform: there are a number of Platform as a service solution like Joyent cloud, heroku, nodejitsu which identify node as first class technology and make deploy and scale of your application trivial. Other similar services like Pagoda let you develop PHP+MySQL application easily as well, but at the moment there is more choice and better support for node technologies in the cloud IMHO.
4) mongoDB and Redis: usually a node.js project comes hand in hand with a NoSQL solution. MongoDB and Redis are complementary technologies that are very well integrated with node.js. If you are doing a project without a relational database, node.js is definitely a good candidate.
5) javascript and coffescript: the fact that Javascript is the language of the browser made it necessary for all web developers to deal with it. This means that almost every developer can read Javascript, and I find more and more people capable of writing good, solid, robust client JavaScript applications. Having node.js in the backend brings other kind of problems like layered architecture, Domain Model Design, MVC and correct use of design patterns which developers are typically used to solve using other languages like PHP, JAVA, Python, RoR, but coffescript constitutes a valid bridging gap translator language between the clssical OO inheritance and prototypal ones like JavaScript, helping not savvy new re-discovered node.js developers to avoid silly mistakes and filtering out the bad part of JavaScript
6) architecture: node.js architecture helps you overcome performance and scalability problems thanks to its non-blocking interaction. Metaphorically someone at the Nodestack on-line conference compared Apache as a pizza over when you have to wait for the existing pizzas to be cooked before putting more in and node.js to a juggler which let requests to be handled in the air while is serving the new coming. This particular architecture that similarly to NGINX leverage directly the Operating System event system calls opens up the development of all those soft real-time application which couldn't be developed easily using other languages. 
7) costs: thanks to its high performance you can avoid costs for extra hardware. I manage to reach 5000 response per second on my laptop (measuring with ab -n 100000 -c an express application). Theoretically you also save in system administration time (unless you have a complex architecture), since there is no need to bridge HTTP or TCP requests to another server side language. So you avoid Apache or NGINX setup and maintenance costs.

There are still a branch of web applications that I would not advise being developed using node.js, although the community is growing so quickly that I wouldn't be surprise to see very soon node.js used at the centre of complex transactional systems. Most probably when you need a sandbox environment where separation of memory space for each requests is critical for the business and you can't afford a situation where a single exception takes down the server node.js is suboptimal.

Why choose Node.js for web applications?


Recently I wanted to find out how github works technically, with the intention of uploading a small personal project. After googling I found a presentation titled exactly that – How GitHub works. However it turns out that it was a presentation given by one of their employees about how the company itself works – how they communicate, how they do planning, development, product releases, etc. I found this very interesting and watched the whole things which is 55 minutes long. Here’s the presentation and a summary I’ve made:

– starts with company structure, ethos, hierarchy (no managers), flexible hours, team setup and size, etc
– @2m Working 9 to 5 doesn’t suit every company, best solutions happen in the zone
– @4m Embrace flexibility, let people work when they want and when they’re most productive
– @7m Trust the people you hire
– @8m Asynchronous workflow
– @10m Limit in person contact, use chat even in same room – lets others into the conversation;
– @12m Weekly tech talks, recorded and uploaded to internal server for future usage for new employees
– @13m Have face-time, once or twice per year get team together for day out / meal / drinks
– @14m Minimize distractions – the zone is difficult to re-enter
– @15m No technical meetings, no stand-up, daily, or planning meetings. Use chat to communicate asynchronously
– @16m 60 employees, no managers
– @19m Minimal process – plan it, build it, ship it
– @22m Use simple branching: master => branch => pull request => merge; master always ready to deploy
– @23m Deploy 5 to 30 times per day
– @23m Pull requests replace traditional code reviews;
– @25m Count number of assertions, currently 8000 taking 250 seconds
– @26m A slow test is a regression
– @28m Deploy => check exceptions => check performance => merge into master (if applicable) => celebrate!
– @32m Foster exploration, shared side projects
– @34m Continuous learning
– @35m Avoid burnout by encouraging new things

On my current project I’ve been working with a concept called a time point, which allows a user to schedule certain events that need to happen at specific points of time. Up until now I had been using the same partial view rendered from different parent views (which were also partial views within an overall view). This caused problems when rendering fields using EditorFor and DropDownListFor methods, as these methods use the model name to create the field names and ids. Because the model was the same, fields called from different parent views were being rendered with the same names and ids. To work around this I had to use an if-else to decide on the prefix that we needed, depending on a certain property in the model which was set in the parent view. This approach was quite clunky and Editor templates negate the need for this as they render the correct ids and names automatically.

An Editor template is a partial view that’s placed by convention in a directory called “EditorTemplates” in Views/Shared, and again by convention is named the same as the view model containing the fields we want to render:




So in this case my ViewModel is called DiscreteTimepointViewModel.cs:

/// <summary>
/// ViewModel for discrete timepoints
/// </summary>
public class DiscreteTimepointViewModel
/// <summary>
/// Gets or sets the TimePointType associated with this StudyEvent
/// </summary>
public int TimePointType { get; set; }
/// <summary>
/// Gets or sets a time points string which can serve as an input for generating an array of time points. This property
/// is only used by the razor views to generate HTML elements using the HTML helpers.
/// </summary>
public double? TimePoint { get; set; }
/// <summary>
/// Gets or sets the ID of the time unit for the specified TimePoint.
/// </summary>
public int? TimeUnitID { get; set; }
/// <summary>
/// Gets or sets the model name
/// </summary>
public string ModelName { get; set; }
/// <summary>
/// Gets or sets the left hand field binding name
/// </summary>
public string LeftHandFieldBindingName { get; set; }

After adding the template view and view model I then add a view model property to each parent view that I want to render it from:

/// <summary>
/// Gets or sets the view model for discrete time points
/// </summary>
public DiscreteTimepointViewModel DiscreteTimePoint { get; set; }

So using the above I render the time point fields from a view as such:

@{Model.defaultStudyEvent = new DiscreteTimepointViewModel { TimeUnitID = 1, ModelName = "defaultStudyEvent", LeftHandFieldBindingName = "leftHandStudyEvent" }; }
@Html.EditorFor(x => x.defaultStudyEvent, "DiscreteTimepointViewModel")


July 2018
« Sep    
%d bloggers like this: