Greg Beech's Website

February 2008 - Greg Beech's Tech Blog

  • Expressions involving deferred execution should be re-entrant

    If you create a method to return a random set of items from an enumerable list, implemented using an iterator... public static IEnumerable<T> GetRandom<T>(this IEnumerable<T> items) { var random = new Random(); foreach (var item in items) { if (random.Next() < 0.5) { yield return item; } } } ...then use it like this, where PrintColors uses a foreach loop to print each colour.....
  • Not using negatives does not make your code less readable

    Most people find negative statements more difficult to comprehend than positive statements. You probably had to double-check the title of this entry to see if it made sense - I know I did! This isn't surprising if you think about it because a positive statements presents a concept which can be used directly, whereas a negative statement presents a concept and then says "the opposite of that"...
    Filed under: ,
  • Information redundancy in language syntax

    Jeff Atwood has quite a number of posts comparing VB and C#, and the general theme is the claim that the verbosity of VB makes it easier to read . One aspect he doesn't appear to have considered, however, is the information redundancy caused by Visual Basic's verbose syntax. Consider the following equivalent property declarations. VB: Public Overridable ReadOnly Property FirstName() As String...
    Filed under: ,
Copyright (C) Greg Beech. All rights reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems