DCSIMG
December 2007 - Posts - Yochay Kiriaty

Yochay Kiriaty

I find your lack of faith disturbing

December 2007 - Posts

During my C# 3.0 deep dive in the Developer Academy II, I presented a new syntactic sugar feature in C# 3.0 called Object Initializers which enables you to init object members using a new (and somewhat odd) syntax that looks like an inlining of values directly to the object members.

Given a Customer object with three string fields, City, ContactName, and CustomerID with only default constructor (C# 3.0 code using Automatic Implemented Properties)

    public class Customer

    {

        public string CustomerID { get; set; }

        public string ContactName { get; set; }

        public string City { get; set; }

    }

 

In C# 3.0, I can now write this line of code:

   // C#3.0 Feature:  Object Initializers

   Customer customer = new Customer()

   {

        City = "Airport City",

        ContactName = "ABC",

        CustomerID = "1"

   };


These lines of code create a new Customer object with the values set to his corresponding members. The feature is really becoming useful when a given object has more than just three member fields. Consider having a lot of members in an object, and you would like to initialize any number of these members in any combination, and in a single line of code - similar to calling different constructor. However you don’t want to overwrite the constructor with all the different permutation of the member field (remember the .NET don’t support default values in the constructor). Therefore using Object Initializers syntactic sugar is a very effective programming. This allows you to reduce the total amount of code you write – no need to create all those overwriting constructors, and makes you code more readable and intuitive. Like everything in C# 3.0, this is really a simple compiler trick, which means it is nothing more than a simple syntactic sugar.

 However with that said, there is one point that we need to address and spent few minutes contemplating on. Given the Customer class and the Object Initializer statement defined above, the compiler generates the following code:

 

clip_image002

The compilers generates a “temporary” (not really temporary) Customer object called customer2 , init its property fields with the corresponding values, and only then assign the temporary customer2 object reference to our original Customer object.

From a quick glance, this may look redundant, uncalled for, very old coding style, not preferment and in general looks like a bug service pack 1 will need to fix. But actually, this is not a bug, it is a feature. This feature is called Atomic Assignment and it is an important feature to protect us stupid programmers from making too many stupid mistakes.

To explain who does Atomic Assignment works, consider the general case here.  What if you write the following code:

class Customer

{

     //dont do that at home

    public byte Age;

    public bool Cool;

    public string City;

    public Customer ReferredBy;

}

 

class Program

{

    static void Main()

    {

        Customer customer = new Customer

        {

           Age = 0x1a,

           Cool = true,

           City = "Airport City",

           ReferredBy = null

        };

        customer = new Customer

        {

           Age = 0x33,

           Cool = false,

           City = "Tugboat City",

           ReferredBy = customer

       };

    }

}

In this case, two separate instances will be constructed, each of which is stored in the customer variable.  However, a property initializer for the second instance refers to the first instance.  If temporary objects were not used, the ReferredBy = customer initializer would point the second instance at itself, instead of at the first instance.

Situations like this are the reason it‘s usually preferable to generate the verifiably correct code and let the JIT optimize the resulting MSIL if possible.

 

אם הייתה לכם את האפשרות להשפיע על התכנים והרצאות של טק-אד ישראל 08 אילו הרצאות הייתם teched רוצים לראות? בסקר של Developer Academy 2 השתתפו קצת יותר מ-900 אנשים!!! שזה חצי מסך האנשים אשר הגיעו לכנס. כמות מדהימה ללא צל של ספק, וברור לנו שרשימת ההרצאות היתה נראתה אחרת ללו ההשתתפות שלכם. כמו כן הבלוגרים "שיכנעו" אותנו לספק Wireless בכל שטחי המקום -דבר שקרה ועד כמה הערות בונות לקראת האירוע.

אני רוצה לצאת בקול קורא לגבי התכנים של TechEd 08 ובכלל לגבי הרמה והתכנים של הכנסים הטגנולוגים של מיקרוסופט. אם הייתה לכם את האפשרות להשפיע על התכנים והרצאות של טק-אד ישראל 08 אילו הרצאות הייתם רוצים לראות? מה היא הרמה הטכנית אותה הייתם רוצים לקבל? האם הרמה צריגה להיות יותר טכנית ומפורטת מ הרמה ב- Developer Academy 2 האחרון שהיה או פחות? האם לתת משקל גדול לעתיד או לבעיות שיש לנו היום? האם להרחיב בנושאים כגון Security, Performance, או אולי בנושאים כגון XNA, MCML, Multi-Core? כמה ממכם רוצים לשמוע יותר על WinForms ועומת WPF? ומה לגבי מוצרים? האם יש לתת יותר מקום למוצרים כגון IIS7, Windows Server 2008, SQL 2008? האם BizTalk Server עם מבט לכיוון Oslo יכול לספק עניין?

כשאתם עונים על השאלות הללו תנסו לתת תשובות אשר יספקו את הצרכים המיידים שלכם כמו כן את הצרכים העתידיים שלכם. וגם חשוב שתנסו קצת "להיסתכל מלמעלה" על השאלות ולנסות לענות בראיה רחבה יותר של כלל קהל המשתתפים בכנס.

הפוסט הזה הוא בפרוש לא סקר, אלא יותר קריאת כיוון לסוג התכנים והעומק הטכנולוגי שאתם רוצים שאנחנו נגיע אליו. אם אתם רוצים תגיבו במייל או כהערות לפוסט . זו היא ההיזדמנות שלכם להשפיעה!!!

אני אשמח לקבל כל התיחסות.

During my C# 3.0 deep dive session in the Developer Academy II, I presented a new syntactic sugar feature in C# 3.0 called Auto Implemented Properties. The Auto Implemented Properties allow us to take regular properties fields that looks like this

//Simple C# 2.0 (.NET Framework 2.0) property decleration

    private string customerID;

    public string CustomerID

    {

        get { return customerID; }

        set { customerID = value; }

    }

 

And simply write this one line of code:

// C#3.0 Feature:  Auto-Implemented Properties

public string CustomerID { set; get; }

The compiler, behind the scenes creates the supporting backing field named CustomerID and also creates the default set & get supporting methods. Using Reflector to check the compiler output you will see this:

clip_image002

 

Note the default setters and getters generated by the compiler and a default constructor.

 

 clip_image004

 

If you want to modify the values in the SET function operation or make format manipulation at the GET function operation you will need to use the old syntax.

So you can see that this only a compiler feature, a trick, no magic nor new code, it is just shorter code that is easy to read and maintain.

הגיע הזמן לעד PDC.

כל מה שנשאר לקוות שהפעם לא יבטלו את האירוע. אבל יש לי תחושה שבשנה הבאה ידברו על כמה דברים מאוד מענינים וחדשים, וגם כאלה שכבר שמענו אליהם כגון- Oslo. כרגיל האירוע ב- Los Angeles בין באוקטובר 27 לאוקטובר 30. לא יודע מה איתכם אני מתכוון להיות שם, זה בטוח !!! bb288534_pdc_toplevel_revised

 

 

 

Posted by Mr.J | 5 comment(s)

Thanks to Alik, I got to read this post from the PowerShell Team.

IBM Releases PowerShell Cmdlets to Manage WebSphere MQ

Don't belive me, see with your own eyes - Dale Lane from IBM posted a blog entry HERE describing a set of PowerShell Cmdlets to manage WebSphere MQ.  You can download the PDF documentation and bits from the IBM website HEREThe ZIP file contains a PDF called PowerShellCookBook which has a bunch of examples of how to use the cmdlets.

You got to love this, I mean what more can the PowerShell Team ask for? Come on, when your competitor, in this case the International Business Machine organization, starts using your software, you know you have a good piece of software. So referring to Tamir's why good programmer never write good programs post, I think we found one software that can be qualified as "good enough".


 PS

If you are not familiar with PowerShell I recommend you start reading the PowerShell Team blog, you read Shahr Gvirtz blog and see his "The Power of PowerShell" presentation recoding (inn two weeks time).
   

May the "Power of PowerShell" Be With You My Friends

Posted by Mr.J | 1 comment(s)

עושה רושם שהכנס היה לא רע. חושבים אחרת? ואני קצת באיחור העלתי את התמונות שלי ל- flickr. הינה חלק מהתמונות. וכמובן אסור לשכוח את התמונה של כל המרצים.

2076135139_a095b718ca

עד תמונות כאן

clip_image001 

clip_image001[14]

clip_image001[17]

clip_image001[19]

 

בהמשך לפוסט "תודה לכם על כנס מפנק" אני רוצה לומר שוב תודה מיוחדת לכל המרצים שבאמת עבדו ממש קשה בכמה שבועות האחרונים בכדי להכין את המצגות המעולות (חושבים אחרת אנא הגיבו). כולם קרעו את התחת ועבדו בשעות הקטנות של הלילה כדי להגיע לרמה הטכנית (הגבוה) שראיתם בכנס. אז לכל המרצים המון תודה, היה שווה (מאוד) ואני ממש אוהב אתכם (את כולללללללכם).

2076135139_a095b718ca_b (הערה: לא כל המרצים שהיו בכנס מופיעים בתמונה)

בנוסף אני רוצה להודות ל:
  • אמיר שבט שלקח על עצמו הכנה של 3 מצגות
  • להילה להב-רייס שלקחה על עצמה את כל ההרצאות של- Team System
  • ליוסי שעזר להכין את שחר התותח, וגיא ב ה....

נתראה בכנס הבא :)

האמת, הופתעתי לטובה מכמות האנשים אשר הגיעו לפנאל. היו הרבה מעל מה שציפנו וכראיה חלק ממכם נאלץ לשבת על הריצפה ועל המדרגות. --> לקח לכנס הבא: פנאלים ראויים לחדרים סגורים וגם צריך להקליט אותם (רעיונות נוספים?)

אחרי מספר דקות הגיעו כיסאות וגם מיקרופון ורמקו,ל שיהיה, אתם יודעים, בשביל האוירה.



2077272074_2cb9ca62d0_m
2077274084_c7f69a5650_m


בפאנל השתתפו: לאון, איל, נועם, אלון, אוהד, מנו ואני.

אבל מעבר לכמות האנשים התוכן הוא זה שהיה קובע. המסר העיקרי שאני וחברי הפנאל נסינו להעביר הוא מספר של פיוס ואהבה, קרי מסר של אין ממה לפחד מה- Framework 3.5 החדש. גם במהלך המצגות שלי ושל לאון, וגם במהלך הפנאל הדגשנו את העובדה שה- CLR (זה שדואג להריץ את תוכניות ה- .NET שלנו) הוא אותו CLR שך .NET Framework 2.0 וכל ההבדל הוא Minor version updates. הרי שגם התוספות של Framework 3.0 וגם של Framework 3.5 הם אך ורק תוספות של DLL-ים ו- Assemblies, וזהו. האמת שכל קוד שכתבתם מ- Framework 2.0 והלאה רץ חלק ללא תקלות ב 3.0 וגם ב3.5.

ולכן המסר העיקרי שלנו הוא עדין: Don't Panic

dontpanic

מכאן תוכלו להוריד את המצגת, חבל רק שלא יהיו הקלטות.

 

I want to thank everyone whom attended my deep dive session on C# 3.0. I hope you enjoyed the session and saw how easy is it to extend LINQ and create your own interpretation to LINQ.

I did a deep dive session on the changes in C# 3.0 (syntax) for the new release of Visual Studio 2008 - Code name Orcas.
untitled
(Step 1) The session started with a similar demo to Leon's earlier session, Discover .NET Language Integrated Query (LINQ) Framework , which was an introduction to LINQ.To understand the "behind the scenes" of C# 3.0 you need to start with a simple demo written in C# 2.0 and (Step 2) start changing the code to show the changes C# 3.0 introduce.

The list of changes in long, with changes like "Local Var Inference", Object and Array Initializes, Lambda expression, etc... we also saw that by the end of the day most of the changes, excluding Anonymous Types (which is a trick) and Extensions Methods (which are a hack?!), are what we call Compiler Magic which means that all the changes are Syntactic Sugar and nothing more. But still we had to go through the code slowly to understand that.

(Step 3) Last we saw my own implementation of few LINQ methods like Where and Select. And through that we saw what happens to a LINQ statement when its meet the compiler.

There are three solution in the Demo zip file containing the three steps we took during the presentation.

קצת באיחור, אני רוצה לומר תודה לכל מי שהגיע לכנס ותמשיכו עם ה- feedback-ים הטובים (וגם הלא טובים רק ככה לומדים). אז מה היה לנו?  

2069657265_977288a17a

 

כנס המפתחים הגדול של מיקרוסופט - Developer Acadey2 

שהתחיל ב-20 דקות איחור עקב בעיות במקרנים באולם הגדול.

 

 

 

 

 

את גלית ויפעת (רכש חדש) אשר ללא הימים ולילות הרבים שהן השקיעו לא היה הכנס יוצא טוב כמו שהוא היה.

2077050440_9931f7a514 2076267401_99904fb493

גלית יפעת

2070002929_67d6ebfb1b

 

 

לכל המשתתפים (קצת יותר מ-1800מבקרים) שאני מקווה שנהנתם מכל רגע. ושוב אני מבקש ממכם לתת לנו- feedback ולומר לנו איך ואיפה צריך לתקן בכדי שהכנס בשנה הבאה יהיה אפילו יותר טוב.

 

 

וכמובן לכל המרצים שבמהלך השבועות האחרונים עבדו קשה מאוד בכדי להרים את המצגות המעולות (חושבים אחרת, בבקשה תגידו). בסוף היום ריכזנו את כל ה- cut-out-ים של המרצים וזה מה שקלטה עדשת המצלמה . . .

2076270093_86461956ea 2077061066_78396efdbb

תודה רבה.