Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

TWC9 - Illustrator-to-Canvas, msPerformance, ExtensionMethod.net,

Download

Right click “Save as…”

This week on Channel 9, Dan and Clint discuss the week's top developer news, including:

Picks of the week!

Follow the Discussion

  • Greg Duncangduncan411 It's amazing what a professional photographer can do...

    Pick of the week!  Thanks for the shout-out as always... Smiley

    BTW, the Watch links for the picks of the weeks are backward (Clint's watch link points at Dan's, Dan's at Clint's)

  • BasBas It finds lightbulbs.

    I love that extensionmethod.net thing. Wonderful!

    Also, Dan's rage with the whole string/stream thing is so recognizable. It drives me crazy every single time.

  • Hans Olavhansol Cloudtastic

    Epic Dan-rant from minute 16:

    "But then I try to create... a God-damn stream - but that's an abstract class... so then I need to find... a StreamWriter...but."

    Truer words were never spoken... And I love the way it ends with a "but", that but is what every developer feels like a grunt coming from your soul every time you try to convince yourself that correct encapsulation and abstraction layers and architecture comes before productivity and ease-of-use.

    Or wait... No it doesn't! Cover the 90% use-cases first and the 10% use-cases later. In the case of symmetric encryption the 90% use-cases are with a string-in string-out. An extension method for this need to be in String - and this needs to happen now as a critical reboot-all-servers update to .NET 4.0! Heck I'll even implement the solution right here and now:

      /// <summary>
      /// Critical extension methods to make encryption and decryption easy.
      /// </summary>
      public static class CriticalStringExtensions
      {
        /// <summary>
        /// Gets a Stream containing the bytes from the given string.
        /// </summary>
        /// <param name="source">String object.</param>
        /// <param name="encoding">Encoding to use. Uses UTF8 as default.</param>
        /// <returns></returns>
        public static Stream AsStream(this string source, Encoding encoding = null)
        {
          if (encoding == null)
            encoding = Encoding.UTF8;
          
          if (source.Length > 0)
            return new MemoryStream(encoding.GetBytes(source));
          else
            return new MemoryStream(0);
        }
    
        /// <summary>
        /// Gets a string from the bytes in a stream.
        /// </summary>
        /// <param name="source">String object.</param>
        /// <param name="stream">Stream to read from.</param>
        /// <param name="encoding">Encoding to use. Uses UTF8 as default.</param>
        public static string AsString(this Stream stream, Encoding encoding = null)
        {
          if (encoding == null)
            encoding = Encoding.UTF8;
    
          using (var reader = new StreamReader(stream, encoding))
          {
            return reader.ReadToEnd();
          }
        }
      }
    

  • Allan LindqvistaL_ Kinect ftw

    are you still forced to submit your internal application to the winphone marketplace in order to get them on devices?

    phone7 looks really hot but it is (or atleast was) waaay to complicated to get your code onto an actual device... paying 99 bucks to simply deploy your own app to your own phone? come on dudes..

    we'd really love to make an app for internal use at my company, but having to submit it to the marketplace where its visible for everyone is an absolute showstopper Sad both in terms of added work to get it approved for the marketplace, and cost to develop and deploy

    @DLNA

    DLNA is a protocol but as far as i understand you have to buy a licence from the DLNA group to make an app that uses it. As far as i know there is no special hardware involved, its just an peer2peer network protocol that TVs and other stuff (such as win7) can support

  • Andy BeaulieuAndy Beaulieu

    Another great show, and thanks for the good word guys!

  • Bent Rasmussenexoteric stuck in a loop, for a while

    @hansol:Not bad; could extend it a little though

    public static class CriticalStringExtensions
    {
        public static Stream AsStream(this string source, Encoding encoding = null)
        {
            var result = Stream.Null;
            if (source != null && source.Length != 0)
                result = new MemoryStream((encoding ?? Encoding.UTF8).GetBytes(source));
            return result;
        }
        
        public static string AsString(this Stream stream, Encoding encoding = null)
        {
            if (stream == null)
                return string.Empty;
            using (var reader = new StreamReader(stream, encoding ?? Encoding.UTF8))
                return reader.ReadToEnd();
        }
    }

    A slightly different take. Not necessarily better.If contracts (with static checks!) are available then one should probably use Contract.Requires(source != null); and likewise Contract.Requires(stream != null).

  • Hans Olavhansol Cloudtastic

    @exoteric: Agreed! I love the succint syntax of the ?? operator, but the Contract.Requires stuff, that's attributes from a feature that's not in production yet, right? Or am I not up to speed here...

  • Clint RutkasClint I'm a "developer"

    @gduncan411: thanks for the heads up, don't tell dan or it will be the last time he'll give me the keys to the car!  Smiley

  • Bent Rasmussenexoteric stuck in a loop, for a while

    @hansol: Code Contracts is a .NET 4.0 feature and so is production ready. Static analysis tools for Code Contracts is a commercial feature of some Visual Studio versions (I forget which). Some Code Contracts features are exposed as attributes, e.g. [Pure]; the above is of course not. I didn't check for how Stream.Null is implemented but it's probably a no-op singleton (I hope).

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.