October 28, 2005

Migrating from Hashtable to Dictionary<K,V> - beware of a difference in the indexer behavior

I'm migrating lots of code to the .NET 2.0 nowadays and wanted to warn my readers about one particularly nasty migration issue. When moving from Hashtable to Dictionary<K, V> look carefully at the indexer usage - there is a runtime breaking change here. With Hashtable when you do myhashtable[mykey] and ...

When working with Hashtable it's quite natural to write code like this:

Foo f = (Foo)myhashtable[mykey];
if (f != null) 
{
  //work with f
}
When moving to Dictionary<K, V> this code would compile but will throw KeyNotFoundException whenver mykey isn't in myhashtable. You gotta change this code.

There are two options here. First - every time you need to get a value out of a dictionary make sure it contains the key:

if (mydictionary.ContainsKey(mykey))
{
  Foo f = mydictionary[mykey];
  //work with f
}
This is bad approach. Not only it performs lookup twice, it still can throw an exception in multithreaded applications.

Much better approach (explicitly designed to cover the whole issue) is to leverage Dictionary.TryGetValue() method:

Foo f;
if (mydictionary.TryGetValue(mykey, out f))
{
  //work with f
}
Dictionary.TryGetValue() method returns true if the Dictionary contains an element with the specified key; otherwise, false. Moreover:
If the key is not found, then the value parameter gets the appropriate default value for the value type TValue; for example, 0 (zero) for integer types, false for Boolean types, and a null reference (Nothing in Visual Basic) for reference types.

Use the TryGetValue method if your code frequently attempts to access keys that are not in the dictionary. Using this method is more efficient than catching the KeyNotFoundException thrown by the Item property.

This method approaches an O(1) operation.

Ok, fine solution, but still remember than when moving from Hashtable to Dictionary<K, V> you have to check very carefully every single indexer usage to spot nonexisting key cases.

October 27, 2005

nxslt 1.6.4 released

Another minor nxslt release is available - v1.6.4. This version adds support for the "extension-element-prefixes" attribute and fixes a glitch in transformation timings reporting. What's the problem with "extension-element-prefixes" attribute? When using <exsl:document> extension element to produce multiple outputs some EXSLT-aware XSLT tools (like 4XSLT) rightly require "exsl" prefix to ...

PDC 2005 videos online

Microsoft put hundreds of hours PDC 2005 videos online at http://microsoft.sitestream.com/PDC05. Here is a list of XML-related and others interesting presentations worthwhile watching IMHO. ...

LINQ/XLINQ

  • TLN306: The .NET Language Integrated Query Framework: An Overview
    Speaker: Anders Hejlsberg
    Modern applications operate on data in several different forms: Relational tables, XML documents, and in-memory objects. Each of these domains can have profound differences in semantics, data types, and capabilities, and much of the complexity in today's applications is the result of these mismatches. The future "Orcas" release of Visual Studio aims to unify the programming models through integrated query capabilities in C# and Visual Basic, a strongly typed data access framework, and an innovative API for manipulating and querying XML. This session introduces each of these areas and walks through how they are related.
    Download Presentation Download PowerPoint Download materials
  • PNL11: .NET Language Integrated Query End-to-End
    Speakers: Dave Remy; Luca Bolognese; Anders Hejlsberg; Erik Meijer; Paul Vick; Don Box
    .NET Language Integrated Query promises to extend the .NET platform in new an exciting ways. Join Anders Hejlsberg and other key Architects and designers responsible for creating this new advance in data access on the .NET platform. The panelist will be able to comment on the history leading up to the advent of NET Language Integrated Query, its immediate usages in C#, VB and the .NET Platform generally as well as some thoughts on future directions.
    Download Presentation
  • DAT324: Using the .NET Language Integrated Query Framework with XML Data
    Speaker: Dave Remy
    One of the key challenges to working with XML data has been the impedance mismatch between XML and programming languages. This session introduces future advances Microsoft is making for the "Orcas" release of Visual Studio in programming languages and frameworks to help integrate XML and queries with C# and Visual Basic. The advances include a framework for navigating, querying, and transforming XML that is both easier to use and more efficient than current XML programming techniques. This framework marries the capabilities of XPath, XQuery, and the DOM with the language integrated query framework planned for C# and Visual Basic. It is suggested that you attend "The .NET Language Integrated Query Framework: An Overview" before attending this session.
    Download Presentation Download PowerPoint

Languages

  • TLN307: C#: Future Directions in Language Innovation from Anders Hejlsberg
    Speaker: Anders Hejlsberg
    Join Anders Hejlsberg, Distinguished Engineer and chief architect of the C# language, for an in-depth walkthrough of the new language features in C# 3.0. Understand how features like extension methods, lambda expressions, type inference, and anonymous types make it possible to create powerful APIs for expressing queries and interacting with objects, XML, and databases in a strongly typed, natural way. It is suggested that you attend "The .NET Language Integrated Query Framework: An Overview" before attending this session.
    Download Presentation Download PowerPoint
  • TLN308: Visual Basic: Future Directions in Language Innovation
    Speaker: Paul Vick
    Visual Basic 9.0 will offer radical improvements in its ability to work with data in all its forms: as objects, as XML, as relational data. Join the language architects for a detailed discussion of features such as query comprehensions, object initializers and anonymous types that enable querying data in a more flexible, natural way than ever before. Also, get a glimpse into the future of dynamic programming in VB with coverage of new features intended to radically simplify working with dynamically typed data on the .NET platform.
    Download Presentation Download PowerPoint
  • TLN309: C++: Future Directions in Language Innovation
    Speaker: Herb Sutter
    If you thought that Visual C++ 2005 was innovative and breakthrough, wait until you see what we have in store in the future. This session covers some of the exciting future of Visual C++.
    Download Presentation Download PowerPoint
  • PNL03: Scripting and Dynamic Languages on the CLR
    Speakers: Erik Meijer; Jim Hugunin; Dave Thomas; Paul Vick; Jim Miller; Bruce Payette

    With the recent rise in popularity of dynamic languages as a first class tool for software development, there are new questions around how to effectively use these tools, and how well they play in the .NET ecosystem. Join members of the CLR team, Microsoft languages teams, and external language implementers in a panel to answer questions around when and where dynamic languages should be used, the futures of these languages, and open discussion on the challenges and opportunities of implementing dynamic languages on the CLR.
    Download Presentation
  • TLN317: CLR: Leveraging Dynamic Language Features
    Speaker: Erik Meijer
    Come and hear about the Common Language Runtime (CLR) advances to support languages of today and tomorrow, encapsulating a spectrum from static languages such as C++, C# to dynamic ones such as Python and the LUA programming language. Get an overview of the differences and similarities of pure statically typed languages to pure dynamic, where languages such as C#, VB.NET and Python sit in this gradient and most importantly how the CLR and Framework supports these languages. Understand how to use the range of different languages and their features to make your life as a programmer easier. More importantly, come and hear about the post-Whidbey plans for these languages, and the future CLR innovations that will better support the "best-of" features from these paradigms.
    Download Presentation Download PowerPoint

XML

  • DAT304: Unleashing the Power of XPS-Based File Formats for your Application
    Speaker: Jesse McGatha
    Applications create and edit data files that must be managed, protected, shared, and validated. Attend this must-see session to discover how WinFX services simplify the management of XPS Documents (previously code-named "Metro"), the next version of Office documents, and your own application's data through the use of the WinFX package APIs and XPS-specific APIs. For example, learn how to apply and use rights management, digital signatures, and metadata. These services will be valuable whether you're building a package file format for your own application or you're creating custom Office or XPS-based solutions.
    Download Presentation Download PowerPoint Download materials
  • DAT321: XML Tools: Future Directions for Leveraging Advanced XML Tools and Building Custom XML Solutions
    Speaker: Denise Draper
    XML now shows up just about everywhere, and it is being used as a file format for everything from configuration files to Office documents to UI specifications. Visual Studio 2005 includes some great new tools for working with XML, especially the new XML editor. In this presentation, we show how the XML editor can be customized to create domain-specific editors for different XML vocabularies, and how the XML editor can be "hooked in" to provide advanced editing functionality in custom designers with the Visual Studio SDK. We will also preview some of what's coming with additional XML tools in upcoming releases.
    Download Presentation Download PowerPoint
  • DAT405: SQL Server 2005: Deep Dive on XML and XQuery
    Speaker: Michael Rys
    Managing semi-structured and markup data is becoming an increasingly important aspect of data management. Besides storing XML natively in a database such as SQL Server 2005, it is as important to extract the information stored in the XML documents. This presentation dives into XQuery, the emerging standard to query and manipulate XML data; it discusses how SQL Server 2005 supports XQuery and XML DML; how to use these technologies to address typical scenarios and how to optimize for performance.
    Download Presentation Download PowerPoint Download materials
  • OFF304: Assembling, Repurposing and Manipulating Document Content Using the New Office File Format
    Speaker: Brian Jones
    The new Microsoft Office Open XML Formats are the default XML file formats for "Office 12". The power and accessibility of these XML file formats are designed for programmability and open up numerous scenarios for manipulating files, creating files from scratch, repurposing content and merging files with business data. This session explains the architecture of the new Open XML Formats, details of the application schemas and walks through how to create a couple of detailed solutions using the WinFX API to control file content.
    Download Presentation Download PowerPoint
  • OFF316: "Word 12": Integrating Business Data into Documents using XML-based Data/View Separation and Programmability
    Speaker: Tristan Davis
    Word 2003 introduced the concept of structured documents with its support for custom XML. This session will show how "Word 12" takes XML document programmability to a new level, offering improved robustness, more intuitive user interaction, and true data/view separation using the new XML file format. A basic overview of the improved out of the box capabilities (incl. integration with Windows SharePoint Services) will be introduced, and then the power behind those will be shown through a more complex scenario leveraging these features.
    Download Presentation Download PowerPoint
  • TLNL08: Tips & Tricks: Using Advanced Tools Features with XML and XSLT
    Speaker: Ken Levy
    This session is an "all demos and no slides" showing of various techniques, tools, and tips in working with the new XML tools in Visual Studio 2005, such as the XML editor and XSLT debugger. The new XML editor in Visual Studio 2005 validates XML documents with smart IntelliSense and error messaging in the source with tool tips, color coding syntax, and more. XML document validation is supported for any XML document in the XML editor based on the W3C rules of XML as well as any referenced XSD schema or DTD. The new XML tools in Visual Studio includes full debugging of XSLT documents with graphical preview and source output integrated within the Visual Studio 2005 IDE. Demos also include showing how to step in and out of source code between any .NET language and compiled XSLT while debugging.
    Download Presentation Download PowerPoint

Other stuff

  • COM200: Applications and Communications Roadmap: Platform Presents and Futures
    Speakers: Mike Vernal, Doug Walter, Dharma Shukla, Don Box

    This session looks at what Microsoft is doing to make Windows the finest platform on the planet for building connected systems. The move towards connected systems gives everyone a chance to rethink the way applications interact with the underlying platform. Application level messaging between services is at least as important as kernel-level device I/O. Manageable deployment and control of network-addressable services becomes at least as important as the loading of individual EXEs. Declarative scheduling of long-running work becomes at least as important as thread scheduling and synchronization. This session provides a roadmap of where and how Microsoft is investing in solving these and other issues facing the connected systems developer.
    Download Presentation Download PowerPoint
  • COM326: Windows Communications Foundation ("Indigo"): Web Services for XML Programmers
    Speaker: Doug Purdy

    If you love XML, you will love this session. Learn how to write services that range from Plain Old XML (POX) to WS-I Basic Profile and WS-* using Windows Communications Foundation (formerly codename "Indigo"). Learn best practices for transforming and manipulating XML data as well as how and when to expose strong-typed views. If you use XML, XSLT, XSD, and serialization directly in your Web services today, this session offers the information you need to successfully migrate your services to the Windows Communication Framework.
    Download Presentation Download PowerPoint
  • PNL09: APIs in the Sky: Developing Public Web Services
    Speakers: David Nielsen; Seth Demsey; Alan Geller; Don Box; Doug Purdy; Omri Gazitt

    Want to know how Amazon, Paypal and MSN design, build, and maintain their Web services? Interested in learning best practices and key insights from the architects of Windows Communication Foundation ("Indigo")? If so, this is the panel for you. Join Don Box and other industry luminaries as they discuss the practical trade-offs involved when building Web services today and what you can expect to see in the near and long-term future.
    Download Presentation
  • PNL14: The Future of RSS: Beyond Blogging
    Speakers: Sanaz Ahari; Jeff Barr; Mike Ehrenberg; Doug Purdy; Amar Gandhi; Greg Reinacker; Robert Scoble
    RSS began as a way for people to keep track of changes to their favorite blogs, and deployment of RSS grew rapidly with the growth of blogs. RSS has now grown into new areas, including traditional news, multimedia syndication, and notification services for corporate dashboards and portals. Some people see this trend as a good thing, while others are skeptical. Our diverse panel of experts share their views about where they see future applications of RSS and discuss their opinions about the opportunities and limitations for developers considering RSS.
    Download Presentation
  • DAT320: Windows Vista: Building RSS Enabled Applications
    Speakers: Amar Gandhi
    Windows Vista adds support for RSS (Really Simple Syndication). The RSS functionality in Windows Vista is being designed to make it simple for end users to discover, view and subscribe to RSS feeds, as well as make it easier for developers to incorporate the rich capabilities of RSS into their applications. In addition, the RSS functionality includes Simple List Extensions, a set of extensions to RSS that can be used to enable Web sites to publish lists such as of photo albums, music playlists and top 10 lists as RSS feeds. Come see multiple examples of subscription-enabled applications built on the RSS APIs. Security safeguards are also explained.
    Download Presentation Download PowerPoint
  • FUN302: Programming with Concurrency (Part 1): Concepts, Patterns, and Best Practices
    Speaker: Jan Gray
    In this session, we present the increasing need for concurrency in modern applications, both to increase responsiveness of your applications and to improve performance and scalability on modern multi-processor and multi-core computer architectures. We start with fundamentals, including an exploration of parallel shared memory architectures and caches. We then move on to demonstrate some common mechanisms using which to express parallelism, and survey the landscape of technologies and best practices. Learn some of the do's and don'ts of concurrent programming along the way, all based on real world examples. Lastly, we wrap up with a peek into the future of mainstream concurrency hot topics, giving insight into up and coming technologies to keep your eye on.
    Download Presentation Download PowerPoint
  • FUN405: Programming with Concurrency (Part 2): Multithreaded Programming with Shared Memory
    Speaker: Joe Duffy
    In this session, see hands-on examples illustrating how best to achieve parallelism safely using multithreaded techniques on Windows Vista and "Longhorn" Server and the Common Language Runtime (CLR). We walk through some common scenarios, APIs, best practices and pitfalls, and take an in-depth look at both managed and native technologies such as threading on the CLR, Windows threads, and OpenMP. To protect your code from concurrency hazards, we discuss how Windows Vista and the CLR can help you handle deadlocks and other hangs as well as shared memory exhaustion. We touch on more advanced topics such as CLR explicit threading and the thread pool and asynchronous programming. Legacy issues that impact concurrent programming today such as COM and UI apartment threading and thread affinity are considered. You can expect to walk away from this session with the knowledge necessary to get started on writing efficient and reliable concurrent programs.
    Download Presentation Download PowerPoint
  • FUN412: Five Things Every Win32 Developer Should Know
    Speaker: Raymond Chen
    The top two factors that control performance are I/O and memory. After exploring the relationship between physical memory, virtual memory, and the virtual address space with popular Win32 blogger and Microsoft developer Raymond Chen, we mix in some knowledge of how CPUs work and see how an O(n) algorithm can outperform an O(log n) algorithm: Why much of what you learned in school simply doesn't matter. Shift gears to Win32 and the window manager and after a brief discussion of the difference between parent and owner windows, we discuss the hazards of attaching thread input (and how it happens behind your back) and other tricks and traps of writing great Win32 code.
    Download Presentation Download PowerPoint
  • FUN421: CLR: Garbage Collection Inside Out
    Speaker: Maoni Stephens
    This session takes you on a depth-first traversal through all of the ins and outs of the CLR Garbage Collector and the algorithms it utilizes to manage memory. We discuss topics such as generations, pinning, allocating on the managed heap, and interactions with Windows memory management. We also look at common programming patterns such as cache management in managed code, and take a look into the future to provide some insight into how we intend to make the CLR GC even better, in particular for applications with more demanding memory management requirements.
    Download Presentation Download PowerPoint
  • FUNL04: Tips & Tricks: Writing Performant Managed Code
    Speaker: Rico Mariani
    If you weren't excited about managed code performance you will be after this talk! Rico Mariani promises to entertain and educate as he goes over the top 10 improvements that have gone into the .NET Framework 2.0 Common Language Runtime (CLR) from a performance perspective and tells you how to best take advantage of what CLR 2.0 has to offer.
    Download Presentation Download PowerPoint
  • OFF201: "Office 12": Introduction to the Programmable Customization Model for the "Office 12" User Experience (Part 1)
    Speaker: Jensen Harris
    "Office 12" is introducing a new, declarative model for customizing the Office user interface using XML. Learn about what is possible and how your Office solutions can benefit from the new technologies.
    Download Presentation Download PowerPoint
  • OFF302: "Office 12": Developing with the Programmable Customization Model for the "Office 12" User Experience (Part 2)
    Speaker: Savraj Dhanjal
    "Office 12" is introducing a new, declarative model for customizing the Office user interface using XML. This session dives into the details of the markup and the resulting behavior, describes how the markup interacts with DLL-based code, and provides guidance for migrating existing solutions and developing new ones.
    Download Presentation Download PowerPoint
  • TLN303: Monad: Advanced Command Line Scripting
    Speakers: Jeffrey Snover; Jim Truher
    Learn about Monad, Microsoft's next generation command line scripting solution. Monad combines the interactivity of KSH or BASH, the programmability of Perl or Ruby, and the production-orientation of AS400 CL or VMS DCL.
    Download Presentation Download PowerPoint
  • TLN404: Visual Studio: Extending Visual Studio with Add-ins and Packages
    Speakers: Phil Taylor; Craig Skibo
    This session introduces Visual Studio Extensibility from the internal architecture viewpoint, and then drills down into the Visual Studio SDK and the core extensibility scenarios it enables. Using a sample walkthrough approach, this session dives into key IDE scenarios (project systems, language service, editors and new document types) to give attendees an appreciation for the depth of control over the IDE Visual Studio Extensibility offers. The session closes with a brief discussion of broader extensibility scenarios and how the core extensibility model is amplified by other products like Team System and Visual Studio Tools for Office.
    Download Presentation Download PowerPoint
  • TLN410: CLR: Writing a Dynamic Language Compiler in One Hour
    Speakers: Joel Pobar; Joe Duffy
    Learn about writing a scripting language compiler that targets Intermediate Language in a single session. Coverage of key decision/choice points when compiling a language on the Common Language Runtime (CLR) are discussed, including the decision to statically or dynamically type and the impacts this has on your design. Includes coverage of writing a late-binder, showing that everything really can be typeless in your source language. Demonstration uses a strawman scripting language as the base language.
    Download Presentation Download PowerPoint
  • PRS312: ASP.NET: Future Directions for Developing Rich Web Applications with Atlas (Part 1)
    Speaker: Shanku Niyogi
    Take an in-depth first look at Atlas, a new set of technologies that will build on innovations in ASP.NET 2.0 and make it easier to build Web applications that deliver rich, interactive, and personalized experiences in the browser using technologies such as DHTML and XMLHttp. Atlas includes a 100% JScript cross-browser client script framework that allows you to easily build browser applications with rich UI and connectivity to Web services, full integration with ASP.NET application services such as user profiles, a set of ASP.NET server controls for Atlas, and a set of client application services. Learn how you can use the Atlas preview release and ASP.NET 2.0 to start developing richer Web applications.
    Download Presentation Download PowerPoint
  • PRS420: ASP.NET: Future Directions for Developing Rich Web Applications with Atlas (Part 2)
    Speaker: Nikhil Kothari
    Take an in-depth first look at Atlas, a new set of technologies that will build on innovations in ASP.NET 2.0 and make it easier to build Web applications that deliver rich, interactive, and personalized experiences in the browser using technologies such as DHTML and XMLHttp. Atlas includes a 100% JScript cross-browser client script framework that allows you to easily build browser applications with rich UI and connectivity to Web services, full integration with ASP.NET application services such as user profiles, a set of ASP.NET server controls for Atlas, and a set of client application services. Learn how you can use the Atlas preview release and ASP.NET 2.0 to start developing richer Web applications.
    Download Presentation Download PowerPoint Download materials
  • PRS330: Windows Presentation Foundation (“Avalon”): Creating Rich Content Experiences in Your Applications
    Speaker: Filipe Fortes
    Using the Windows Presentation Foundation (formerly codename “Avalon”), you can provide your users with world-class content and document experiences within your application. Learn how to take your existing XML content and take advantage of services such as “Metro”, pagination, columns, and sub-pixel ClearType rendering to create a rich and branded display within your application.
    Download Presentation Download PowerPoint

October 23, 2005

Opera 9.0 Preview 1 supports XSLT

Opera 9.0 Preview 1 released October 20 finally adds support for XSLT and XPath to the Opera browser. Finally they are awake. Good move, but it might be too late for the Opera. [Via <XSLT:Blog/>] ...

"Share customer's pain" video

I've seen this video at the MVP Summit. Fun, but you know, sometimes I wish something like that was actually deployed. Hey, wait, I'm a developer too... Well, all actions have consequences after all. Oh, and don't forget "Bill Gates goes to college" too. What I can't find on the ...