Entity Framework

Entity framework is the new kid on the block on the ORM realm. It’s Microsoft new technology for data access, and although it didn’t receive very good comments on its first version, things have been greatly improved in its latest release. It now looks really interesting, with some features which surpass the most seasoned ORM frameworks that have been in the game for years.

Here’s what Entity Framework (EF) has to offer:

Read the rest of this entry »

ASP.NET 4.5 and Visual Studio 11

Back in September 2011 the next versions of ASP.NET and Visual Studio were announced. Microsoft has set up a page informing about all of the new features we can find in them. Check them out:

Read the rest of this entry »

Persistance layer: object-relational mapping tools

Nowadays it’s very usual to work with object-oriented programming and relational data bases. Relational data bases are all about tables, relations and groups. However, the object-oriented programming paradigm consists of objects, attributes and inter-object relationships. When these objects need to be stored using a relational data base, it’s very obvious that these two models of representing information are very different from each other. We need some kind of translation to transfer data from one to the other.

If we’re using objects in our application and we want to save them, we’ll probably use some data base system. We’ll most likely establish a connection to the data base, create a SQL sentence with the values of the object (or call some kind of stored procedure), and save them to some table. Easy enough, right? Well, this may seem trivial for a small object with 4 or 5 properties. Just consider an object not so small, with 40 or 50 properties. But… what happens with associations? And… what if the object itself contains some other objects? We’ll store them in the data base as well? All of them or just some? What will we do with foreign keys? We can see that, as the application gets more complex, this translation is not so trivial anymore… As a matter of fact, storing objects in the database can become a very usual source of headaches. There are some studies which state that up to 35% of code is dedicated to the role of translating data between the application and the data warehouse.

Read the rest of this entry »

Parallel programming with .NET

When I’m talking to people about the new things that Visual Studio 2010 and ASP.NET 4.0 bring, and the easy it is to write code to be executed in parallel, many people just don’t care. They see it as if it wasn’t related to them. It’s true that some kind of applications don’t really need this type of optimization… but that’s not an excuse to try to take advantage of our hardware as much as possible. From several years ago the most common thing in any computer is to have at least two processor cores. As a matter of fact, we’re starting to see now desktop computers with 8-core processors. The trend is to have an ever-increasing number of cores in our computers. This means that any application will have the chance to work in an environment where more than one thread can be executed simultaneously. Besides, nowadays if you want your software to perform faster, you can no longer just move it to a machine with a faster processor and forget about it. We’re approaching the maximum speed a processor can get, so improvements in next CPUs will come from the side of more threads, not a higher clock-rate. I think parallel programming  is a key concept all programmers should care about. ASP.NET 4.0 and Visual Studio 2010 bring new libraries, types and tools to ease multi-core development. ASP.NET 4.0 includes the new “Parallel Extensions”, which are formed by:

Read the rest of this entry »

Test-driven development

Surprisingly, there’s many programmers who still don’t know what Test-driven development (TDD) is. I think it’s a very important practice that all of us should follow, since it produces software with many less bugs.

TDD is a programming methodology that involves two other practices: test first development, and refactoring. First a set of unit tests is written and verified to fail. Then, code to make them pass must be written, and lastly this code is refactored. The aim of TDD is to achieve clean code that works. The main idea around this methodology is that requirements must be translated into automated tests: thus, when these tests pass, all requirements are guaranteed to have been accomplished. The application to be developed must be flexible enough to allow automated tests to be run. Each test should be small enough to exactly determine which piece of code is failing.

Read the rest of this entry »

JavaScript best practices II

We’ve seen some basic recommendations we should all follow when writing JavaScript. Now let’s go through some more:

Read the rest of this entry »

JavaScript best practices I

Now that we’ve seen the basic JavaScript concepts, we’ll go through some recommendations to make a good code. These are some practices that should be followed if you want to make a readable and maintainable code. It is based on my knowledge and experience of JavaScript over several years of practical experience:

Read the rest of this entry »

Object Oriented JavaScript III: some tips

We’ve already gone through the basic JavaScript concepts we need to write object oriented code, and we’ve already seen the basic pattern. But here’s a couple of tips that has proven useful many times when writing long and complex JavaScript code.

The curious case of the mutating scope

Ok, now imagine we have some fancy widget in our class and we want to interact with it. There are many widgets which redefine the this keyword to its instance instead of ours. For this case, we might want to be able to access our instance instead of the widget instance. We’ll need to redefine the scope in which the function is being executed. To do so, we can use the following function:

// Creates a new function and returns a reference. This new function has its scope set to 'newScope'
this.setScope = function (originalFn, newScope) {
   return function () { return originalFn.apply(newScope, arguments); };
};

We could just use the apply method on our original function, but I prefer this way since its more comfortable to work with parameters like this.

Be careful when using this, since this is a double-edged sword. By accessing our class scope we have all our data available. But we won’t have the widget’s scope available anymore. So make sure you don’t need to access the widget’s scope before changing the scope of the event handler.

Read the rest of this entry »

Object Oriented JavaScript II: the pattern

Ok, now that we’ve covered the most basic concepts of JavaScript, we can now proceed to take a look at the pattern itself.

The first feature we need to implement is private and public members. Using closures, this is easy to achieve:

Read the rest of this entry »

Object Oriented JavaScript I: the basics

Today’s web applications are inconceivable without the use of JavaScript. It has become a fundamental part in modern web systems. A lot of time and effort must be put into client-side programming to make our application have that modern look & feel that JavaScript provides and we all like to see.

Until AJAX techniques emerged, JavaScript was not seen as an application development platform. It was treated merely as a scripting language to implement minimal dynamic web page behavior. Up till not too long ago, all the JavaScript I needed to write was just a few lines of code to make some validations, a few animations and some AJAX calls… but this has definitely changed today. The number of JavaScript lines I am writing nowadays for the web apps I’m developing are counted in the thousands. Heck, the last module I developed at work contained more than 12000 lines of JavaScript code! This means that I can no longer just write code without order. I need to have some logic behind the process of writing code. And this is when object oriented techniques come into play.

Read the rest of this entry »