Tuesday, September 23, 2014

Interaction Design between user and the operating system - Part 2

Taking our discussion further, in this blog we would explore options for programming the user interaction with operating system.

User action programming

In part 1 of this series we focused on the direct user interaction with the operating system. But fact of the matter is that most of the user interaction on a computer or a device happens through a custom software or app. So it is very important to focus on the programmability of the operating system functions.

"Any programmed interaction must make use of most of the operating system supplied functions."

The above statement is the essence of this discussion. Let us establish one thing here before we go any further.

The best (in terms of ease of use and reliability and probably others) interaction experience is through operation system supplied functions.

For example: If I want to open folder and view its contents, the operating system has a command for it. It would have a user interface and set protocols (steps) to invoke that command and the experience that user gets would be standard and consistent. A programmer can write a custom software that would accomplish exactly the same thing but using different user experience and different protocols (steps). Another programmer can write another software that accomplishes exactly the same thing but using another set of different user experience an different protocols (steps) and so and so forth.
The thing to note here is the impact on the user. Since custom software uses its own user interaction and protocols, it is responsible for the acceptability and reliability of its functions. What is meant here is that the programmer would have to consider so many things to create such a software. The user is totally dependent on the knowledge and the interface engineering provided by the programmer through the custom software. This is where we start loosing the battle. This is where we as engineers or programmers have to ask ourselves, are we taking the user out of misery or putting them in misery? If we use the operating system supplied functions in our code, then we would not have to worry about so many other things.

As a reader you must be thinking that this would end  all the programming and programmers especially the application programmers. Well that is true, in a perfect world. We as technologists are not as developed yet. We have a long way to go. But this is what should we strive for.

Let us get back to our current era and talk about the points againts the above statements.

1. What about those interactions that operating system does not provide?
That is a very valid point. Let us take an example to elaborate more on it.  The application that user is using requires a certain interaction of moving the position of the window from right to left with in the time span of 2 seconds as a result of a user action. This user action would always yield the same result of moving the position of the window. The operating system that user is using does not define it a function. Means there is not a similar interaction provided by operation system as a function. In the case the obvious solution would be to write a custom code that does such interaction. A programer writes a such a code. Same task is given to another programmer and another programmer. We would have a result using different solutions that accomplishes the same thing. Since the solutions or the written custom code is different, we have to assume that one of them is better then all the others. What if we just had one programmer and he/she was the one who tasked and the solution the he/she wrote was not the one that was the best. It means we have a software code is not best code. This is the point that mentioned earlier as the point that we as technologists start loosing.

So what should be the solution. The solution should be that the operating system should be augmented with the best solution (code) for the moving the window from right to left within a set time. This would become an augmented function of the operating system and should be made available publicly to other progammers.

2. So we keep adding functions to OS but for how long?
This is another valid argument. We cannot keep adding any new interaction that anyone's mind can think of. This is where we have to make a distinction between valid and invalid interactions. We have to draw a line in the sand and define these two types of interactions. We should design software using such that user would not need to make use of an invalid interaction. This is another high point in this discussion. The interaction design should be so smooth and natural that user does need to think of an interaction that in fact is an invalid interaction.



Conclusion

The point of this part was not that we do have software that do not make use of operating system defined functions. But to point out the places where we cannot. The two main points are: A) that operating system should be rich in respect that all its functions should be valid and available. B) the second point is that we should design the interaction so smooth and natural that use would not need to make use of interaction that is not defined as a valid interaction.



 

Thursday, August 28, 2014

Dart from .NET - Unit testing

Introduction


Unit testing as an aspect of software development is essential tool to keep the code  valid. This means that when we develop software or write code, we need an automated way (programmatic way) to validate the written code. QA can help with validating the results but cannot take place of automated scripts that run the unit tests. Also, we need to have something written by programmers that validate what programmers have written so far, looking from programmers' perspective.

Unit testing with Dart

Unit testing with dart is pretty straight forward. Here is what you need to do to write a simple unit test using dart language.

1. Import unit test package 'package:unittest/unittest.dart'.
2. Setup main() function to launch the test
3. Arrange code to prepare for test
4. Write code for test.
5. Assert the results.
6. Establish the testing infrastructure (or simple create a web page that would call the test code).
7. Run the tests in the browsers.

Here is an example:

 import 'dart:html';  
 import 'dart:convert' show JSON;  
 import 'dart:async' show Future;  
 import 'dart:math' show Random;  
 import '../lib/attempt_helper.dart';  
 import '../model/attempt.dart';  
 import 'package:unittest/unittest.dart';  
 import 'package:unittest/html_enhanced_config.dart';  
   
 List offlineSymbols;  
   
 main() {  
  useHtmlEnhancedConfiguration();  
  //useHtmlEnhancedConfiguration(true);  
  var path = 'symbols.json';  
  //HttpRequest.getString(path)  
  //  .then(_getOfflineListFromJSON)  
  //  .then(_launchOfflineTests);  
  HttpRequest.getString(path)  
   .then(_parseSymbols)  
   //.catchError(_getFailsafeFeaturedSymbol)  
   .then(_launchAttemptHelperTests);  
  //_launchAttemptHelperTests();  
 }  
   
 List _parseSymbols(String jsonString) {  
  offlineSymbols = JSON.decode(jsonString);  
  return offlineSymbols;  
 }  
   
 void _launchAttemptHelperTests(List symbols) {  
  AttemptHelper attemptHelper = new AttemptHelper();  
  List<Attempt> attempts = new List<Attempt>();  
  Attempt newAttempt = new Attempt()  
   ..answers.add("1")  
   ..answers.add("2")  
   ..answers.add("3")  
   ..answers.add("4")  
   ..correctAnswerIndex = 1  
   ..givenAnswerIndex = 1;  
  attempts.add(newAttempt);  
  Random random = new Random();  
  group('Attempt Helper Tests ->', () {  
      test("Test to check if list has any item", () =>  
       expect(attempts.length > 0,isTrue)  
      );  
      test("Test to check if returned attempt from helper is not null", () =>  
       expect(attemptHelper.getAttempt(attempts, symbols) != null, isTrue)  
      );  
      test("Test to check if returned attempt's answers from helper is not null", () =>  
       expect(attemptHelper.getAttempt(attempts, symbols).answers != null, isTrue)  
      );  
      test("Test to check if returned attempt's answers are greater than 0", () =>  
       expect(attemptHelper.getAttempt(attempts, symbols).answers.length > 0, isTrue)  
      );  
      test("Test to getScore", () =>  
       expect(attemptHelper.getScore(attempts) > 0, isTrue)  
      );  
      test("Test to check if returned randon answer is not null", () =>  
       expect(attemptHelper.getRandomAnswer(symbols, random, newAttempt.answers) != null, isTrue)  
      );  
      test("Test to Post a wrong given answer", () =>  
       expect(attemptHelper.postGivenAnswer(attempts, "10") == false, isTrue)  
      );  
      test("Test to Post a correct given answer", () =>  
       expect(attemptHelper.postGivenAnswer(attempts, "1") == true, isTrue)  
      );  
      test("Load test by running 10records", () =>  
       expect(get100Attempts(attemptHelper, 10) != null, isTrue)  
      );  
     });  
  }  
   
 List<Attempt> get100Attempts(AttemptHelper attemptHelper,int numberOfInterations) {  
  List<Attempt> hundredAttempts = new List<Attempt>();  
  for(int i = 0; i < numberOfInterations ; i++) {  
   attemptHelper.getAttempt(hundredAttempts, offlineSymbols);  
  }  
  return hundredAttempts;  
  }  
   

As you can see from the above example it is pretty simple to write the unit tests in dart programming language. Also you can see how similar it is to unit tests that we write using C# in .NET.

Running the unit tests

As mentioned in point 7 and 8 in the previous section, we have to establish the unit test infrastructure which essential the host for the tests. In our example it is a simple web page. You can use command line app to host your unit tests.

Here is the code of the web page that establishes the infrastructure and runs the unit tests:



 <html>  
  <head>  
       <meta charset="utf-8">  
       <meta name="viewport" content="width=device-width, initial-scale=1.0">  
   <title>tests</title>  
  </head>  
    
  <body>    
   <p id="text"></p>  
   <script type="application/dart" src="tests.dart"></script>  
   <!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->  
   <script src="packages/browser/dart.js"></script>  
  </body>  
 </html>  


That is it!

Here is how the results look like:



Monday, August 4, 2014

Dart from .NET - Why Dart?

Introduction

I have been a Microsoft .NET developer since .NET came out as Beta back in late 2000 and Visual Basic developer before that. Over the past fifteen years I came across many languages and technologies that pose challenge to .NET and its development framework. They were good but usually they were good in one particular aspect and again at some level you have to fall back to IIS or .NET framework for other features. I am not claiming that over the past fifteen years there was no language or technology that did all what .NET does. They might have done all but they were not as good as .NET or in some cases the development environment was not as easy to use as Visual Studio.

And then came Google's Dart

 As I mentioned in my intro that .NET provided a complete solution for most of the programming projects. That meant that in some cases we as developers had to work through some of the challenges that .NET framework posed. I always looked for a language that would be close enough to C# and at the same time development would be easy in it should provide a complete solution and not just one aspect. 

Elephant in the room

Let us talk about the elephant in the room first. By the elephant in the room, I mean the following:

1. Dart is not even supported by Chrome

At the time of writing this article, the Google's chrome does not support dart in its default setting. But there is a version of Google Chrome called Chromium that does come with Dart support. You can visit https://www.dartlang.org/docs/dart-up-and-running/contents/ch04-tools-dartium.html for further details.

2. Why not just use java script?

Google has been improving java script for a long time. Java script has come a long way. The fastest java script engine that I am aware of is called V8. Having said that Java script has some language features that put Java script in some disadvantage. If not disadvantage then at least cause the slowness. Google's dart language has language features that allow it be faster than javascript. Just that alone is an advantage that makes a whole lot of sense when thinking about scalable mobile applications. Also, let us say you use dartToJs to convert dart code to Java script. That too is faster than traditional java script. 

Screen shot from : https://www.dartlang.org/performance/


3. What about the Google's Go programming language?

This one is a tough one. Per my knowledge Google's Go language or golang was developed to make programmers more productive. So it means it is not a language comparable to C# or VB but a language to fix a part of problem. I do not think that if I should invest time and energy in learning golang. If you compare that with Dart then dart appears to be more general purpose and more evolved than golang.


 4. What about jQuery?

If you take the evolution of a language as a factor then jQuery seems to be quite evolved. Google Dart seems to have been "inspired" by many features of jQuery if you go through some development using Dart. With all the good stuff that jQuery does,  underneath that it is essentially java script. So the same disadvantages Also, if jQuery would have been filling all the gaps that java script has then I do not think Google dart would have been developed.



So since I have explained the negative things that are said about Google's Dart language, I can now talk about the good stuff.

Amazing Dart Features

Now let us talk about the aspects that makes language of choice for modern web apps.

Scalable Web app development:

When the dart was being developed, it appears that only the 'good parts' of other languages like 'C#' and 'Java script' were taken into consideration. At the same time the 'bad parts' of the other languages were avoided. What resulted is a language that is highly tuned for scalable web application development. Here is one example:

import 'dart:math' as math;
 
import 'dart:convert' show JSON;
  
The above two examples show a feature that is quite amazing. What it does is that it enables a program to include a particular library but not all of what is present in a library. It allows select part of library that your program would be concerned with. Imagine the situation where System.Web in .NET. The system.web is a huge a library about 8 megs. In ASP.NET we use system.web a lot but we do not need all the features of system.web. What ends up happening is that the application becomes bloated. 

So language features as one mentioned above allow us developers to create scalable web applications using Google's dart language.

Mobile development:

Like or not more and more applications are being developed for mobile. Which means that more and more of the logic is being sent on the browser end and less of  running the logic at the server side. This is pushing the envelop on web development. You do not have much memory at the same time you cannot rely on chatty architecture as mobile environment is not always available with internet (that is why SPA "Single page application" gained popularity). So what it means that you want to provide rich experience to users but not rely on heavy web controls. Dart fills this gap very well. It is robust like jQuery for provided rich experience at the same time it is fully refined language as C#.

Language feels like C#:

Why this is an amazing language feature? That is because most of the .NET developers including me love C#. So when you see a language similar to C# then you feel at home and learning curve does not seems intimidating. Let us say if the dart's syntax was very different from C# then for me personally it would have been a major turn off or I had to prepare myself for steep learning curve. Now let us see some of the examples where dart language feels like C#.


Server side programming:


This is huge. We have been living in a web echo system where UI logic was written in different language then middle tier logic or the back-end logic. Example, a web site that has front end developed using jQuery or Java script, talking to a web service that is written using C#. That certainly meant that you have to have expertise in both languages in order to produce an excellent result. Which often meant two different types of developers.With dart you can have a developer who is expert for both back-end and front-end developer. There is an interesting analogy that helps explain this. In the world of military aviation, those air force who have more variety of aircraft are considered less efficient than those who have less variety. This is because for more variety you have to have more skill personal in different technology who translates into more expensive maintenance.

In my next few blogs I will share my experience and knowledge with regards to dart.