December 2004 - Posts

Pair Programming breaks
Tuesday, December 28, 2004 1:45 AM

Jeff Schoolcraft has an interesting post on Pair Programming and how it influences your break schedule.  Two people working together certainly helps to avoid distraction and remain "on task" (asides from all the other benefits) but is it unhealthy?  Should there be a "pairing-o-meter" which turns red at some point and causes the pair to stretch their legs before the dreaded window incident Jeff alludes to? :-)

At our current client, there is an outside balcony which allows us to look over the downtown and get a breath of fresh air.

Oh and definitely QuestionAndAnswerSection. :-)

C# Teaser - The Tricky Ternary Teaser?
Thursday, December 23, 2004 1:05 AM

Today we came across a little quirk that is worth sharing. Big thanks to Bob Flanders and Jeff Schoolcraft for help in figuring out the quirk.

The Rules:

  1. Prize (a Thycotic keyring light) to be mailed to the first comment with the correct answer(s) on this blog post with valid contact information.
  2. My definition of the problem is the correct one. :)  Other answers might be right but won't win the prize.
  3. I will post the answer within a few days.

using System.Web.UI;

using System.Web.UI.WebControls;

 

namespace Teasers

{

    public class TernaryTeaser

    {

        private object GetValue(Control o)

        {

            return (o is TextBox && ((TextBox)o).Text.Trim() != "") ?

                 ((TextBox) o).Text : System.DBNull.Value;

        }

    }

}

  1. What is the problem and what is the easiest way to fix it?
  2. Why do ternaries work this way - is there something at the compiler or IL level?

The first person to successfully answer part (1) gets a hearty pat on the back, the first person to explain part (2) gets a Thycotic keyring light.

UPDATE: Thanks to Kirk and Joseph for spotting the logic error - not what I was looking for, just my silly oversight (where's a test when you need one!) - I have updated the code to make more sense.

Winner: Jonathan de Halleux

Answer & Discussion (click and drag your mouse to see the answer)

Answer:
The simplest fix I was looking for is casting the System.DBNull.Value to an object:

 return (o is TextBox && ((TextBox)o).Text.Trim() != "") ? 
((TextBox) o).Text : (object) System.DBNull.Value;
For a full explanation of the ternary/conditional operator, read the docs.
For the answer to part (2), see Jonathan de Halleux's awesome detailed comment below.

by thycotic | 6 comment(s)
Filed under: ,
Programming Contest by EggHeadCafe ... just Regex?
Thursday, December 09, 2004 1:05 AM

Rafael Munoz pointed me towards a Programming Contest By EggHeadCafe in his latest MVP Update Newsletter.  Reading through their criteria ...

<snip>
2. All occurrences of an in a sentence must be replaced by un.
3. Replace all occurrences of au in a sentence with oo
4. Inside any word (ie., after the first character):
replace all a's not followed by whitespace with the letter e. Thus, the word a by itself would not be translated to e
replace all o's in a word by u. Example: Doh becomes Duh.
</snip>

It sounds like a simple console application using a few Regular Expressions would do it ... (and obviously an adhoc test method to drive the results TDD style) ... am I missing something?

by thycotic | 3 comment(s)
Filed under: ,
More Posts

This Blog

Syndication