Showing posts with label company. Show all posts
Showing posts with label company. Show all posts

Thursday, 9 June 2016

The 6 Best Blogs for a Software Developer

Blogs are not better than books. They are a different medium for the dissemination of knowledge, and certainly will not be replacing books. In fact, they compliment books quite nicely. The medium they seem to be replacing is periodicals.

Best Mobile App Company
Software Development Company in Gurgaon

Joel on Software - This is a great blog to get started reading software blogs. Joel Spolsky is an incredibly good writer. His ideas on software design and development, project management, and leadership are delivered with vibrant examples and clear reasoning. Plus, you get to experience the growth and development of his software company, Fog Creek Software, almost first hand. It's a fascinating look into how a real software company can start from almost nothing and grow organically through hard work and determination. I'll warn you, by the end you'll likely be convinced to start using his company's software products, or start your own company.

Mobile Development company in Delhi Noida & gurgaon
Android app development

Coding Horror - Whereas Joel clearly entered blogging with strong opinions and an excellent, fully developed writing style, Jeff Atwood seems to have started blogging with the intention of exploring and developing his ideas and improving his writing. His first posts were stilted and awkward, but with years of practice he became a great writer who could clearly express his thoughts with sharp reasoning and emotional force. It was inspiring to read along and witness his evolution as a writer and a software developer. During the course of the blog, an idea for a software company occurred to him and he decided to run with it. He partnered with Joel Spolsky and together they created Stackoverflow and the Stack Exchange network of Q&A sites. He went on to other pursuits as well. The entire progression of his career is an excellent read and quite enlightening.

Website development company in Delhi
Website development in Delhi


Paul Graham's Essays - Like Joel Spolsky, Paul Graham started blogging as an excellent writer. However, his focus is quite different. Instead of slowly growing a small company into a sustainable business, Paul writes convincingly for the flip side of the coin - the fast-growing startup. He relates his own experience running ViaWeb and selling it to Yahoo!, and shares an ongoing stream of great insights for running a successful startup. A few years into his blog, in the summer of 2005, he puts these ideas to the test by starting a startup school called Y Combinator. The school starts small, but after gaining a lot of inertia, it now turns out dozens of startups per year. Reading about the whole theory and process behind it helps you understand this part of the business world better, and it's a great contrast to the slow and steady way of starting a company.


Android development company
Mobile app development company India

Stevey's Blog Rants - Steve Yegge's articles are spread across multiple places. The bulk of them are at his Blogger site, but he also has some posts on his Google+ site (+Steve Yegge), and a bunch of articles that he wrote while working at Amazon are stored at Stevey's Drunken Blog Rants. He now works at Google, and he writes a lot about programming language design, working at large software companies, and staying current as a software developer. His posts are filled with wisdom, wit, and sarcasm, and they are long. He packs them so full of information, and he is so entertaining that I don't mind that a bit. He's worth a read if only to get a clear view of the programming language landscape delivered with a healthy dose of cutting satire.

Web development company India

The Conscience of a Liberal - This is not a technical blog, but it will flex your logic and reasoning skills. Paul Krugman's blog is a wickedly smart critique of modern economics and politics, and he doesn't pull any punches. If there's some policy he doesn't agree with, and there are many, he'll explain every deficiency and delinquency as clearly as you could possibly imagine. It doesn't matter if the ideas are coming from the left or the right, if the logic and reasoning are wrong, Krugman will neatly tear them apart. He always backs up his criticisms with solid data and a tremendous command of the English language, easily making him the best writer in this list. Reading him will teach you how to deliver an argument. He also shows a sharp wit combined with an expansive cultural knowledge that is always entertaining. The true mark of wisdom is shown when someone can explain complex topics simply enough that anyone can understand them, and Krugman delivers this in spades. This blog and his weekly columns are an extremely worthwhile read.

Bruce Bartlett - Economix Blog - Bruce Bartlett is a conservative economist who has served in the Reagan and Bush I administrations as well as the staffs of multiple Republican congressmen. His writings are a study in how to let the data do the talking, and he often advocates solutions that you wouldn't expect of a conservative. His reasoning is always straightforward and nonsense-free, and he has an amazing store of political and economic historical knowledge that gives his writing excellent context. He steadfastly lets the facts determine the most rational policy recommendations without letting his own subjectivity intrude. Reading his posts will give you a firm appreciation for careful analysis and measured conclusions.

Tuesday, 27 October 2015

Promises in AngularJS. Part II. $q service.

I have already blogged about Promises in AngularJS 1.x. This is the second part which describes the Angular's $qservice. The $q service can be used in two different ways. The first way mimics the Q library for creating and composing asynchronous promises in JavaScript. The second way mimics the ECMAScript 2015 (ES6) style. Let's begin with the first way. First of all, you have to create a deferred object by $q.defer()
?
1
2
3
  
var deferred = $q.defer();
  
deferred object can be created within an asynchronous function. The function should return a promise object created from the deferred object as follows: 
?
1
2
3
A promise is always in either one of three states:
  1. Pending: the result hasn't been computed yet
  2. Fulfilled: the result was computed successfully
  3. Rejected: a failure occurred during computation
When the asynchronous function finished the execution, it can invoke one of the two methods: 
?
1
2
deferred.resolve(...)
deferred.reject(...)
The first call deferred.resolve(...) puts the promise into the fulfilled state. As result a success callback will be invoked. The second call deferred.reject(...) puts the promise into the rejected state. As result an error callback will be invoked. It is also possible to invoke 
?
1
2
3
  
deferred.notify(...)
  
during the function's execution to propogate some progress from the asynchronous function to an update callback. All three callbacks can be registered on the promise as parameters of the function then
?
1
2
3
4
5
6
7
8
9
10
11
var promise = someAsynchronousFunction();
promise.then(function(value) {
    // success
    ...
}, function(reason) {
    // failure
    ...
}, function(update) {
    // update
    ...
});
Let's implement an example. We will take setTimeout() as an asynchronous function. In the real application, you will probably use some other asynchronous services. In the setTimeout(), we will generate a random number after 1 sek. If the number is less than 0.5, we will invoke deferred.resolve(random), otherwise deferred.reject(random). The entire logic is implemented in the controller PromiseController
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var app = angular.module('app', []);
app.controller('PromiseController', PromiseController);
function PromiseController($q) {
    var _self = this;
    this.message = null;
    var asyncFunction = function() {
        var deferred = $q.defer();
        setTimeout(function() {
            var random = Math.random().toFixed(2);
            if (random < 0.5) {
                deferred.resolve(random);
            } else {
                deferred.reject(random);
            }
        }, 1000);
        return deferred.promise;
    }
    this.invokeAsyncFunction = function() {
        var promise = asyncFunction();
        promise.then(function(message) {
            _self.message = "Success: " + message;
        }, function(message) {
            _self.message = "Error: " + message;
        });
    }
}
As you can see, the asynchronous function asyncFunction is invoked in the controller's method invokeAsyncFunction. The function asyncFunction returns a promise. In the success case, the promise gets fulfilled and the first registered success callback gets executed. In the error case, the promise gets rejected and the second registered error callbackgets executed. The invokeAsyncFunction is bound to the onclick event on a button. 
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta content="IE=edge" http-equiv="X-UA-Compatible" />
    <script src="https://code.angularjs.org/1.4.8/angular.js"></script>
</head>
<body ng-app="app" ng-controller="PromiseController as ctrlPromise">
    <div ng-bind="ctrlPromise.message"></div>
    <p></p>
    <button ng-click="ctrlPromise.invokeAsyncFunction()">
        Invoke asynchronous function
    </button>
    <script src="controller.js"></script>
</body>
</html>
The message in GUI looks like as follows (success case as example):


The Plunker of this example is available here. Here is another picture that visualize the relation between methods of the deferred object:


As you can see, the asynchronous function doesn't return the deferred object directly. The reason for that is obvious. If the deferred object would be returned instead of deferred.promise, the caller of the asynchronous function could be able to trigger callbacks by invoking deferred.resolve(...)deferred.reject(...) or deferred.notify(...). For this reason these methods are protected from being invoking from outside by the caller.

The example above can be rewritten in the ECMAScript 2015 (ES6) style (I mentioned this way at the beginning). A promise in ECMAScript 2015 can be created as an instance of Promise object. 
?
1
2
3
4
5
6
7
8
var promise = new Promise(function(resolve, reject) {
    ...
    if(...) {
        resolve(value); // success
    } else {
        reject(reason); // failure
    }
});
Our asyncFunction function looks in this case as follows: 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var asyncFunction = function() {
    return $q(function(resolve, reject) {
        setTimeout(function() {
            var random = Math.random().toFixed(2);
            if (random < 0.5) {
                resolve(random);
            } else {
                reject(random);
            }
        }, 1000);
    });
}
The remaining code stays unchanged. Let's go on. The next question is, how can we produce a rejection in success or error callbacks? For instance, you check some condition in a callback and want to produce an error if the condition is not fulfilled. Sometimes, we also want to forward rejection in a chain of promises. That means, you catch an error via an error callback and you want to forward the error to the promise derived from the current promise. There are two ways to achieve this qoal. The first one consists in using the $q.reject(...) like shown below. 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var promise = someAsynchronousFunction();
promise.then(function(value) {
    // success
    ...
    if(someCondition) {
        $q.reject("An error occurred!");
    }
}, function(reason) {
    // failure
    ...
}).catch(function(error) {
    // do something in error case
    ...
});
In our example, we will adjust the function invokeAsyncFunction in order to check very small values (smaller than 0.1). 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
this.invokeAsyncFunction = function() {
    var promise = asyncFunction();
    promise.then(function(random) {
        if (random < 0.1) {
            return $q.reject("Very small random value!");
        }
        _self.message = "Success: " + random;
    }, function(random) {
        _self.message = "Error: " + random;
    }).catch(function(error) {
        _self.message = "Special error: " + error;
    });
}


A Plunker example is available here. Keep in mind the difference between deferred.reject(...) and $q.reject(...). The call deferred.reject(...) puts the corresponding promise into the rejected state. The call $q.reject(...) creates a new promise which is already in the rejected state.

The second way to produce a rejection in success or error callbacks consists in throwing an exception with throw new Error(...).
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
this.invokeAsyncFunction = function() {
    var promise = asyncFunction();
    promise.then(function(random) {
        if (random < 0.1) {
            throw new Error("Very small random value!");
        }
        _self.message = "Success: " + random;
    }, function(random) {
        _self.message = "Error: " + random;
    }).catch(function(error) {
        _self.message = "Special error: " + error;
    });
}
AngularJS will catch the exception, create a promise in the rejected state and forward it to the next block in the chain of promises. In the example, the error will be forwarded to the catch block. One downside of this approach with throw new Error(...) is that the error will be logged in the console. Picture from the Chrome Dev Tools:


But well, it works as designed and probably it is even an advantage to see thrown errors in the console. 

There is also an opposite method $q.when(...) which returns an immediately resolved promise. The documentation says: $q.when(...) "wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted." You can e.g. wrap an jQuery Deferred Object with $q.when(...) or simple write 
?
1
2
3
4
5
$q.when("Finished!").then(
    function handleResolve(value) {
        console.log("Resolved with value: ", value);
    }
);
and see Resolved with value: Finished! in the console. The alias of $q.when(value) is $q.resolve(value). This was introduced later in order to maintain naming consistency with ECMAScript 2015.

Last but not least is the method $q.all(promises) where promises is an array of multiple promises. This call returns a single promise that is resolved when all promises in the given array gets resolved. 
?
1
2
3
4
5
6
var promise1 = someAsynchronousFunction1();
var promise2 = someAsynchronousFunction2();
$q.all([promise1, promise2]).then(function(result) {
    console.log("Promises " + result[0] + " and " + result[1] + " finished their work successfully");
});
As you can see, the result passed into the callback function is an array of two outcomes - the outcome of the first and the outcome of the second callback.