Code editor control with syntax highlighting for Silverlight available

by Vlad 1. November 2010 14:12

This is an update to my Syntax Highlighting TextBox in Silverlight using MVVM post.

First of all, i'd like to thank Jeff Willcox for his port to Silverlight of Drew Miller's syntax highlighting engine called ColorCode and Morten Nielsen for putting it together with my overlaying TextBox idea.

Morten's SyntaxHighlightingTextBox control is just for demo (he mentions that a polished version will be included in their SDK), and the performance goes down when the text is bigger than just a few lines of code.

I rewrote the control in order to improve the performance - the goal was to get instant update when typing.

Changes:

Used a RichTextBox in the background instead of a TextBox. They both use Inlines for the content so the change is trivial, but from my observations the RichTextBox is faster, especially for scrolling.

Fixed a couple of bugs in the Colorizer.

Problem:

Syntax highlighting is done on the UI thread at every key press; refreshing the syntax caused the whole content do be cleared and rebuilt.

Solution:

Use in memory entities for formatting instead of updating the Inlines collection directly. This decouples the syntax highlighting code from the UI and also enables background processing. Also, it enables partial updating - basically updating only the Inlines that changed instead of clearing and reloading all the content for the RichTextBox. Even more, it is possible to update only the style (color) for existing Inlines if the text is the same.

Problem:

With the syntax highlighting in the background, the UI continues responsive, but typing takes place in the invisible overlaying TextBox and it is not visible until the syntax highlighting updates the background RichTextBox, and it is confusing for the user. (For big texts, the syntax highlighting can take seconds).

Solution:

Use a DiffTextBox as overlay. A DiffTextBox handles all key presses and updates a list of text transforms (insert, remove, move caret). Using that information, I can update rapidly the affected RichTextBox Inlines and get instant update for the background. The syntax highlighting can now be delayed so that it takes place after the user stops typing (configurable HighlightDelay).

There is still a limit of text size that the text box can handle - if the text is very big (dozens of pages), the Silverlight TextBox and RichTextBox slow down considerably. I'm thinking this could be fixed by managing "virtual pages" and loading only the current context (several pages) in the control so that it keeps being responsive.

You can see the control in action in this code sharing site I built: CodeReturn.com. You can upload code that you want to share and / or embed in your pages. The best part is that you can edit the code (and soon: post replies to other people's code) directly in the page where it is embedded! You just need to login with any OpenID account!

Like this:

Also, you can grab the source code here: SyntaxHighlighting.zip (99.63 kb).

VS 2010 Database projects - treat your database as code

by Vlad 29. July 2010 21:09

Before

Working on a project that includes a database implies dealing with the schema changes and versions. The problem is that the tools that can help you are pretty expensive and (from my experience) not 100% reliable. It was so bad that my team and I developed our own database versioning mechanism and even started working on a tool to automate it.

What I want

I want to be able to deal with the database schema objects the same way i deal with the code files - specifically, I want to be able to see a svn history for them.

I want to be able to deploy a new version of the database to test and production servers AUTOMATICALLY, without worrying about data loss.

I want to be able to restore an old backup (like one with specific test data) of the database and update it to the latest version.

I want to keep the developer, test and production databases in sync (that is, the schema is the same for the same version).

I want the configuration data (read-only data like states and cities) to be included in the versioning system. More...

Categories: Databator | SQL

Agile vs Plan Driven

by Vlad 29. July 2010 18:51

If you ever had to convince a client or a boss why Agile works, you know that it's not an easy task. Agile goes against many ideas that are considered axioms in the business world - like planning first and then keeping to that plan: "plan your work, then work your plan". If that is the case, these points from a talk by Martin Fowler and Neal Ford (ThoughtWorks) might help you.

In the Plan Driven approach, a project is successful if it goes according to plan, so in software development it depends on requirements stability, on having clear and fixed requirements. As you probably know, that is a luxury most software projects don't have, and a first approach would be to apply techniques like Change Management or Sign In Blood to contain the changes. Unfortunately that leads to unhappy clients and unusable software.

The Agile approach is to break the dependency on requirements stability and come up with a process that takes into account changes. It does that by using Adaptive Planning and Evolutionary Design.

Adaptive planning implies going through the project cycle many times, re-planning and re-adapting often.

Evolutionary design can be achieved with the help of practices like Self Testing Code, Continuous Integration, Refactoring and Simple Design.

If this made you curious, I highly recommend that you view the complete talk here:

 

Pourquoi, pas comment
Pourquoi, pas comment

USI 2010 : conférence incontournable du l'IT en France
Rendez-vous annuel des Geeks et des Boss souhaitant une informatique qui transforme nos sociétés, USI est une conférence de 2 jours sur les sujets IT : Architecture de SI, Cloud Computing, iPhone, Agile, Lean management, Java, .net... USI 2010 a rassemblé 500 personnes autour d’un programme en 4 thèmes : Innovant, Durable, Ouvert et Valeur.
Plus d'informations sur www.universite-du-si.com

 

VS 2010: Web.Config Transforms extra spaces problem

by Vlad 21. July 2010 20:38

In Visual Studio 2010 you can use xdt transforms to fill the web.config files with the appropriate values for deployment to test or production environments.And it is pretty simple to use:

  • - add Config Transforms to the web.config (like web.Debug.config)
  • - duplicate the sections with the values you want to customize
  • - set the xdt:Locator attribute for the nodes that need to be identified by an attribute (like xdt:Locator="Match(name)")
  • - set the xdt:Transform to control how the values are changed (common uses - xdt:Transform="SetAttributes" to update some attribute values, or xdt:Transform="Replace" to replace the whole node
  • - you get the transformed web.config when publishing or creating a deployment package (or you can create it from command line).

More details on how to use the Web.Config Transformation here.

 

However, there is a nasty bug that you won't probably notice before publishing for the first time.

Let's say that you want to replace a value that is not an attribute, but the inner text of a node.

 <value>Default value here</value>

You can write the transform like this:

 <value xdt:Transform="Replace">Production value</value>

The problem is that in the generated web.config file the value will appear like this:

 <value>Production value
 </value>

The extra spaces (and newline) will be passed to the value and can generate problems if the setting represents a file path for example.

According to Microsoft, this is a known bug and will be fixed in the next Service Pack for Visual Studio.

 

The workaround is to trim the value before using it in code, but that won't help you if the setting belongs to a 3rd party component that you can't modify.

 

Categories: Gotcha | WTF

Links - 2010-07-06

by Vlad 6. July 2010 15:39

Benoit Mandelbrot: Fractals and the art of roughness

At TED2010, mathematics legend Benoit Mandelbrot develops a theme he first discussed at TED in 1984 -- the extreme complexity of roughness, and the way that fractal math can find order within patterns that seem unknowably complicated.

 

Silverlight for Symbian

Silverlight includes a runtime that is optimized to display content on memory-constrained devices. Silverlight support for Nokia S60 5th Edition devices includes:

  • The ability to view Silverlight applications in the mobile browser.
  • Tools to build Silverlight applications that target devices

Tips and Tricks for INotifyPropertyChanged

As a WPF or Silverlight developer, you know that your models must implement INotifyPropertyChanged and it can be a pain. To do it safely, you really need to check to see if there are any registered handlers, then raise the event. To add insult to injury, the event arguments take a string, so if you mistype the property name you're out of luck. Some clever individuals have created nice code snippets to generate the needed plumbing, but it doesn't help with refactoring.

One common solution is to create a base class that provides the plumbing for a raise property notification.

Import Art from Photoshop and Make into Silverlight Controls

In this tutorial, we’ll take graphics created in Adobe Photoshop and Illustrator, import them into Expression Blend and then quickly turn the visual assets into interactive Silverlight controls.

Create a Custom Control - Inheriting from TextBox

When a control almost does what you want it to – if only it had another button or behaved slightly differently – you may be able to extend it by writing a custom control. Custom controls let you change an existing control or write a completely new control.

Categories: News | Silverlight

Monterrey geeks - Extreme Tuesday May 18th

by Vlad 17. May 2010 11:49

For Monterrey geeks: I'm organizing an "Extreme Tuesday" meeting (which I hope can turn into a regular event).

The idea is to get together and talk about geek stuff - agile, TDD, software development, mobile technologies, Silverlight, .NET or whatever IT-related theme you can think of.

Place, date and time: Sierra Madre Galerias (Av. Insurgentes), Tuesday May 18th 2010 staring at 7 PM.

If you are interested, please confirm your attendance here - Nerd Dinner or leave a comment below.

Also, comments suggesting a specific theme or topic for this first meeting are welcome.

 

Para los geeks de Monterrey: estoy organizando un encuentro de "Martes Extremo" "Martesextremo" (a sugerencia de Heriberto - there is sex in the middle Laughing).

La idea es de juntarnos y platicar acerca de cosas geek - agile, TDD, desarrollo software, tecnologias moviles, Silverlight, .NET o cualquier tema relacionada con TI que se les ocurre.

Lugar, fecha y hora: Sierra Madre Galerias (Av. Insurgentes), Martes 18 de Mayo de 2010 empezando a las 7 PM.

Si estas interesado, por favor confirma tu asistencia aqui - Nerd Dinner o deja un comentario abajo.

Comentarios que proponen un tema especifico para este primer encuentro son bienvenidos.

 

 

Categories:

DesignData support for Silverlight in Visual Studio 2010 and Blend 4

by Vlad 14. May 2010 12:52

In order to take advantage of the design-time binding support in Blend (and now VS .NET 2010), especially when using MVVM, you had these options:

1. Set the DataContext in XAML to a StaticResource (like a ViewModel) created for design only, and change it to the real thing at runtime.

Good: use the existing class structure, XAML intellisense and autocompletion.

Bad: the design-time object will get created at runtime too, cannot access private set or readonly properties, must have a parameterless constructor.

2. Create sample data in Blend (XML).

Good: can be created by designers, can use private set or readonly properties, no runtime penalty.

Bad: must be kept in sync with the actual ViewModel, no compile-time checking, no intellisense support.

DesignData

The DesignData combines the advantages of the two options - you can create a XAML with your design values, based on the existing class model.

You can take advantage of intellisense and autocompletion and you're able to set readonly properties, instantiate classes with no parameterless contructors.

The objects will be created only at design time, so there is no runtime penalty. You also get compile-time checking - you get an error if you try to set an invalid value to a int property, for example.

This functionality has been available since Blend 3, but it was (and still is) kind of hidden - in Blend 3 / VS 2008 you had to manually edit the project file to get it to work.

Fortunately in VS 2010 you don't need to edit the project file, but there still is no Item Template for DesignData files.

More...

Categories: MVVM | Silverlight | DesignData

Syntax Highlighting TextBox in Silverlight using MVVM

by Vlad 5. May 2010 19:53

EDIT: You can find an update to this post here: Code editor control with syntax highlighting for Silverlight available.

This is a demo about leveraging the databinding and templating support in Silverlight and the MVVM pattern to create a simple syntax highlighting textbox control.

The idea is to have an invisible TextBox (handling the editing) overlapping a ItemsControl that uses TextBlocks to highlight the keywords in the text. The ItemsSource property of the ItemsControl is bound to a collection property on the ViewModel, so we only need to update this collection in order to maintain the controls in sync.

In the end we'll get something like this:

More...

Monterrey geeks - get together for an Extreme Tuesday

by Vlad 5. May 2010 12:11

For Monterrey geeks: I'm organizing an "Extreme Tuesday" meeting (which I hope can turn into a regular event).

The idea is to get together and talk about geek stuff - agile, TDD, software development, mobile technologies, Silverlight, .NET or whatever IT-related theme you can think of. For Heriberto: no, sports are not IT related :)

Place, date and time: Sierra Madre Galerias (Av. Insurgentes), Tuesday May 11th 2010 staring at 7 PM.

If you are interested, please confirm your attendance here - Nerd Dinner or leave a comment below.

Also, comments suggesting a specific theme or topic for this first meeting are welcome.

 

Para los geeks de Monterrey: estoy organizando un encuentro de "Martes Extremo" (que espero que se va a convertir en un evento periodico).

La idea es de juntarnos y platicar acerca de cosas geek - agile, TDD, desarrollo software, tecnologias moviles, Silverlight, .NET o cualquier tema relacionada con TI que se les ocurre. Para Heriberto: no, los deportes no son relacionados con TI :)

Lugar, fecha y hora: Sierra Madre Galerias (Av. Insurgentes), Martes 11 de Mayo de 2010 empezando a las 7 PM.

Si estas interesado, por favor confirma tu asistencia aqui - Nerd Dinner o deja un comentario abajo.

Comentarios que proponen un tema especifico para este primer encuentro son bienvenidos.

 

 

Categories: Extreme Tuesday

Filter candidates early by interviewing them online

by Vlad 9. April 2010 14:59

This happened to me lots of times:

The candidate arrives for the interview. We spend a few minutes for the introductions and small talk. Then, the first question: "What is a class and what is an object?"... <crickets>...

At this moment I normally try a few other questions, just to be polite, but my mind is made up: I just wasted my time!

It can be even worse - I get an answer that is sufficiently vague and uses some buzzwords to be considered correct. So I spend let's say 30 minutes trying to determine if the candidate knows stuff and has a problem expressing himself or he's just taking long shots with his answers.

And then, the practical part: get him or her to write some simple code -  a class with a property and a method (C#). As a programmer you probably write dozens of those each day. And that's when I have my confirmation: the candidate doesn't even know the syntax for a property or a method. He's looking for the door, thinking if it would be less shameful if he just got up and ran. And I just wasted even more of my time!

Now, on top of that, imagine that the company had to arrange transportation and accommodation for the candidate, because he/she was from another city. Or, the company has a recruiting process that requires the candidate to pass an interview with HR or to take some personality tests first. What a waste!

And it is a global problem - Coding Horror, The Non-Programming Programmer.

The solution? Interview candidates by phone or online first. Coder Proof is a free interview tool that allows you to see the candidate's skills at programming in real time. You can see how he writes code before dedicating more time and resources to bring him to the office for a face-to-face interview.

And the candidate can run at any time - there is no shame in "I just lost my internet connection". Wink