Saturday, November 10, 2012

Hello world with nodejs and script#

I have used S# at work before to write client side javascript. It really shines when you have a lot of javascript files/modules in your application. You get all the benefit of leveraging C# oops paradigm, managing dependencies among various modules in javascript as well as benefiting from all the tools Visual studio has to offers.

Recently, I was playing with nodejs in one of my project and wanted to see if I can build a simple Hello World nodejs application with S#. Even though the public version of S# extension for Visual Studio does not support NodeJs out of the box, the functionality already exists as part of S# github repository. So to get started, I need the latest bits from S# github repository. To do so, 


1. Clone the repository


git clone https://github.com/nikhilk/scriptsharp.git

2. Once its cloned, go to scriptsharp/src folder and open ScriptSharp.sln solution. Now build the solution with both debug and release setting.

3. Once done, go back to scriptsharp root folder. At this point, you should see a bin folder containing following folders.




4. At the time of writing, this should corresponds to 0.8 version of S#. Simply double click on ScriptSharp extension and install it. As a best practice, I always keep a copy of the whole folder under my external libraries folder and add a README file to note the time stamp when I build this library.


5. Once the extension is installed, create a new project in visual studio and select nodejs application as follows:





6. You project should now contain a single class (Class1.cs) which essentially creates a program that listens to all the http requests on your localhost at port 1337 and spits "Hello Node.js World, from Script#!" in response.

7. To run this program, simply build it, It will output <yourappname>.js file in bin folder. Navigate to the either bin/debug or bin/release (depending on how you build your app) folder in your command prompt and simply run 


node <youappname>.js

Now navigate to http://127.0.0.1:1337/ and you can see your Hello World program in action.


NOTE: For some reason port 1337 did not work for me. When I ran node command from command line , I got:



events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: listen EACCES
    at errnoException (net.js:769:11)
    at Server._listen2 (net.js:892:19)
    at listen (net.js:936:10)
    at Server.listen (net.js:993:9)
    at dns.js:71:18
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

To get rid of this error, I simply changed the port to 1338 and it started working for me. I am not sure why it is throwing that error. My guess is I have some other service running on that port.


As I mentioned before, though the power of S# might not seem obvious with this Hello world example, but I am sure that as you app logic grows, you will appreciate the power of S#.

Wednesday, March 14, 2012

How to fix the commenting system on internet

I personally think that the current commenting system on internet is suboptimal as also mentioned recently by Nick from Gawker Media. I believe that they are considered second class citizen on page even though many times they provide much more useful data and reveal more issues around the whole topic. I definitely think there is an opportunity to rethink the whole commenting system. Here are my some initial thoughts -

Do you know how in Microsoft Word you can attach comments with a particular section of the document ? I personally think that those sort of comments tends to be more concise and useful. In my last project, everybody was encouraged to review any doc offline and add comments. During the review, they would only go through comments. It went very well and the meetings were very productive. Another similar example - remember back when we were in school, how our teachers used to grade our exams ? They would add their remarks next to a particular answer or part of the answer which required attention. My point is attaching comments with a section feels much more natural , much more human. I think we need to have a way such that comments are attached to certain section of the article. My hypothesis is that such a mechanism would encourage more constructive criticism of an article which would in turn increase the quality of the article. Note that the section necessary does not have to be text - it could be part of an image or at some point in time for a video ( I am sure you must have seen - go to 12:15 in the video for blah.)

I also think the placement of the article on the page is not optimal. Currently comments are placed at the bottom of the page - for most part (This also sort of reflects that they are second class citizen). When a new user comes to the article, he/she only engages with the comments after they went through the whole article even though comments sometime contains a lot of facts, figures and/or alternative thoughts. However, I think the comments should be read as part of the article. While you are in the middle of an article, all the applicable comments should have equal chance to be read at the same time for that section. This keeps the current context in perspective and would empower user to better make his/her opinion about the whole article. This would make comments more engaging and useful. Furthermore, this would also help to increase the quality of the new comments.

I understand that all the comments are not useful. Once a comment is shown, how do you determine which one is most useful to the current section ? Let the user decide which one is better. Let them vote and then bubble them up to the top. If you buy my previous hypothesis that attaching comments to a section is useful - now imagine how the whole system would work. Reader reading an article and get to read the most useful comment at the same time. To add up - imagine there is one global commenting system and you carry your reputation across the sites on internet.