Tuesday, February 11, 2014

Conditional Compilation in Delphi

Conditional Compilation in Delphi

Conditional compilation is based on the existence and evaluation of constants, the status of compiler switches, and the definition of conditional symbols.

Conditional symbols work like Boolean variables: they are either defined (true) or undefined (false). Any valid conditional symbol is treated as false until it has been defined. The {$DEFINE} directive sets a specified symbol to true, and the {$UNDEF} directive sets it to false. You can also define a conditional symbol by using the -D switch with the command-line compiler or by adding the symbol to the Conditional Defines field on the Project > Options > Delphi Compiler page.

The conditional directives {$IFDEF}, {$IFNDEF}, {$IF}, {$ELSEIF}, {$ELSE}, {$ENDIF}, and {$IFEND} allow you to compile or suppress code based on the status of a conditional symbol. {$IF} and {$ELSEIF} allow you to base conditional compilation on declared Delphi identifiers. {$IFOPT} compiles or suppresses code depending on whether a specified compiler switch is enabled.

For example, the following Delphi code snippet processes differently depending on whether the DEBUG conditional define is set. You can set conditional defines on the Project > Options > Delphi Compiler page or by entering {$DEFINE DEBUG} in your code:

{$DEFINE DEBUG}
{$IFDEF DEBUG}
  Writeln('Debug is on.');  // This code executes.
{$ELSE}
  Writeln('Debug is off.');  // This code does not execute.
{$ENDIF}

{$UNDEF DEBUG}
{$IFNDEF DEBUG}
  Writeln('Debug is off.');  // This code executes.
{$ENDIF}

Note: Conditional symbols are not Delphi identifiers and cannot be referenced in actual program code. Similarly, Delphi identifiers cannot be referenced in any conditional directives other than {$IF} and {$ELSEIF}.

Note: Conditional definitions are evaluated only when source code is recompiled. If you change a conditional symbol's status and then rebuild a project, source code in unchanged units may not be recompiled. Use Project > Build All Projects to ensure that everything in your project reflects the current status of conditional symbols.

Monday, February 10, 2014

How to open and close datasets in Delphi? Difference between Open Method and Active Property in Delphi

How to open and close datasets in Delphi? Difference between Open Method and Active Property in Delphi

To read or write data in a dataset in Delphi, an application must first open it. You can open a dataset in two ways:

1. Open method: Call the Open method for the dataset at run time.
2. Active Property: Set the Active property of the dataset to True, either at design time in the Object Inspector, or in code at run time.

After performing operations on datasets, you must close them. You can close a dataset in two ways:

1. Close method: Call the Close method for the dataset at run time.
2. Active Property: Set the Active property of the dataset to False, either at design time in the Object Inspector, or in code at run time.

For example, if you have dsSample dataset in your code. You can open it like:

dsSample.Open;
dsSample.Active := True;

and close it like:

dsSample.Close;
dsSample.Active := False;

Difference between Open and Active

1. Open is a methods and Active is a property.

2. Open method is generally used at runtime while Active property is used to open dataset at design time. Active deals with Object Inspector. Without having Active property you wouldn't be able to open the dataset at design time because you cannot publish method to the Object Inspector.

3. Open method is much more readable than evaluating what's assigned to the Active property.

4. Active property calls Open method internally.

5 Advantages and Disadvantages of Software Developer Job

5 Advantages and Disadvantages of Software Developer Job 

No job is perfect. Every job has some advantages and disadvantages. If you are enjoying your job, that job is best for you. You should carefully choose a right career for you as it can make your life heaven or hell. If you have chosen for becoming a software developer, you must know the pros and cons of this career. I would like to share the advantages and disadvantages of software developer's job.

Advantages of Software Programming Job

1. Good Pay: As compared to other jobs and professions, software programming job's pay is high.

2. Portable Skills: You learn a lot of things like programming language, software tools etc. in one company and can apply that knowledge in another company. When you switch from one company to another, you also get a good salary hike.

3. Work Anywhere: You can work from anywhere. All you need is one laptop and the internet connection. Work From Home is a very good facility in this field.

4. Comfortable Working Environment: You work in a very comfortable environment. You always have access to fast internet connection. You always have air condition office, nice comfortable chair. You don't have to worry about the harsh weather conditions outside. Heavy rainfall, hailstorm, cold snow, hot or cold weather cannot affect your work.

5. Continuous Learning Curve in all directions: You always keep on learning new things in your office, in your project. Your knowledge continuosly increases with your experience. You always remain updated with the new technologies and inventions.

Disadvantages of Software Programming Job

1. Global Competition and Outsourcing: We live in a very well connected world. Every body in any corner of the world is well connected with each other through emails, messengers etc. There is great IT workforce in India which can do the same job in less money as compared to the developers in USA and Europe. Almost every IT company outsources its lot of work to India to reap benefits by utilising the talent of India and saves a lot of money. So, the competition in this field is global and you have to be very perfect to cope this.

2. You have to upgrade your skills continuously: Technology is changing every day. Everyday, there are new enhancements, everyday there is new invention. You have to keep yourself very active and updated otherwise you will be left behind in the race. You have to learn new thing everyday. You should learn to adapt with new things. Standing rigid with the old things will make you lose the competition. Keep on learning new programming languages and always add new thing to your resume.

3. Sitting Job: You have to sit tight to your desk and stare at your computer continuously. If this is not fine for you, you should not come to this profession. But today, other jobs are also becoming like this. So you will find this kind of scenario in each and every job. It can make you unhealthy very easily.

4. Age Discrimination: There is a lot of age discrimination in the software programming field. Many people think that a person above 40 would not be able to perform well. Preference is given to the young developers because it is assumed that they have fresh mind and would be able to solve the programming puzzles and tricks easily as compared to the old brains. Also young developers will cost less to the companies.

5. Long hours, Tight deadlines and no personal and social life: In IT field, you are bound to the tight deadlines and have to work for long hours and on weekends to meet the deadlines. Most of the Software developers have to sacrifice their personal and social life to make the deliveries on time. 

Friday, February 7, 2014

Should Interviewers ask Puzzles to Software Developers in an Interview to evaluate their skills?

Should Interviewers ask Puzzles to Software Developers in an Interview to evaluate their skills?

Programming is not about writing lines of code, it is about solving problems for the people. Some interviewers ask puzzles in an attempt to gauge software developer's ability and approach to solving problems. Puzzles can be useful in assessing problem solving skills, which is of course one of the key aspects of programming. Interviewer's expectations in that case are to hear you articulate your approach to the problem. What other data would you try to gather? How would you test your hypothesizes, etc. The point of asking the puzzles is to watch how developers work toward the solution, not necessarily if they get the right answer. You can spot good programmers pretty quickly just by watching this process. The interviewer must have been referring to problem solving and logic skills, which is part of the everyday work of a programmer. When given a problem, you need to be able to analyze it, subdivide it, and write a solution for it by using the most optimal approach.

Personally, I don't think that such puzzles provide an accurate indicator. I cannot understand the connection between such puzzles and programming. In the "real world", you have more than five minutes to figure out if your dealing with a bin packing vs a back pack problem, for instance. Initially, it's sometimes easy to misunderstand the problem at hand until you're in the middle of applying the wrong solution. That happens to people with 1, 5, 10 or even 20 years of experience.

The best interview 'puzzles' are the ones where you sit down at a computer to solve a problem in the domain in which you claim expertise. I also dislike the "Well, a programmer should be able to ..." thinking because it doesn't take into consideration that people get anxious when hit with something unexpected in a setting that is already stressful. Sure, you could solve that if you had time to think about it.. and perhaps you could solve it faster if you realized that your life would be over if you didn't. Do you want to work somewhere where your life will be over if you can't solve problems in five minutes? Will you get fired if you can't?

Should all great programmers also be champion sudoku solvers? I'm sure that plenty are, but it's not like some kind of prerequisite for competency.

I'm not saying that you should not be tested on how you approach problems, but the tests should be fun and invite the 'best' that the applicant has to give, given their area of expertise. Proving that you are as smart as a character that Bruce Willis portrays seems kind of pointless, considering that producers spent a pretty sum to get that scene just right.

These sorts of puzzles are generally used by interviewers who neither know what they are doing nor how to look for developers? These are just voodoo hiring practices. Some interviewers ask these questions so they feel like they are supposed to. They know that not answering the question is "bad" and answering is "good", but they can't tell you why beyond non-answers like "a developer needs these skills". They are a waste of time and an indicator that the interviewer is not a competent interviewer. In other words, if you detect that you're being interviewed by someone who has little comprehension over what you'll actually be doing, excuse yourself to go to the restroom and never return.

Suggestion to Interviewers

It is far better to ask coding questions to the software developers. In other words, you need to ask questions that allow you to explore the skills and behaviour of the software developer as they try and tackle the problem. Asking silly puzzles instead of coding philosophies will not give you any indication about how good that person is for the job.

Always try to make the applicant feel as comfortable as possible, so that you can actually try to find out how good that person will be for the job. The best programmers are those who understand the dynamics of software development, even if they don't have the highest IQs.

Tuesday, February 4, 2014

Amazon AWS vs IBM SoftLayer: Why IBM cannot dominate Amazon as a Cloud Computing Services Provider?

Amazon AWS vs IBM SoftLayer: Why IBM cannot dominate Amazon as a Cloud Computing Services Provider?

Can IBM SoftLayer ever dominate Amazon AWS? Today, Amazon is the biggest Cloud Computing Services provider. Amazon AWS already has a number of large enterprises running production workloads on it, and the trend is accelerating. IBM is unquestionably a strong brand with deep customer relationships — it exerts a magnetism for its customers that competitors like HP and Dell don’t come anywhere near to matching. 

Why IBM SoftLayer cannot dominate Amazon AWS?

1. Is IBM SoftLayer worthy?

IBM's own cloud did not work, and now it has thrown out that strategy and is now pinning its hopes on SoftLayer, which was never a credible AWS competitor to begin with. IBM acquired SoftLayer last year and announced addition of more than 1,500 customers just after three months of its acquisition of SoftLayer.  It certainly helps immensely that SoftLayer is a more compelling solution than SCE, but customers continue to acknowledge that they don’t necessarily feel they’re buying the best solution or the best technology, but they are getting something that is good enough from a vendor that they trust. SoftLayer has always competed to some degree against AWS (philosophically, both companies have an intense focus on automation, and SoftLayer’s bare-metal architecture is optimal for certain types of use cases), and IBM SoftLayer will as well.

2. Amazon is not limited by the traditional IT constraints

The fact that Amazon does not have a long history in enterprise IT is precisely why it's the preferred public cloud solution. It doesn't have legacy baggage, so is not limited by the traditional constraints we place on IT and IT technology providers such as IBM. Amazon AWS is also very disruptive to traditional enterprise vendors because Amazon doesn't care all that much about profit margins. Amazon's stated strategy is to invest more money in growing market share and capability rather than taking profits. Amazon was able to build its offering from the market requirements up. It doesn't have to deal with maintaining synergy with existing and ageing product lines, nor does it have to deal with the internal politics as IBM does.

3. IBM won't beat Amazon -- or the other major cloud providers, for that matter -- because IBM is, well, IBM. IBM has done a poor job in both understanding the cloud computing marketplace and providing compelling products to capture the market.  Although IBM does understand the enterprise and certainly has the sales force to go sell stuff to enterprises, it doesn't have a culture prepared to promote public cloud services, which are very different than enterprise hardware and software. 

In addition, the more cloud services that IBM sells, the less money it will make. In essence, it will displace existing IBM hardware and software with its own public cloud offering. If not, Amazon, Microsoft, Rackspace, and Google will displace IBM hardware and software. It's truly a no-win situation for IBM, but other large enterprise providers are in the same boat.

Statistics

If you go with a cloud services only argument, AWS is twice as large as IBM. If you include hardware in the cloud revenue equation, the two are about equal on revenue give or take a few million. IBM claims that IBM Cloud supports 270,000 more Web sites than Amazon and supports 24 of the top 25 Fortune 500 companies. Amazon took in around 35 percent of the $1.2 billion spent globally on public IaaS in the fourth quarter of 2012, and IBM came in a distant second with 5 percent, according to Synergy Research Group. Other studies show the same (or worse) for IBM, with a few analyst firms leaving IBM off the research altogether, instead naming Rackspace, Microsoft, and Google as Amazon's true competitors. Gartner states that Amazon AWS has 5 times the size of the next 15 cloud vendors combined. 

As for pricing comparison's IBM's SoftLayer has the most AWS-ish pricing schemes. SoftLayer's pricing is transparent. IBM's other cloud calculators take a bit more work. The biggest takeaway is that AWS is on its enterprise rivals radar in a big way.

Conclusion

IBM SoftLayer has a strong value proposition for certain use cases, but today their distinctive value proposition is a different one than AWS’s, but a very similar one to Rackspace’s. But IBM SoftLayer is still an infrastructure-centric story. I don’t know that they’re going to compete with the vision and speed of execution currently being displayed by AWS, Microsoft, and Google, but ultimately, those providers may not be IBM SoftLayer’s primary competitors.

AngularJS vs Ember vs Backbone: Which Javascript Framework to choose for Front-end Web Development?

AngularJS vs Ember vs Backbone: Which Javascript Framework to choose for Front-end Web Development?

I have tried to compare three most widely used Javascript frameworks like AngularJS, Ember and Backbone in terms of their performance, model mutation, template engine, testability, easy to learn and implement etc. Which javascript framework to choose for front-end web development is mainly decided by the nature of your application, what functionalities do you want to achieve in your application and your hold on the Javascript framework. Let's try to understand the difference between the various features of AngularJS, Ember and Backbone.

1. Templates

Backbone: In backbone, you can choose your own template engine, no matter whether it’s String or DOM based. Usually people prefer handlebars.js, a string-based template library.

Ember: It uses built-in string-based templates (mandatory). Arguments in favor of string-based templates include “it’s faster” (debatable) and “theoretically, the server can render them too” (also debatable, as that’s only true if you can actually run all of your model code on the server, and nobody generally does that in practice).

AngularJS: Angular uses built-in DOM-based templates (mandatory). DOM-based templates means doing control flow (each, if, etc.) purely via bindings in your actual markup and not relying on any external library. Argument include “it’s faster” (debatable) and “the code is easier to read and write”

In AngularJS, the DOM structure is created on pageload. Suppose you have multiple templates in your page and you don’t want to show them at a time. In that case also you have to define those at page load lavel, if you use angular, which will unnecessary create few extra DOM elements. But in Ember you can insert dynamic templates as it uses string based templating method. So in this perspective Ember and Backbone’s string-based templating may go handy, but if you talk about data binding, DOM-based templates provides you better performance. According to the Angular developers’ team, in near future DOM-based templating will be natively supported on browsers and when this happens, Angular apps will run way too faster, so we should best prepare ourselves for the future by adopting it now. AngularJS is from Google, so they are already working on this with Chromium and standards bodies.

2. Model Mutation

Backbone & Ember: In model mutation both Backbone and Ember follows almost the same structure and flow. They use getters and setters to get or set a value and this is also an efficient way to learn the model change and accordingly reflect it to view. But while rendering the data elements, ember adds observers to each element. As the observers are heavy, so it makes the rendering process slower.

AngularJS:  Angular doesn’t use the traditional getters and setters like backbone and ember, rather it uses Dirty Checking to learn the model change, which is way too faster (according to the angular team).

AngularJS uses Dirty Checking, which is based on the lexical scoping in js and helps in garbage collection too. Not only that, angular lets all the model mutation to happen first and then inform all the listeners in a consistent state. This helps to prevent wrong data operations.

3. Performance

Performance is something, which you just can’t judge only basing on the pros and cons of the framework. Rather, it completely depends on your needs and the type of app you are developing. The key performance judging factors are given in the examples below.

Eg 1: Suppose, in your app, you are using huge number of data. So if you use ember, you will find the app is taking too much time to get loaded; and that’s because ember adds observers to each element. So this thing makes the rendering very slow in comparison with backbone and angular. But once the app is loaded, and you expecting your view to reflect the model change immediately; well angular will make you sad. Because, as it don’t have an observer attached with each element, so to learn the data change, the angular controller has to traverse the whole data model (dirty checking). But if your app doesn’t depend on fast data binding; rather you want your app to load faster, angular is the best option.

Eg 2: AngularJS is sort of a HTML compiler. It has the power to manipulate the normal behaviour of your HTML. Suppose, you are printing the data of your model one by one using {{#each}} helper in ember (actually in handlebars), or using the ‘For’ loop of backbone. In this case ember will run a loop to print them; and as you know, loops are always heavy and time consuming operations. But in a similar situation, angular’s ‘ng-repeat’ will fetch the data as a whole and will put it directly on your html. This is a much faster process.

Eg 3: Suppose your app is a continious animation based app, where you have to perform some animation to each element in your model (let your model has the instances of few html elements or something similar to that). So here, ember’s observers will be of no use; cause no matter what, you have to change the model and view continuously. So angular’s continuous checking or dirty checking may play a role for you here.

So, this is how, performance is a variable thing, which varies from projects to projects, scenarios to scenarios, environments, dependencies and many more. So only that framework can give you best performance which is the most compatible one to your app.

4. Learning & Development

Backbone: Basic backbone is very easy to learn, but while developing, you will find it was not enough. Because only using backbone you can’t structure your code much. It needs more libraries and templates to make a proper project.

Ember: Ember has more structured documents and it’s also not that tough to learn. Its implementation (with handlebars) is much similar to the other process and object oriented programming.

AngularJS: Angular is a little tricky, because it’s somewhat an extension of HTML. But once you get this html processing, it will become the simplest framework to learn.

AngularJSis comparatively simple to learn, and more simple to develop. A friend of mine made a widget on backbone, which was of more than 3800 lines. It has come down to 725 lines when rewritten in Angular. And the code was more structured and clean. Simplicity is one of the best plus points of Angular.

5. Testability

Testing is possible on all the frameworks, if you learn the right pattern to develop your project. Your modularity and ability of dependency injection are the key parts to have a testable code. And modularity and dependency injection are two of the major features of angular. Angular itself was built keeping the testing facility in mind. So I think, in testability angular is ahead of Backbone and Ember.

6. Projects point of view

While developing, or before starting the development of a project you need to keep in minds many points; and these really plays the role behind the selection of the framework.

There was a time when the codes of backbone seemed to be very clean and structured. But ember and angular showed the codes can be more cleaner and structured. Let’s watch these three frameworks as project developers point of view.

Backbone: Maximum people has worked with backbone; so it’s much easier to found an experienced backbone developer. There are lot of help available there in the net about backbone. It won’t cost you much to train your people. So in this point of view, backbone is good.

Ember: The best thing about ember is, if forces you to follow the ember way; and if you don’t, the app will never run. Though for beginners it will be a headache; but the best thing is; as everyone will follow the same way to develop the app, so it will be well structured and very very easy to maintain in future. Everyone is not a good coder; and humans always like shortcuts. So, if you are developing a huge project with lots of developers, they can’t code any logic wherever they want. They have to strictly follow the MVC structure and ember’s way of coding.

AngularJS: What if you don’t have much time to develop your project? Not much time to learn frameworks? Then you must go with the angular way. Angular also makes the code much more cleaner, structured and maintainable if the developer has knowledge of MVC development. It reduces the lines of codes like anything.

Conclusion

It’s not like a single framework will be always the best one. I’ve also given examples for that in this article. There are lot of factors you need to take care of before selecting the javascript framework for your application. I’m working in a travel service company right now and we selected Ember over Angular for our development, because it was more suitable to our previous architecture and widget based development. Similarly lot other environmental factors will come.

Every framework has its pros and cons. But what we need to consider is, the requirement list of our project and the adaptability of the framework on those requirements. But as an overall view, I’ve found out angular is very easy to learn (even a guy who didn’t work much with MVC and just knows simple HTML and javascript, can learn it very easily); it reduces the number of lines in your code more than backbone and ember; if your data model is not huge, it provides you fast rendering and execution; manipulates the DOM directly; makes your code testable and lot more. That is why I’m considering Angular a better option than Ember and Backbone generally.

Monday, February 3, 2014

Basic AngularJS Interview Questions and Answers for Front-end Web Developers

Basic AngularJS Interview Questions and Answers for Front-end Web Developers

AngularJS is widely known Javascript framework. If you are a front-end web developer preparing for AngularJS interview, following basic AngularJS interview questions and answers might help you little bit. Before going to AngularJS interview, you should know basic concepts and architecture of AngularJS, key features of AngularJS, how AngularJS is different from jQuery or other Javascript frameworks etc. Following basic AngularJS interview questions and answers will give you little insight of these concepts.

1. Why is this project called "AngularJS"? Why is the namespace called "ng"?

Because HTML has Angular brackets and "ng" sounds like "Angular".

2. Is AngularJS a library, framework, plugin or a browser extension?

AngularJS fits the definition of a framework the best, even though it's much more lightweight than a typical framework and that's why many confuse it with a library.

AngularJS is 100% JavaScript, 100% client side and compatible with both desktop and mobile browsers. So it's definitely not a plugin or some other native browser extension.

3. Why to choose AngularJS Javascript Framework for front-end web development?


4. What are the key features of AngularJS?

Scope

The job of the Scope is to detect changes to model objects and create an execution context for expressions. There is one root scope for the application (ng-app) with hierarchical children scopes. It marshals the model to the view and forwards events to the controller.

Controller

The Controller is responsible for construction of the model and connects it to the view (HTML). The scope sits between the controller and the view. Controllers should be straightforward and simply contain the business logic needed for a view. Generally you want thin controllers and rich services. Controllers can be nested and handle inheritance. The big difference in AngularJS from the other JavaScript frameworks is there is no DOM manipulation in controllers. It is something to unlearn when developing in AngularJS.

Model

In AngularJS, a Model is simply a JavaScript object. No need to extend anything or create any structure. This allows for nested models  - something that Backbone doesn’t do out-of-the-box.

View

The View is based on DOM objects, not on strings. The view is the HTML. HTML is declarative – well suited for UI design. The View should not contain any functional behavior. The flexibility here is to allow for multiple views per Controller.

Services

The Services in AngularJS are singletons that perform common tasks for web applications. If you need to share common functionality between Controllers, then use Services. Built-in AngularJS, Services start with a $. There are several ways to build a service: Service API, Factory API, or the $provide API.

Data Binding

Data Binding in AngularJS is a two-way binding between the View and the Model. Automatic synchronizing between views and data models makes this really easy (and straightforward) to use. Updating the model is reflected in View without any explicit JavaScript code to bind them together, or to add event listeners to reflect data changes.

Directives

Now this is cool. AngularJS allows you to use Directives to transform the DOM or to create new behavior. A directive allows you to extend the HTML vocabulary in a declarative fashion. The ‘ng’ prefix stands for built-in AngularJS directives. The App (ng-app), Model (ng-model), the Controller (ng-controller), etc. are built into the framework. AngularJS allows for building your own directives. Building directives is not extremely difficult, but not easy either. There are different things that can be done with them. Please check out AngularJS’s documentation on directives.

Filters

The Filters in AngularJS perform data transformation. They can be used to do formatting (like I did in my Directives example with padding zeros), or they can be used to do filter results (think search).

Validation

AngularJS has some built-in validation around HTML5 input variables (text, number, URL, email, radio, checkbox) and some directives (required, pattern, minlength, maxlength, min, max). If you want to create your own validation, it is just as simple as creating a directive to perform your validation.

Testable

Testing is a big concern for enterprise applications. There are several different ways to write and run tests against JavaScript code, thus against AngularJS. The developers at AngularJS advocate using Jasmine tests ran using Testacular. I have found this method of testing very straightforward and, while writing tests may not be the most enjoyable, it is just as importable as any other piece of developing an application.

5. What is a scope in AngularJS?

scope is an object that refers to the application model. It is the glue between application controller and the view. Both the controllers and directives have reference to the scope, but not with each other. It is an execution context for expressions and arranged in hierarchical structure. Scopes can watch expressions and propagate events.

6. Can you explain the concept of scope hierarchy? How many scopes can an application have?

Each Angular application has exactly one root scope, but may have several child scopes. The application can have multiple scopes, because child controllers and some directives create new child scopes. When new scopes are created, they are added as children of their parent scope. This creates a hierarchical structure similar to the DOM where they're attached.

When Angular evaluates a bound variable like say {{firstName}}, it first looks at the scope associated with the given element for the firstName property. If no such property is found, it searches the parent scope and so on until the root scope is reached. In JavaScript this behaviour is known as prototypical inheritance, and child scopes prototypically inherit from their parents. The reverse is not true. i.e. the parent can't see it's children's bound properties.

7. Is AngularJS a templating system?

At the highest level, Angular does look like a just another templating system. But there is one important reason why the Angular templating system is different, that makes it very good fit for application development: bidirectional data binding. The template is compiled in the browser and the compilation step produces a live view. This means you, the developers, don't need to write code to constantly sync the view with the model and the model with the view as in other templating systems.

8. Do I need to worry about security holes in AngularJS?

Like any other technology, AngularJS is not impervious to attack. Angular does, however, provide built-in protection from basic security holes including cross-site scripting and HTML injection attacks. AngularJS does round-trip escaping on all strings for you and even offers XSRF protection for server-side communication.

AngularJS was designed to be compatible with other security measures like Content Security Policy (CSP), HTTPS (SSL/TLS) and server-side authentication and authorization that greatly reduce the possible attack vectors and we highly recommended their use.

9. What's Angular's performance like?

The startup time heavily depends on your network connection, state of the cache, browser used and available hardware, but typically we measure bootstrap time in tens or hundreds of milliseconds.

The runtime performance will vary depending on the number and complexity of bindings on the page as well as the speed of your backend (for apps that fetch data from the backend). Just for an illustration we typically build snappy apps with hundreds or thousands of active bindings.

10. Does Angular use the jQuery library?

Yes, Angular can use jQuery if it's present in your app when the application is being bootstrapped. If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.

Due to a change to use on()/off() rather than bind()/unbind(), Angular 1.2 only operates with jQuery 1.7.1 or above.

11. What are the key differences between AngularJS and jQuery?


12. How will you compare AngularJS with other Javascript frameworks like Ember and Backbone?

Read complete answer

13. How will you display different images based on the status being red, amber, or green?

Use the ng-switch and ng-switch-when directives as shown below.

<div ng-switch on="account.status">
 <div ng-switch-when="AMBER">
  <img class="statusIcon"
   src='apps/dashboard/amber-dot.jpg' />
 </div>
 <div ng-switch-when="GREEN">
  <img class="statusIcon"
   src='apps/dashboard/green-dot.jpg' />
 </div>
 <div ng-switch-when="RED">
  <img class="statusIcon"
   src='apps/dashboard/red-dot.jpg' />
 </div>
</div>

14. How will you initialize a select box with options on page load?

Use the ng-init directive.

<div ng-controller="apps/dashboard/account" ng-switch
 on="!!accounts" ng-init="loadData()">

15. How will you show/hide buttons and enable/disable buttons conditionally?

Using the ng-show and ng-disabled directives.

<div class="dataControlPanel"
    ng-show="accounts.releasePortfolios">
     
    <div class="dataControlButtons">
     <button class="btn btn-primary btn-small"
      ng-click="saveComments()" ng-disabled="disableSaveButton">Save</button>
     <button class="btn btn-primary btn-small"
      ng-click="releaseRun()" ng-disabled="disableReleaseButton">Release</button>
    </div>
</div>

16. How will you loop through a collection and list each item?

Using the ng-repeat directive.

<table
  class="table table-bordered table-striped table-hover table-fixed-head portal-data-table">
  <thead>
   <tr>
    <th>account</th>
    <th>Difference</th>
    <th>Status</th>
   </tr>
  </thead>
  <tbody>
   <tr
    ng-repeat="account in acounts">
    <td width="40%">{{account.accountCode}}</td>
    <td width="30%" style="text-align: right">{{account.difference
     | currency: ""}}</td>
    <td width="30%">

     <div ng-switch on="account.status">
      <div ng-switch-when="AMBER">
       <img class="statusIcon"
        src='apps/dashboard/amber-dot.jpg' />
      </div>
      <div ng-switch-when="GREEN">
       <img class="statusIcon"
        src='apps/dashboard/green-dot.jpg' />
      </div>
      <div ng-switch-when="RED">
       <img class="statusIcon"
        src='apps/dashboard/red-dot.jpg' />
      </div>
     </div>

    </td>
   </tr>
  </tbody>
</table>

17. How will you add options to a select box?

Using the ng-options and ng-model directives.

<fieldset>
 <dl class="control-group">
  <dt>
   <label for="cientId">
    <h4>Client Id:</h4>
   </label>
  </dt>
  <dd>
   <select id="cientId" class="input-xlarge" ng-model="clientId"
    ng-options="reportClient.clientId as reportClient.clientId  for reportClient in reportClients "
    ng-click="getReportParams()" ng-change="getValuationDates()" />
  </dd>
 </dl>
 <dl class="control-group">
  <dt>
   <label for="valuationDate">
    <h4>
     Valuation Date <small>(dd/mm/yyyy)</small>
    </h4>
   </label>
  </dt>
  <dd>
   <select id="valuationDate" class="input-xlarge"
    ng-model="valuationDate"
    ng-options="reportdate for reportdate in reportDates" />
  </dd>
 </dl>
</fieldset>

18. How will you display inprogress revolving image to indicate that RESTful data is bing loaded?

<div ng-show="loading">
 <img class="loading" src="portal/images/loading_32.gif" />
</div>

 $scope.loadReportData = function($http) {
 $scope.loading = true;  // start spinng the image
 $http(
   {
    method : 'GET',
    url : propertiesService.get('restPath')
      + '/myapp/portfolio/'
      + $scope.clientId
      + '/'
      + dateService
        .userToRest($scope.reportDate),
    cacheBreaker : true
   }).success(
   function(data, config) {
    $scope.reportData = data;
    portal.log('reportData: ',
      $scope.reportData);
    $scope.loading = false;   // stop spinning the image
   }).error(
   function(data, status, headers, config) {
    if(data.errorMsg != null) {
     $scope.httpError = data.errorMsg;
    }
    else {
    $scope.httpError = "Error retrieving data from " + errorService
      .getApacheErrorTitleMessage(status,
        data, config);
       }
    $scope.loading = false;  // stop spinning the image
   });

};