Category Archives: visual studio


Silverlight: developer win, designer fail?

I posed this question in a post over on itjoblog. There are several reasons why Silverlight struggles to get designer attention, including:

1. Designers are pragmatic and target the runtime that is already deployed most broadly, ie. Flash.

2. Flash is already good enough so why bother?

3. The tools: Adobe’s designer tools are a de facto standard, target Flash, and run on the Mac.

Developer is another matter. The cross-platform .NET runtime is Silverlight’s big advantage; and this time the tools tip the balance towards Microsoft (Visual Studio) – not for everyone, but for the substantial Microsoft platform community. That’s going to be further reinforced by Visual Studio 2010 which gets full visual designer support, plus of course Silverlight 3.0.

Microsoft does have a problem with Silverlight out of the browser. Developers need a way to have these run with more local permissions, subject to user consent, otherwise they will turn to Adobe AIR. Actually the whole Silverlight on the desktop story is confused, since you can also do Silverlight Mesh-Enabled Web Applications, or stick Silverlight content in a desktop gadget or other embedded browser. No, not the one in AIR (nice idea though): Adobe only includes Flash support and the PDF plug-in.

The tension behind this is that ultimately developers and designers need to work on the same applications, so this remains a fascinating contest.

A Silverlight database application with image upload

I’ve been amusing myself creating a simple online database application using Silverlight. I had this mostly working a while back, but needed to finish off some pieces in order to get it fully functional.

This is created using Silverlight 2.0 and demonstrates the following:

  • A bound DataGrid (as you can see, work is still needed to get the dates formatted sensibly).
  • Integration with ASP.NET authentication. You have to log in to see the data, and you have to log in with admin rights to be able to update it.
  • Create,Retrieve,Update,Delete using ASP.NET web services.
  • Image upload using Silverlight and an ASP.NET handler.
  • Filter a DataGrid (idea taken from here).
  • Written in Visual Studio 2008, and hosted on this site, which runs Debian Linux, hence Mono and MySQL. Would you have known if I had not told you?

You can try it here. I’ll post the code eventually, but it will be a couple of months as it links in with another article.

MVP Ken Cox notes in a comment to Jesse Liberty’s blog:

Hundreds of us are scouring the Internet for a realistic (but manageable and not over-engineered) sample of manipulating data (CRUD operations) in a Silverlight 2 application. There are promising pieces of the puzzle scattered all over the place. Unfortunately, after investing time in a sample, we discover it lacks a key element – like actually saving changed data back to the database.

I can safely say that mine is not over-engineered, and that yes, it does write data.

Parallel Programming: five reasons for caution. Reflections from Intel’s Parallel Studio briefing.

I’m just back from an Intel software conference in Salzburg where the main topic was Parallel Studio, a new suite which adds Intel’s C/C++ compiler, debugging and profiling tools into Visual Studio. To some extent these are updates to existing tools like Thread Checker and VTune, though there are new features such as memory checking in Parallel Inspector (the equivalent to Thread Checker) and a new user interface for Parallel Amplifier (the equivalent to VTune). The third tool in the suite, Parallel Composer, is comprised of the compiler and libraries including Threading Building Blocks and Intel Integrated Performance Primitives.

It is a little confusing. Mostly Parallel Studio replaces the earlier products for Windows developers using Visual Studio; though we were told that there are some advanced features in products like VTune that meant you might want to stick with them, or use both.

Intel’s fundamental point is that there is no point in having multi-core PCs if the applications we run are unable to take advantage of them. Put another way, you can get remarkable performance gains by converting appropriate routines to use multiple threads, ideally as many threads as there are cores.

James Reinders, Intel’s Chief Evangelist for software products, introduced the products and explained their rationale. He is always worth listening to, and did a good job of summarising the free lunch is over argument, and explaining Intel’s solution.

That said, there are a few caveats. Here are five reasons why adding parallelism to your code might not be a good idea:

1. Is it a problem worth solving? Users only care about performance improvements that they notice. If you have a financial analysis application that takes a while to number-crunch its data, then going parallel is a big win. If your application is a classic database forms client, it is probably a waste of time from a performance perspective. You care much more about how well your database server is exploiting multiple threads on the server, because that is likely to be the bottleneck.

There is a another reason to do background processing, and that is in order to keep the user interface responsive. This matters a lot to users. Intel said little about this aspect; Reinders told me it is categorised as convenience parallelism. Nevertheless, it is something you probably should be doing, but requires a different approach than parallelising for performance.

2. Will it actually speed up your app? There is an overhead in multi-threading, as you now have to manage the threads as well as performing your calculations. The worst case, according to Reinders, is a dual-core machine, where you have all the overhead but only one additional core. If the day comes when we routinely have, say, 64 cores on our desktop or laptop, then the benefit becomes overwhelming.

3. Is it actually desirable on a multi-tasking operating system? Consider this: an ideally parallelised application, from a performance perspective, is one that uses 100% CPU across all cores until it completes its task. That’s great if it is the only application you are running, but what if you started four of these guys (same or different applications) simultaneously on a quad-core system? Now each application is contending with others, there’s no longer a performance benefit, and most likely the whole system is going to slow down. There is no perfect solution here: sometimes you want an application to go all-out and grab whatever CPU it needs to get the job done as quickly as possible, while sometimes you would prefer it to run with lower priority because there are other things you care about more, such as a responsive operating system, other applications you want to use, or energy efficiency.

This is where something like Microsoft’s concurrency runtime (which Intel will support) could provide a solution. We want concurrent applications to talk to the operating system and to one another, to optimize overall use of resources. This is more promising than simply maxing out on concurrency in every individual application.

4. Will your code still run correctly? Edward Lee argues in a well-known paper, The Problem with Threads, that multi-threading is too dangerous for widespread use:

Many technologists are pushing for increased use of multithreading in software in order to take advantage of the predicted increases in parallelism in computer architectures. In this paper, I argue that this is not a good idea. Although threads seem to be a small step from sequential computation, in fact, they represent a huge step. They discard the most essential and appealing properties of sequential computation: understandability, predictability, and determinism. Threads, as a model of computation, are wildly nondeterministic, and the job of the programmer becomes one of pruning that nondeterminism. Although many research techniques improve the model by offering more effective pruning, I argue that this is approaching the problem backwards. Rather than pruning nondeterminism, we should build from essentially deterministic, composable components. Nondeterminism should be explicitly and judiciously introduced where needed, rather than removed where not needed.

I put this point to Reinders at the conference. He gave me a rather long answer, saying that it is partly a matter of using the right libraries and tools (Parallel Studio, naturally), and partly a matter of waiting for something better:

Law articulates the dangers of threading. Did we magically fix it or do we really know what we’re doing in inflicting this on the masses? It really come down to determinism. If programmers make their program non-deterministic, getting out of that mess is something most programmers can’t do, and if they can it’s horrendously expensive.

He’s right, if we stayed with Windows threads and Pthreads and programming at that level, we’re headed for disaster. What you need to see is tools and programming templates that avoid that. The evil thing is what we call shared mutable state. When you have things happening in parallel, the safest thing you can do is that they’re totally independent. This is one of the reasons that parallelism on servers works so well, in that you do lots and lots of transactions and they don’t bump into each other, or they only interface through the database.

Once we start opening up shared mutable state, encouraging threading, we set ourselves up for disaster. Parallel Inspector can help you figure out what disasters you create and get rid of them, but ultimately the answer is that you need to encourage people to use programming like OpenMP or Threading Building Blocks. Those generally guide you away from those mistakes. You can still make them.

One of the open questions is can you come up with programming techniques that completely avoid the problem? We do have one that that we’ve just started talking about called Ct … but I think we’re at the point now where OpenMP and Threading Building Blocks have proven that you can write code with that and get good results.

Reinders went on to distinguish between three types of concurrent programming, referring to some diagrams by Microsoft’s David Callaghan. The first is explicit, unsafe parallelism, where the developer has to do it right. The second is explicit, safe parallelism. The best approach according to Reinders would be to use functional languages, but he thinks it unlikely that they will catch on in the mainstream. The third type is implicit parallelism that’s safe, where the developer does not even have to think about it. An example is the math kernel library in IPP (Intel Integrated Performance Primitives) where you just call an API that returns the right answers, and happens to use concurrency for its work.

Intel also has a project called Ct (C/C++ for Throughput) which is a dynamic runtime for data parallelism, which Reinders considers also falls into the implicit parallelism category.

It was a carefully nuanced answer, but proceed with caution.

5. Will your application need a complete rewrite? This is a big maybe. Intel’s claim is that many applications can be updated for parallelism with substantial benefits. A guy from Nero did a presentation though, and said that an attempt to parallelise one of their applications, a media transcoder, had failed because the architecture was not right, and it had to be completely redone. So I guess it depends.

This brings to mind another thing which everyone agrees is a hard challenge: how to design an application for effective parallelism. Intel has a tool in preparation called Parallel Advisor, to be part of Parallel Studio at a future date, which is meant to identify candidates for parallelism, but that will not be a complete answer.

Go parallel, or not?

None of the above refutes Intel’s essential point: that effective concurrent programming is essential to the future of computing. This is an evolutionary process though, and at this point there is every reason to be cautious rather than madly parallelising every piece of code you touch.

Additional Links

Microsoft has a handy Parallel Computing home page.

David Callaghan: Design considerations for Parallel Programming

Mono creeping into the mainstream?

For those of you who have not already seen this link on Twitter: I’ve posted a short piece on Mono, the open source implementation of Microsoft .NET. The piece was prompted by my own experience writing a simple .NET application in Visual Studio and deploying it to Linux. Admittedly I anticipated the move by using MySQL rather than SQL Server as the database; but even so, I was impressed by how easy it was – I spent more time recently deploying an application from Visual Studio 2008 to Windows Server 2008, thanks to some issues with SQL Server Express.

Don’t Miguel de Icaza’s comment about scalability and garbage collection, two of the factors that have deterred some from real-world Mono deployments.

Hands on with ASP.Net Membership, SQL Express and Server 2008

Is it worth using the built-in membership framework in your ASP.Net application, or should you roll your own? I’ve been trying it out recently, and I have mixed feelings.

On the plus side, it does get you up and running quickly with user login and role-based permissions, saving time and possibly achieving more reliable results, on the grounds that Microsoft and countless other users should have found and fixed any bugs by now.

One the negative side, there are annoying limitations. The most obvious one is that a user as defined in the framework only has a minimal number of fields, not including information you probably want to store like first and last name. You are meant to fill this gap by using profiles, another ASP.Net feature which lets you store arbitrary name-value pairs in a database as a kind of persistent session. That works, but the way profile properties are stored makes it hard to do things like sorting users by last name. Therefore, you will probably end up managing your own user database and joining it to the membership system with the user ID, at which point you begin to lose some of the benefits.

Some of the supplied controls, like the CreateUserWizard, seem rough-and-ready too.

Still, the real fun began when I tried to deploy my demo app to Server 2008 and SQL Server Express 2008. By the way, make sure you install .NET Framework 3.5 SP1 and Windows Installer 4.5 before installing the latest SQL Server Express, otherwise the setup spends ages unpacking its files and then exits with a brief message. I got there eventually, copied my application across, and optimistically tried to run it.

When you debug a web application in Visual Studio, it defaults to a SQL Express database in the App_Data folder within the web site, attached on demand. In theory, that should make it easy to deploy to another machine with SQL Express installed: just copy it across, right? There must be a way of getting this to  work, but it seems a lot of people have problems. I got the message:

Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.

This makes sense, insofar as ASP.NET runs as this user. I temporarily attached the database and added the login, to be rewarded with a different and more perplexing error:

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance.

A quick Google shows that many users have suffered from these errors, and that a large number of remedies have been proposed. I abandoned the idea of attaching the database on demand and set up a new database, made ready with Aspnet_regsql. I still got one or other of these errors.

Eventually I realised that my application was using more than one connection string. The problem is that the membership framework uses three different "providers", one for membership, one for roles, and one for profiles. By default in IIS 7.0, these all use an attach-on-demand connection string, defined as LocalSqlServer, and inherited from machine.config buried deep within your Microsoft .NET Framework system folder. In order to prevent ASP.Net membership from using this, you have to override all three providers in the web.config for your application. There’s an example in this article from ISP MaximumASP. I wish I’d come across it sooner; but my demo works fine now.

SharpDevelop 3.0: everything .NET from Boo to F#

I’ve been researching open source .NET and noticed that SharpDevelop, the free IDE for .NET on Windows, completed version 3.0 earlier this month. Congratulations to the team. Along with Windows Forms and ASP.NET applications in C# or Visual Basic, you get extras like support for F#, Boo and Python. Another welcome feature is built-in support for Subversion version control. There’s even an ASCII table in the IDE, which brings back memories: 15 years ago every programming manual had one at the back.

SharpDevelop has two major challenges. One is keeping up with Microsoft; right now there are discussions about improving WPF support, for example. The other is that Microsoft offers free Express versions of Visual Studio, which leaves SharpDevelop with those niche users for whom the Express products are unsuitable, but who do not want to pay for a full version, or who are wedded to some exclusive SharpDevelop feature.

In favour of SharpDevelop, it installs more easily and loads more quickly than Microsoft’s effort, and certainly proves the point that native C# applications do not have to be slow.

A more interesting though less complete product is the forked MonoDevelop, which is cross platform and targets Mono, the open source implementation of .NET. Mono now looks good on Linux; but the idea of WORA (Write Once Run Anywhere) has never really caught on in the .NET world. How many significant Mono applications for Windows have you seen? My guess is that if it happens at all, it will be in the form of Silverlight/Moonlight running in the browser.

Technorati tags: , , , ,

First screenshots of Visual Studio 2010 UI

Jason Zander has posted some screenshots and info about the new WPF-based UI for Visual Studio 2010.

An early build of VS 2010 was handed out at PDC last year, but lacked the new UI.

Floating document windows is a great new feature. That said, Visual Studio 2008 works rather well; I hope the new version is equally fast and stable.

Technorati tags: , ,

Visual Studio 2008 as a JavaScript editor

I’ve been doing some work on JavaScript editors recently, and was impressed by Microsoft’s Visual Studio in this respect. Here’s my post on the subject. By the way, even the free Express edition works fine for this; and you don’t need to use ASP.NET. You do need to use Internet Explorer of course; that’s another story.

Amethyst from SapphireSteel: Develop Flex in Visual Studio, an alternative to Tofino

Not long ago I looked at an early preview of Ensemble’s Tofino, an extension to Visual Studio for developing Flex applications that target the Adobe Flash runtime. It was disappointing, though I’ve been assured that an improved build is in preparation. Ensemble had better be quick: I’ve just been informed of an alternative called Amethyst, from SapphireSteel software, creators of the Ruby Visual Studio extension Ruby in Steel. Here’s what I know so far about Amethyst:

  • ActionScript and MXML editing and project management
  • Installs into commercial editions of Visual Studio or the free Visual Studio shell
  • Initial beta of free personal edition available next week
  • Planned for the 2nd quarter of 2009: commercial Professional Edition with drag-and-drop Flex/AIR visual design environment, IntelliSense and graphical debugging tools
  • Can integrate with Ruby In Steel to create a multi-language Visual Studio solution with Flex at the front end and Rails at the back
  • Amethyst Personal will remain completely free

All sounds good; and Ruby in Steel is well-regarded so this is worth watching out for if you have any interest in developing for Flex in Visual Studio.

A high quality Visual Studio design tool for Flex would help Adobe gain adoption for Flex and AIR among Microsoft-platform developers.

Embarcadero RAD Studio 2009 is done

Embarcadero / CodeGear has released RAD Studio 2009, which includes Delphi 2009, C++ Builder 2009 and Delphi Prism. Note that Prism has its own IDE, which is actually the Visual Studio shell; this is the new take on Delphi for .NET that targets Mono as well as Microsoft .NET. You can also install Prism into an existing Visual Studio installation.

Looking at the UK prices, RAD Studio starts at £979.00, whereas Delphi starts at £549.00. Upgrades are much cheaper – less than half the price in some cases. The message seems to be: get RAD Studio if you think you might need more than one of these three products.

I’ve been asked whether the upgrade to Delphi 2009 is worth it. I have no idea, of course, since it depends what you need it for – though if you need Unicode I’d have thought it was worth it for that alone. I do think it is the best so far in the post-Delphi 7 series. Personally I prefer it to Delphi 7 as well; though check Mason Wheeler’s comments to a previous post for a contrary view. Vista compatibility is another advantage, though you can hack this in any version of Delphi. I doubt that Windows 7 will be much problem here; it is close to enough to Vista that the same stuff should work fine.