Monday, August 11, 2014

How to justify anything as a developer?

How to justify anything as a developer


One way of calculating pi is from the area of a circle, you could even embedded that image in the code. You /could/ then suggest someone call this as an external program, to calculate pi from a script. This is clearly a stupid thing to do.

Here’s a badly written program to do it:

   
#include < stdio.h >
#include < math.h >

char mask [20][20] = {
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
  {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
  {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
  {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
  {0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};

int main() 

{
  int area=0;

 for(int x=0;x<20 i="" nbsp="" x="">

{
     for(int y=0;y<20 i="" nbsp="" y="">

    {
       if(mask[x][y] == 1) area++;
    }

}

  printf("pi: %f\n",(float)area/((17/2)*(17/2)));
}


And here are some ways of justifying it:

Hmm perhaps we should refactor this, maybe there’s a better way?
It works so it’s fine, there are more important things for us to be working on.

Why don’t you just use a hardcoded value, or value from a library?
That’s crazy, you should /always/ avoid magic numbers in your code. How do you know a hardcoded value is correct? You’re developers get no intuitive feeling for the value of pi. They don’t know how to increase the precision of the value. I’m sorry that’s just nuts.

The answer is WRONG it calculates pi as around 3.7
There’s no /right/ answer, all values of pi are approximations. 3.7 is good enough for many applications. It’s also trivial to modify this program to use larger circles and get a better approximation.

OK, but there are FASTER ways of calculating pi

Have you benchmarked it? (people are generally too lazy to benchmark). If it’s really a performance bottleneck you can calculate the value once and store it. In any case, don’t be sucked into premature optimisation. Developer time is more expensive than compute time.

But it’s completely UNCLEAR

I disagree, this method gives the developer a visual representation of the value of pi. They can intuitively see where the value is coming from. What’s more it’s easy from them to change to code and add larger circle images as required. There are even peer reviewed images of circles all over the Internet which can easily be incorporated.

You’re nuts
You just don’t understand the business case for doing it this way, you’re too wrapped up in the technical issues to see the big picture. You’ll understand better when you’ve been programming for (as long|at the same scale|with large teams) as me.

You can attempt to justify pretty much any programming position by appealing to: utility, premature optimisation, readability and intuition, business cases, and the old standby: experience.

Monday, June 23, 2014

WebRTC on iOS devices

If you haven't already heard about WebRTC, it is one of the hottest buzz words around town (early 2014). WebRTC is an emerging standard that enables a browser-to-browser voice, video and data sharing without the need of plugins, software or centralized communication infrastructure. It is an innovative technology that finds many applications, ranging from simply sharing a URL to start a video-conference between two browsers to buyers looking at the products in real-time as apposed to static images before they complete the purchase. The WebRTC has the potential to impact businesses including PBX firms, videos firms and web conferencing firms.


Here is my brief summary of WebRTC technology with an emphasis technologies that enable WebRTC on Apple iOS devices.  

Technology Overview

The WebRTC is a communications standard developed by the W3C in close cooperation with the RTCWeb standard developed by the IETF. In practice WebRTC is a set of Libraries/Application Programming interfaces (API) designed to allow Real Time Communication (RTC) using web-browsers without requiring plugins, downloads or installs.  The WebRTC is a part of HTML 5 that offers web application developers the ability to write rich, real-time multimedia applications on the web using simple JavaScript APIs and HTML. 

Background

Google Inc. started WebRTC as a royalty free project. The WebRTC standard solves a common problem for video communication in today’s trends 1). Incompatibilities for real-time communications, with a goal to build a standards-based real time media engine implemented in all of the available browsers, 2).  WebRTC leverages the recent trend in which the web browser is the main “application-runtime”.


Figure 1, WebRTC enabled browsers communicating with different Applications [1].
A WebRTC enabled browser can leverage any signalling system through a web-service that can direct the browser to establish a voice or video RTP connection to another WebRTC enabled device or media server. Once the initial connection is established the WebRTC APIs and the media engine defines and controls the communications path.
To achieve fully immersive video-calling solution WebRTC API standard can be split in to two layers. 

The web application layer

Much of the promise of WebRTC is in the fact that it provides APIs from the browser to the underlying hardware. The web-application developers can communicate with the WebRTC API by calling a set of simplified JavaScript methods. The programming methods are directed to the driver interfaces that provide controls to underlying microphones, and video capture hardware etc.
With WebRTC enabled in a browser (both mobile and desktop), developers can:
·       Capture camera or microphone streams directly from a browser using only JavaScript.
·       Make browser-to-browser calls (audio and/or video).
·       Share data (no server in the middle) to enable peer-to-peer apps (e.g. text chat, gaming, image sharing especially during calls)

The Browser Layer
To implement the code that will allow web browser engines to respond to the JavaScript API calls; A WebRTC stack is also available as a C++ API that allows browsers to capture and hook hardware resource at their disposal.

Figure 2, WebRTC application stack [2]
   

WebRTC support in desktop browsers

·       For the PC, the WebRTC is currently built into the latest Google Chrome version 32.0.0, Opera 18+, Firefox version 27.0, and Internet Explorer using a WebRTC compatible CU-RTC-Web API, a Microsoft implementation of WebRTC like library [3].
·       For Linux based desktops WebRTC is available in the current Chromium version 29.0.0 (beta) Chrome 31.0.0 and Firefox 27.0. 
·       For Apple Mac, the native browser Safari does not support WebRTC. The WebRTC support is available through the latest Google Chrome, Firefox and Opera 18+, but none of the browser’s supports 100% of the WebRTC API functions. A current implementation status WebRTC functions can be viewed in Figure.3. 



Figure 3, current status of WebRTC functions implemented [2][4].

Other than the browser base support on the Mac, there are also few bespoke implementations of WebRTC available for Apple Macs e.g. TenHands, a startup video conferencing company, has embedded their WebRTC capability into FaceTime. The Vidtel is another a cloud based video bridge provider and has already incorporated the WebRTC stack in their Mac SDK. 



1             WebRTC on Mobile Platforms

1.1        Android
Both Google chrome and Mozilla Firefox browsers are fully supported on android platform. Firefox WebRTC support is in its infancy and it has few bugs running a full WebRTC session; such as, issues with echo cancellation, CPU overutilization and video frame occasional out of sync issues [5, 6, 7].

1.2         Apple iOS
Apple iOS is the 2nd most used mobile platform with millions of people using iOS devices. Apple’s take on web browsers for iOS devices is different than other platform. Apple's development agreement makes sure that only iOS’s default browser Safari can be used as a backend engine for any browser running on iOS.  Google Chrome is available for iOS devices but it’s restricted from using the Google’s latest WebKit or Blink rendering engine.  A Google-Chrome running on an iOS device does not use the V8 JavaScript engine and it does not have a multi-process architecture. The iOS limitations make sure that all third-party browsers are built using UIWebView, so they use the same rendering and JavaScript engine. Among other issues such as Safari’s browser engine is slower than the competition it also does not support WebRTC without any apparent roadmap to support it.  
While reviewing the limitations of browsers on iOS it should also be kept in mind that consumption on smartphones especially iOS takes place more using dedicated apps than in the web-browser.
Following are the few vendors that implement WebRTC either as a dedicated app or plugin for WebRTC.

1.2.1      Bowser

Bowser is an experimental implementation of WebRTC on iOS and Android, developed by Ericsson Research [8]. Bowser is not only an App but also a dedicated WebRTC-enabled browser for mobile devices. ‘Bowser’ web browser is based on an Open Source project called the "WebRTC3”, which is being developed within the World Wide Web Consortium and the Internet Engineering Task Force (IETF).

1.2.2      Bistri

Bistri is a simplified one-link solution to enable mobile communication between web browsers by sharing a URL, which can be sent in an email or shared using an IM. Its based on WebRTC technology and it has their service available for web, iOS and Android [9].

1.2.3      TokBox

TokBox provides hosted cloud infrastructure, APIs and pre-configured tools required to deliver enterprise-grade WebRTC capabilities. It does so primarily through its proprietary OpenTok video platform for commercial application. The latest version of OpenTok 2.0 iOS SDK allows OpenTok based WebRTC video sessions in apps built for iPad, iPhone, and iPod touch devices.
Telefonica recently acquired TokBox. The majority of the customer base for TokBox is with vendors who have used their services to add an interactive layer of interface to personalize interaction with their online customers, using just a web-browser [10].

1.2.4      AddLive

AddLive is another simple SDK that can be used to integrate live video, voice and text chat into applications using WebRTC ecosystem. The AddLive SDK support both iOS and Android.

1.2.5      Voxeo

Voxeo Corporation is a telecommunication company that specializes in providing development platforms for unified customer experience (self-service) and unified communications (real time communications) applications. Voxeo has a proprietary SDK for iOS called Phono. The Phono ‘Cordova’ plugin adds the power of Phono [11] to mobile app using the PhoneGap application framework for iOS devices.

1.2.6      Twilio

Twilio Mobile SDK for iOS and Android has used WebRTC to deliver an Internet base telecommunication service. Working on a on a marketing pitch of making any device a phone, they provide local phone numbers with SMS and video/voice call facility in over 17 countries [12].
To provide WebRTC integration Twilio has developed a very stable SDK called Twilio-Cliet. Twilio-Client iOS is an Objective-C library for iOS that enables voice communications with landlines or other Twilio Client devices, including web browsers and other mobile devices.

1.2.7      OpenClove

OpenClove is a mobile tech company that delivers cloud-based mobile and video communication platform. OpenClove online video exchange (OVX)  is the first cloud based video MRF with WebRTC support enabling video in any web or mobile application. OpenClove’s video cloud platform is complete with APIs has not only an SDK for iOS (and Android) [14] but also an established app of their own, called ‘LiveBoard’.

1.2.8      Hookflash

Hookflash is another cloud based voice communication solution. It provides an RTC toolkit that comes with WebRTC enabled SDKs for iOS, Android and now Blackberry 10. It also has an implementation for P2P signaling protocol that allows WebRTC to setup an complete PBX integration without a centralized server [15].

1.2.9      EasyRTC

EasyRTC is the only full-stack open source WebRTC Solution. It comprises of a toolkit suitable for building secure, enterprise WebRTC applications. The SDK provides a bundle of web applications, code snippets, client libraries and server components meticulously written and documented to work right out of box [16].

   References
·       [1] – http://www.tmcnet.com/
·       [2] – www.webrtc.org
·       [3] – CU-RTC-WEB Microsoft flavored implementation of WebRTC http://lists.w3.org/Archives/Public/public-webrtc/2012Oct/att-0076/realtime-media.html
·       [4] - http://iswebrtcreadyyet.com/
·       [9] - https://bistri.com/
·       [11] - http://phono.com
·       [13] - http://easyrtc.com/
·       [15] - http://hookflash.com/
·       [16] - http://www.easyrtc.com