Jan 27 2012

Lambda Expressions in C#

Lambda Expressions are very powerful when it comes to filtering sets. There are built in methods such as Where() or FindAll() available for most collections in C#. These methods use Lambda Expressions for filtering. I have listed a few examples below.

Find evens in a list of positive integers


List numbers = Enumerable.Range(1, 100).ToList();
var evens = numbers.FindAll(n => n % 2 == 0);

Find primes in a list of positive integers


List numbers = Enumerable.Range(1, 100).ToList();
for (int i = 2; i < 8; i++) {
numbers = numbers.Where( n => (n > 1) && ( (n == i) || (n % i > 0) ) ).ToList();
}

Although, it is probably not necessary for me to explain; prime numbers cannot be divided by 2, 3, 5, 7 and not equal to 1. Why doesn’t  it matter that 4 and 6 are in the loop too? It is because 4 is a multiple of 2 and 6 is a multiple of 3. If a number is divisible by the multiple of a prime number then it must be divisible by the base prime too. Therefore anything that is divisible by 4 or 6 cannot be a prime.

Lambda Expressions can use Generic Delegates to ensure that the input, output is matching a given type. For instance, the expression below will return a compiler error because the inferred type is a double.

Func<double,double> giveMeDouble = (x) => x / 2;
int MyInt = giveMeDouble(1);

This short introduction is not even scratching the surface of what Lambda Expressions can do. If you want more information about them check out ExpressionTrees on MSDN.

Related reading:

BeginningBeginning Programming with C++ For Dummies (For Dummies (Computers))
An ideal starting point to get a strong grasp of the fundamentals of C++ C++ is an object-oriented programming language commonly adopted by would-be programmers. This book explores the basic development concepts and techniques of C++ and explains the ‘how’…

Jun 21 2011

Google Algorithm Changes

I have come across this eye opening article that sheds some light on the algorithm changes committed by Google over the years. It has encouraged me to do a little research and think about how it might affect websites in the future…

The article shows plausible evidence that Google is not reluctant to make fundamental changes to how it is indexing documents on the web nor anxious about what this means to e-commerce companies round the world. Google has set a goal to serve their customers (the users) primarily with less regards to corporate entities whose role also is, or supposed to be, to serve their own customers. The SEO community is divided about Google’s methods but most of us – victims, are in agreement that the attempt to figure out exactly what is going on is  usually seems futile. SEO is more of a trial end error process that some cleverer large SEO firms have already adopted in their sales pitch.

Continue reading

Related reading:

Apr 1 2011

Indecision – The greatest enemy of successful eCommerce

“Then indecision brings its own delays, And days are lost lamenting o’er lost days. Are you in earnest? Seize this very minute; What you can do, or dream you can, begin it; Boldness has genius, power and magic in it.” – Johann Wolfgang von Goethe

I have been an active part of the IT industry for nearly two decades now and I believe that I could tell a few stories about success and failure. Having seen many occurrences of both amongst the endeavors of my clients, employers, colleagues, some people I know and admittedly also some of my own. Looking back for a cause behind them, and for an understanding why the imaginary scale is tilting towards either side, is somewhat simple if you can avoid over-dramatizing the events leading up to the point of your examination. Continue reading

Related reading:

Feb 2 2011

SQL Server – Char vs. Varchar

Beginner developers often get confused about which types should they use when they are designing tables simply because they are struggling to understand the difference that their choice will make.

First of all, there is a good reason for the existence of the different types, so we should not make assumptions when it comes to choosing between them. I will soon publish a new series of posts about SQL data types, however, in this particular post I would like to talk about the most commonly misunderstood data types and about what troubles their misuse is likely to cause.

I find string types to be the most troublesome, especially Char. First and foremost Char is a fixed length type, which means that the space for the length of the characters is reserved. Another type of Char is VarChar (acronym for variable character). This variable length type could save a considerable amount of space in large databases in exchange for a mostly negligible performance hit*. Continue reading

Related reading:

Jan 11 2011

Appraisals – How to prepare?

For me the New Year is always exciting - not only because for a short while I get to believe that I will actually keep my new years resolutions, but also for me, making new plans has a certain unexplainable buzz to it. It is somewhat similar to how I felt every time we moved to a new house, a city or a country and started a new life which, quite frankly, we have done way too many times for a normal human being. Somehow however, we get better at it every time as we accumulate more and more experience by doing it.

Alright, why am I talking about this? I guess the subject that I wanted warm up to with my little monolog was the end-of-year assessments, and explain how I manage to look at them as a valuable experience rather than a pain in the backside… Appraisals, contrary to the common belief, are not just opportunities to ask for a pay raise. They are rather a good chance for us to think about what we could brush up on in the new year, and how to find new things that we could learn to expand our knowledge and our worth. But first and foremost the appraisal is a great opportunity to learn about ourselves and think how we could become “better” people. After all, what others are willing to pat for our time does not only depend on what we know but also how we think about ourselves and whether our colleagues, managers concur or oppose our views in the matter. Continue reading

Related reading:

© George Berdal 2006-2010 All Rights Reserved


Valid HTML 4.01 Transitional