What's hot ? (and I mean really ...) - scroll down for more
1).  Code Templating - advanced usage of delegates & generics: my slides & demos are available for download! CodeProject article is also available.

2).  My series "TDD in the eyes of a simpleminded" is in progress(including code!): preface, part1, part2, Q&A 1, Manual Stub .vs. Mock Stub

3).  TDD Workshop: SeeCompass v0.1 and v0.2 are out.
# Tuesday, May 02, 2006

I have a popup window(calendar control) which contains a drop-down-list with many items in it. The problem occurs when I try to select the year 1930, which is outside of the popup frame:

 

calendarbug.gif

 

This close the the entire popup window instead of selecting the year 1930 as expected (well, I did anyway). I tried to cancel the event from bubbling, to set the height of the select object (doesn't work), you name it !

*btw*: I don't want to change the entire flow or to work with a different window model - to much work.

Any ideas ??

Posted by Oren Ellenbogen 
02/05/2006 03:24, Israel time UTC+03:00,     Comments [1]  | 

My team use the Sql Server 2005 Replication feature in order to synchronize between databases in different enviornments. One of the strange things though, is that the reference to Microsoft.SqlServer.Replication generated a weird "Invalid access to memory location. (Exception from HRESULT: 0x800703E6)" Error. After a quick google search I found this link which offers a nice workaround (this seems to be VS.NET 2005 bug) which worked for several folks out there but unfortunately it didn't work for me. The search continues...

Posted by Oren Ellenbogen 
02/05/2006 09:32, Israel time UTC+03:00,     Comments [4]  | 
# Wednesday, April 26, 2006

In one of our screens we were required to refresh a Modal Dialog window in order to redraw the entire screen. Trying to refresh a Modal Dialog window will resolve in a new window with the same url.

A possible solution is to create a new "container" file (MyContainer.aspx) which will only have an IFrame with the "real" page(MyPage.aspx) in it as src; Your main page (MyMainPage.aspx) will open the "container" as Modal Dialog instead of the "real" page. The trick is that the IFrame can refresh itself so we've created a Modal Dialog which behaves as a normal window. if you need to set the Modal Dialog returnValue parameter you can call "top.returnValue=...." from the "real" page.

The downside of this solution is QueryString delegation - if you need to send a QueryString parameter(s) to your "real" page you will now have to pass it via the "container" file.

Posted by Oren Ellenbogen 
26/04/2006 05:16, Israel time UTC+03:00,     Comments [6]  | 
# Tuesday, April 25, 2006

This is one of the strangest things I've seen lately, but it turns out that sending "2006-04-25 14:15:26:421" (via SqlParameter from SqlDbType.DateTime) to my Sql Server 2005 database has been saved as "2006-04-25 14:15:26:423". Does it happen every time you might ask? well, the sad answer is NO; Sometimes(really, just sometimes) it happen and sometimes it don't.

Why do I need such accuracy? Well, this DateTime column is one of the Primary Keys in my table. Trying to pull out "2006-04-25 14:15:26:421" will give me... nothing !

I wanted to reproduce it on a clean sheet so I created a new table named "CreationDates" with the single column "CreationDate" which is from DateTime type of course.

Then I've written the following code:

class Program
{
   static void Main(string[] args)
   {
      Init();
      Test();
   }

   private static void Init()
   {
      // Default culture - hebrew (I need it this way).
      CultureInfo israel = new CultureInfo("he-il");
      israel.DateTimeFormat.LongTimePattern = "HH:mm:ss.fff";

      Thread.CurrentThread.CurrentCulture = israel;
      Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
   }

   private static void Test()
   {
      string connString = @"MyConnectionString";
      using (SqlConnection conn = new SqlConnection(connString))
      {
         string query = "INSERT INTO CreationDates(CreationDate)VALUES(@CreationDate)";
         SqlCommand cmd = new SqlCommand(query, conn);

         DateTime dt = DateTime.Now;

         SqlParameter p1 = new SqlParameter("CreationDate", SqlDbType.DateTime);
         p1.Value = dt;
         cmd.Parameters.Add(p1);

         Console.WriteLine("parameter time: " + ((DateTime)p1.Value).ToString());

         conn.Open();

         cmd.ExecuteNonQuery();
      }

      using (SqlConnection conn = new SqlConnection(connString))
      {
         string sQuery = "SELECT TOP(1) CreationDate FROM CreationDates ORDER BY CreationDate DESC";
         SqlCommand sCmd = new SqlCommand(sQuery, conn);

         conn.Open();
         SqlDataReader reader = sCmd.ExecuteReader();
         if (reader.Read())
         {
            Console.WriteLine("db time: " + reader.GetDateTime(0).ToString());
         }
      }
   }
}

* I know, I could make it nicer, but this is a simple test for god sakes !

In one of my tests, this code produce the following output:

datetime.gif

The Sql Server 2005 Profile shows:

exec sp_executesql N'INSERT INTO CreationDates(CreationDate)VALUES(@CreationDate)',N'@CreationDate datetime',@CreationDate=''2006-04-25 14:15:26:423''


So I've sent "2006-04-25 14:15:26:421" but the database received "2006-04-25 14:15:26:423" !

Any smart ideas ??

 

Posted by Oren Ellenbogen 
25/04/2006 03:26, Israel time UTC+03:00,     Comments [4]  | 
# Sunday, April 23, 2006

I was required to update 40+ tables in our DB; Moran Benisty, our DBA master gave me a cool solution:

SELECT 
   'update ' + name + ' set SomeColumn = ''SomeValue'' where OtherColumn = ''SomeOtherValueToMatchBy'''
FROM 
   sys.objects
WHERE 
   name LIKE 'LK_%'



Now all I had to do is copy the results and run them. Sweet !

BTW - use at your own risk. :)

Posted by Oren Ellenbogen 
23/04/2006 04:42, Israel time UTC+03:00,     Comments [2]  | 
# Friday, April 21, 2006

There are *a lot* of posts out there about interview questions we should all be familiar with before going to an interview for a developer\architect position. I'm not going to add more to that Q&A list but rather to talk about how many interviews you should go to while looking for a job talk and how you should talk, react and respond during those interviews. I want to share with you my experience in the field both from interviewee and interviewer point of views. Maybe this will enable you to get some more $$$ to your paycheck, maybe it will make you simply more confident during those interviews or maybe I would be able to answer some of the questions you've got and still nobody answered before.

I'm looking for a job, when should I say "That's enough interviews, let's sign" ?

I would say between 5-10 *successful* interviews. That means that you have at least 5 proposals from companies you're interested working for, even if 1-2 of them are out of the question due to the low payment. Less than 5 proposals will not give you the right impression about "how much am I worth?" so don't hurry to sign, you don't want to get stuck in a company just because they offered X$ more than the rest and you thought it was a lot. I know, you can always resign, but this is still a waste of time. Doing many interviews, on the other hand, can burn you which means you'll go to your 11th or 12th interview and don't give your best, that's a shame; Don't forget, your reputation is at stake and our industry is a small world.

Know how to walk the walk, but learn how to talk the talk:

Listen, an interview is like a blind date, you must create a great first impression if you want to get to second base (that means passing to the next phase in the screening, in our case). Therefore you must grasp the nature of technical people and press the right buttons and even more important - don't press the wrong ones. I know, learning how to talk and sell yourself is very hard to master, some of us are just born with it, some of us just think we have it, some of us learn how to do it during the years and some don't count on it ("I'll be good and that should be enough!"). If you're one of the latter, meaning that you know you're good and you think that should be enough.... you're damn right! BUT! you won't get the payment you deserve, trust me, so continue reading, maybe you can learn some good tips.

In an interview you must convey me that you have the confidence I seek. See, we all want to hire people we can trust: trust that they can do their job even in stressful times, trust their abilities to learn new things and to teach others. Just be relaxed, have faith in yourself and in your abilities. All of us are nervous during  interviews, we all want to impress, but over-motivation will get you eliminated, you'll simply cause the interviewer to be more anxious and try to make you sweat harder("The interviewer must be better than the interviewee" symptom); This is not the impression you would like to leave.

So, how do you learn to talk the talk? That's an hard question, but I've got a simple answer - search for a person(s) in your life who you feel does a good marketing for himself and start looking, listening and understand the way he talks and behaves around people. Try to stay close to that guy as he will make you move in the direction you want and will help you work on your PR(public relations) skills. After some time will pass you'll feel more confident and that will allow you to be "rude" enough to push yourself and be confident about your abilities. That's it.

Some tips about "talk the talk" during the interview from an interviewer point of view:

  1. Be relaxed. No interviewer wants to make you fail, he just want to make you sweat a little to see if you're up to the job.
  2. Have confidence in your abilities. An interviewer can smell lack of confidence and this will make you harder to excel during the interview. Have a "pep" talk with yourself before - "I'm not the best programmer, yea, I don't know how to write multi-thread applications, but I have the ability to learn, I have the passion for this job, I'm a good at X, Y and Z! yes! I've got a lot to offer". When I was 16 and I got my first job (PHP programmer), I really believed that I can be great if someone would give me a chance. Why? Because I knew that I love programming and I'll do anything to be good at it! you want me to work extra hours? to read at home? NO PROBLEM! Bring it on!
    This is the attitude you need in order to be a GREAT interviewee. Do it with passion!
  3. Think before you answer. This is the most important tip I can give to anyone. Numerous interviewees I've interviewed were eager to let me know how bright they are. They didn't even let me finish the question. Relax (see section 1), let the interviewer complete his question and think before you answer. I would like to hear something "That's a good question, give me a few seconds to think..... OK, so what you can do is ....". This shows that you don't hurry to pull something out of your sleeve just to meet "he asked, I replied" rule a lot of follows.
  4. Don't have the answer? nothing happened! Relax! (I would write see section 1, but I think you got the point right?)
    All you have to do is simply tell me "To be honest, I don't remember\know how to solve this question, BUT, if I had google, MSDN (whatever) - I would likely search "XXXXXX". In addition, let me think out loud about possible solutions to your question... OK so you can (1)XXXXX or maybe (2)XXXXX, I'm not sure but perhaps (3)XXXX will work as well". This will certainly make a good impression. Nobody can memorize MSDN and none of us has enough experience to cover 100% of the questions. Good interviewees just know how to stay cool and think out loud; Explain your way to the solution and I'll show you the way to the job and paycheck you seek.
  5. You're good, I have no doubt, but there are others who are better, I have no doubt. arrogance is a quality you must avoid or at least decrease. Nobody like arrogant people although I truly believe that there is a thin line between self confidence and arrogance. Try to stay humble, let them know that you have more than good programmer skills to contribute; Do it with grace.


Any tips you would like to share with me ?

Posted by Oren Ellenbogen 
21/04/2006 12:09, Israel time UTC+03:00,     Comments [0]  | 
# Thursday, April 13, 2006

I've joined Microsoft Israel community so you can now find some of my post in this address:

http://blogs.microsoft.co.il/blogs/orenellenbogen/

I'll publish a few advanced post in Hebrew in the following month so stay updated.

.NET | Life
Posted by Oren Ellenbogen 
13/04/2006 07:08, Israel time UTC+03:00,     Comments [0]  | 
# Wednesday, April 12, 2006

I'm going to give a deep insight presentation about advanced usage of delegates, generics and anonymous methods at the next C# group meeting.

Please let me know if you're planning to come(drop me a comment), it will be nice to see some of my co-workers\readers\friends at my first lecture at Microsoft user groups.

The original excrept can be found here. (don't forget to register, free of charge, by sending an email to: ivcug at comconix dot com)

The Details:

Date:    Wednesday, May 17, 17:00 - 20:00

Place:   Microsoft Israel 

            Hapnina 2  (Amdocs Building)

            Ground Floor

            Raanana

+972 (9) 762-5100         

 

Parking available at the Kurkar parking lot. Proceed straight past the traffic circle and the parking lot will be on your right.

Topic: Advanced Use of Delegates and Generics

Lecturer: Oren Ellenbogen

 This lecture will not be just about Delegates or Generics, but it will combine those topics to show you how you can leverage to usability of those semi-new features. Oren will discuss the receiving of delegates as parameters and the implementation of abstraction in this methodology. He will tie the two topics together by refactoring(live!) existing code using a principle he calls “Code Templating”;  a coding method that allows running unique logic within recurrent code.

 Agenda:

  1. Looking at a "simple" scenarios of recurrent code
    1. Check if a value exists in a collection.
    2. Get the item index in a collection.
    3. Filtering a collection (get only some of the items based on a condition).
    4. Manipulating every item in the collection (string concatenation for example).
  2. Looking at "advanced" scenarios of recurrent code
    1. Querying the database.
    2. Exception handling.
  3. Discuss solutions for further abstraction in those scenarios.
  4. Introduce "Code Templating" – separating the unique code from the recurrent code.
  5. Before we start, getting to know our toolbox: generics & delegates
    1. What are they?
    2. Calling a delegate which was given as parameter – understand the benefits.
    3. Anonymous delegates\methods – how & why
    4. What's going on under the hood?
  6. Examples of Code Templating in .Net 2.0
    1. Handle those "simple" scenarios via List<T>.Find, List<T>. FindAll, List.<T>.Exists etc…
  7. Refactor (live!) the "advanced" scenarios, step-by-step.
  8. Code Templating - What do we gain? What can we lose?
  9. Q & A

 

Oren Ellenbogen is a Team Leader at SQLink's R&D Department. Oren's responsibilities and areas of expertise span from Analyzing and Designing Web Applications to developing innovative coding enhancement tools. Oren's project leading at SQLink involves all stages and forms from team leadership to high level consulting.

 Oren's years of developing experience cover a variety of languages including PHP, C++, VB6 and C#.

 Oren published a series of articles at codeproject.com, publishes a programming oriented blog and is an active member of several .Net architects forums.

 As always, although admission is free and you may attend without reserving a place, we kindly request that you notify us if you plan to attend so that we can be sure to have enough chairs and FOOD!

Posted by Oren Ellenbogen 
12/04/2006 05:00, Israel time UTC+03:00,     Comments [0]  | 
# Thursday, April 06, 2006

I sat with Mario today in order to figure out the best way to receive a "status" message from one of our business layer methods.

The task was clear:

We want to activate a rules validation method which will query the data and retrieve the missing operation(s) which are needed before the user can save his data. It is possible that the user have only one operation he has to do but it's also possible that he has to do N operations. We needed some sort of status combination.
In addition, if the validation passes - we want some sort of "Everything is OK" status.

Our options:

  1. Use ref\out parameter and fill a string variable. Concat error messages to that string and send it back to the caller. The method will return true if everything is good and false otherwise.
  2. Return the error message(s) as string. Again, we'll have to concat the error messages.
  3. Return a Bitwise Enum which will allow us to "add"\"remove" statuses.

Elimination process:

The main reason we quickly drop options (1) and (2) is the orientation of the error message(s). Sometimes, in act of pure laziness, we will print the error we've got from the BL method directly to the user screen. Some time passes by and the user gives you a call and says "Hey, I'm trying to save a user but it throws me an error like [Rule 1] is invalid... What the heck is [Rule 1] ?? I don't remember seeing it in the user manual!" and you'll reply "Wait a second, let me see... Hmm... if... else...not... Oh ya!! the bank account number you filled doesn't match the bank address !". See the problem here ?

Think about it - your business layer should return a "programmer oriented" message rather than "client oriented" message. If you'll return some sort of client oriented message from your BL - how would this work in multilingual application ? your BL would talk with some Resource Manager just to return the "correct" message to the user ? No. This is why you have Graphic User Interface layer. So we'll send a programmer oriented message from the BL back to our caller (for logging purpose), but wait, this will require our GUI to parse the string we've got from the BL method and format it for the client. Something like:

if (errorMessage.indexOf("Rule 1 is invalid") != -1 && errorMessage.indexOf("Rule 2 is invalid") != -1)
{
    // show "1). You must fill the user details. 2). You must fill the user paycheck"
}
else if (errorMessage.indexOf("Rule 1 is invalid") != -1)
{
    // show "You must fill the user details"
}
else if (errorMessage.indexOf("Rule 2 is invalid") != -1)
{
    // show "You must fill the user paycheck"
}
else
{
    // show "Save complete"
}

Yes, I can make some refactoring (constants, ToLower(), split) but no matter what I'll do - this code smells (terrible) !

Solution:

This leaves me with option 3. It would be great to ask something *like*:

if (status == ActionStatuses.InvalidRule1 && status == ActionStatuses.InvalidRule2)
{
   // show "You must fill the user details. You must fill the user paycheck"
}
else if (status == ActionStatuses.InvalidRule1)
{
   // show "You must fill the user details"
}
else if (status == ActionStatuses.InvalidRule2)
{
   // show "You must fill the user paycheck"
}
else
{
   // show "Save complete"
}

It's time to write some code, shall we ?

1). Let's define a bitwise Enum, so will be able to create a status combination:

[Flags]
public enum SaveUserStatuses
{
   OK = 1,
   BankAccountMissing = 2,
   WrongEmailFormat = 4,
   BankAccountMismatchBankAddress = 8,
   SaveFailed = 16
}

The only rule: if you need to add more values just double the previous value by 2.

2). In our business layer method, we'll do something like:

public static SaveUserStatuses Save(User user)
{
   SaveUserStatuses status = SaveUserStatuses.OK;


   if (!CheckIfBankAccountExists(user.BankAccount))
      status = (status | SaveUserStatuses.BankAccountMissing) & ~SaveUserStatuses.OK;

   if (!CheckEmailFormat(user.Email))
      status = (status | SaveUserStatuses.WrongEmailFormat) & ~SaveUserStatuses.OK;


   // you get the idea...

   if (status == SaveUserStatuses.OK)
   {
      if (!UsersDal.Save(user))
      {
         status = SaveUserStatuses.SaveFailed;
      }
   }

   return status;
}


The trick here is for every bad validation you add ("|" - bitwise OR)  the required status and remove the "OK" status by using "~" complement operator.

3). Finally, in our GUI:

SaveUserStatuses status = UserBL.Save(someUser);

if ( (status & SaveUserStatuses.BankAccountMissing) == SaveUserStatuses.BankAccountMissing &&
     (status & SaveUserStatuses.WrongEmailFormat) == SaveUserStatuses.WrongEmailFormat )
{
    // show the required message - client\user oriented !
}
// like the above - parse the status and show the required client oriented message(s).


This code smells a lot better:

a). We have no problem extending this code: (1) Add another member to the Enum (2) Add another check to our BL (3) handle the new status at GUI level.

b). We don't have to parse strings in order to build our errors. Parsing strings is error prone. Using Enum values can set a contract between the BL and the GUI. If someone will break it, we'll get compile time error (fail fast).

Back to code...

.NET | Design
Posted by Oren Ellenbogen 
06/04/2006 04:58, Israel time UTC+03:00,     Comments [5]  | 
# Friday, March 24, 2006

" Today, a real experience is much more important than a degree, well, unless you're looking for a government position. The problem in our industry is that students decide to study for the degree on the way, while trying to work in 120% job. In my opinion, if you want to give a student a chance at the real world while he can stay focus on his degree (and event enjoy it) you must assist him by finding him a position as an intern for at least a few months so later on he could apply to any position he'll be suited for. "

Well, that quote was mine(during launch time at my company). I'm one of those folks who tries to get my degree while trying to work my ass of. Sadly, I suffer 80% of the time as I struggle finish my papers for the universty on time and still enjoying my job(100% of joy). 
If internship was a part of the degree, I believe that the a lot of us programmers out there could enjoy the learning process without damaging our career and hack, maybe it will produce better programmers in our industry. 

In the USA (and in France too, as my cousin told me), this dream is a plain reality - you can see the internship project Joel Spolsky started here.

Posted by Oren Ellenbogen 
24/03/2006 10:02, Israel time UTC+02:00,     Comments [0]  |