Technology

The technology category is a home for the developers at Elevator Learning to post their views on programming best practice, the latest web gadgets and other web tech related areas that drive our business.

First pharma branded Tweet released! Revolution?

Novo Nordisk released the first branded Tweet! The US racing driver Charlie Kimball ‘tweeted’ from his Novo Nordisk sponsored ‘Race With Insulin’ page http://twitter.com/racewithinsulin

This is the first instance of using branded direct to consumer advertising (DTC) and is a very bold step made by the company since the US PhRMA regulators are yet to release a set of regulations about using DTC advertising through the social media.

Will it change online communication in pharma for better or worse…?

Comments (0)

Pharmaceutical digital marketing workshop

With the noise around digital marketing appear to be growing on a daily basis, the digital era is here like it or not.

Investment in digital marketing by many companies has resulted in a poor return. This does not need to be the case and is often due to the simple fact that it is utilised as a bolt-on to traditional activities.

It is no longer easy to use the excuse of lack of understanding or regulatory issues, as it becoming impossible to ignore the potential digital marketing offers for improving relationships and dialogue with stakeholders.

In an effort to untangle the concerns and improve understanding of digital marketing, Elevator has launched a digital marketing speed learning workshop.

Using a unique digital marketing life cycle map, the workshop illustrates the types of digital marketing activities which may be appropriate for brands in different phases of  the life cycle, integration of digital marketing within the wider marketing mix and the potential benefits for each phase of the life cycle.

Each workshop is tailored based on an organisations training objectives, current level of understanding, marketing challenges and opportunities and key therapy areas.

For further information contact Rob Wyer on:

tel: +44 (0)161 244 5544

email: business@elevatorlearning.com

Comments (0)

Sparkle Effects (AS2)

Playing with the glow effects in flash, a few simple motion tweens, and some actionscript number crunching can create some engaging effects:

(Click on the image below for a preview)
Sample sparkle effects using AS2 and stage objects. Firework effect, Spiral effect, Burn effect.

Source File: SparkleFX_as2.zip

Comments (0)

Variation on AS2 Prototype for animation (code)

Prototypes provide quick shortcuts to functionality that is otherwise a hassle to code up.
The code below, partly inspired from jQuery.js, simplifies writing animations for stage objects. For example:

animation1._alpha = 0;
animation1.fadeTo(100); // fade in movie clip from hidden, default speed and animation style
 
animation1._x = -400;
animation1.propertyTo("_x", 100, 1.5); // moves the movieclip in from left to right, in 1.5 seconds

I’ve played around with various animation libraries, and wrappers for the tween functions, but when quick effects are required I’ve found clip.propertyTo(…) the fastest to use. Its not as configurable as a full Tween instance, but makes it much easier to code in tweens around the stage without worrying about all the details such as Tween class (Regular, Strong, Elastic, etc.), start and end values, and the timing (value, frames, seconds). Tweening made easy I think.

import mx.transitions.Tween;
import mx.transitions.easing.*;
 
MovieClip.prototype.fadeTo = function(number:Number)
{
var clip:MovieClip = this;
clip.propertyTo("_alpha", number);
}
 
MovieClip.prototype.propertyTo = function(property:String, value:Number, time:Number):Tween
{	
var clip:MovieClip = this;
 
if(time == undefined)
time = 1.0;
 
clip["tween_"+property].stop();
var tween:Tween = new Tween(clip, property, Strong.easeInOut, clip[property], value, time, true);
clip["tween_"+property] = tween;
 
return tween;
}

Because this is a prototype, wherever this is defined in your code, all instances of MovieClips will have access to the fadeTo and propertyTo methods. If you find yourself using the same property animation, or special case often, then I’d recommend wrapping the propertyTo method in another function (e.g. fadeIn, fadeOut) to simplify your code.

Comments (0)

Design by Contract in .Net

There are two things I loathe during development:  spending any time at all with the VS.NET debugger and seeing “object reference not set to an instance of an object” (which is usually why I’m in the debugger to begin with).

The technique of Design-by-Contract (DbC) allows you to not only eschew these two issues but also assists with writing better self-documenting and more expressive code.  Design-by-Contract isn’t a new technique; in fact, the language Eiffel has DbC built right into it.  There’s a lot we can learn from Eiffel’s approach.

Implicit Contracts
Typically, if you’re not using DbC techniques, comments are (hopefully) included to describe to the client how the code should be used and any caveats to be expected.  (The “client” could be a third party calling your API, another developer on your own team, or, most often the case, another bit of code you’re writing yourself.)  As an example of an implicit contract - read “not DbC” - the following method fully describes the “contractual obligations” of the calling code:

/// <summary>Gets the user for the given ID.</summary
/// <param name="id">Should be > 0.</param>
public User GetUserWithIdOf(int id, UserRepository userRepository)
{
return userRepository.GetById(id);
}

The developer of this code has documented the restrictions for using the method - the “calling contract” - and, implicitly, has promised to return a User. There are a few problems with this:

  • If the client didn’t pay attention to the comments, there’s nothing to stop the client from passing in an invalid ID of 0.
  • The client could easily pass null for userRepository. This would result in an “object reference” exception.
  • Since the returned User may be null, the client will have to check for this possibility or also risk an “object reference” exception. In other words, the target method has not obligated itself to any sort of “response contract.”
  • What if, down the road, it becomes OK to pass 0 to the method. If the developer neglects to update the comment, then the stated business rule will conflict with the inherit business rule within the code itself.

Explicit Contracts
Design by Contract allows you to transform the implicit contract, described above, into an explicit bidirectional contract.  The bidirectional contract obligates both the client to invoke the method in a particular way and for the target method to guarantee a particular result.  If the contract is broken, then the breaking party will be severely chastised (conditionally…more on this soon).  The calling contract is expressed with one or more “pre-conditions” while the response contract is expressed with one or more “post-conditions.”  A pre-condition states “this is your end of the bargain which must be adhered to to call me.”  A post-condition states “this is my end of the bargain which you can count on me to enforce.”  What follows is a very explicit, and very inflexible, bidirectional contract:

/// <summary>Gets the user for the given ID.</summary>
public User GetUserWithIdOf(int id, UserRepository userRepository)
{
// Pre-conditions
if (userRepository == null)
throw new ArgumentNullException("userRepository");
if (id <= 0)
throw new ArgumentOutOfRangeException("id must be > 0");
 
User foundUser = userRepository.GetById(id);
 
// Post-conditions
if (foundUser == null)
throw new KeyNotFoundException("No user with an ID of " + id + " could be located.");
 
return foundUser;
}

With the bidirectional contract now in place, almost all of the previous drawbacks have been addressed.  Furthermore, the code is much more self-documenting and requires very few comments to be explicit.  But a few drawbacks still exist:

  • The contract is a bit verbose and easily blends in with the surrounding code.  Preferably, the contract should be more concise and easily spotted.
  • The contract above always throws exceptions.  It should be simpler to conditionally turn on exceptions for debug vs. release mode.  Furthermore, it should be simpler to always throw exceptions for pre-conditions, but only throw exceptions for post-conditions in debug mode.
  • What if we want to extend contracts to the class level, and not just on individual methods?  The above technique is difficult to extend for these purposes.
  • What if we want class level contracts to be extended (or restricted) within inherited classes?  Again, the above technique would become cumbersome - read “fragile and difficult to maintain” - when inheritance is involved.

Design by Contract Class Library
Fortunately, a light-weight class library has been written for the .NET environment which addresses these issues:  http://www.codeproject.com/csharp/designbycontract.asp.  With this library in place, the previous example could be expressed as follows:

/// <summary>Gets the user for the given ID.</summary>
public User GetUserWithIdOf(int id, UserRepository userRepository)
{
Check.Require(userRepository != null, "userRepository may not be null");
Check.Require(id > 0, "id must be > 0");
 
User foundUser = userRepository.GetById(id);
 
Check.Ensure(foundUser != null, "No user with an ID of " + id + " could be located.");
 
return foundUser;
}

Now, the contract is concise, explicit and easy to spot.  The library also provides for inheritance, allowing you to (only) weaken preconditions and (only) strengthen postconditions in overriding methods.  (As an exercise for the reader, you’ll also want to explore this library’s inclusion of an “invariant” which allows contracts to be applied to the class level.)  Finally, a few conditional compilation constants are provided to vary behavior between debug and release mode.  I recommend not varying the conditional compilation constants regardless of the compilation mode.  As commenters have noted, and as I have seen from using the library, behavior should not vary between debug in release mode.  A contract is always a contract.  Furthermore, variations in behavior may lead to difficult-to-reproduce bugs.

Day-to-Day Use & Benefits
From a practical standpoint, once you have the DbC class library in place, you’ll find the “Check.Require” to be, by far, the most useful addition to your coding arsenal. The benefits of Design-by-Contract include:

  • A better understanding of the method and how the software is constructed.
  • A systematic approach to building bug-free systems.
  • An effective framework for debugging, testing, and more generally, quality assurance.
  • A method for self-documenting software components.

The Future: C# 4.0 and beyond

It was announced at last year’s Professional Developers Conference that a subset of Spec#, the contracts library, would be included as part of the base class library in .NET 4.0. The research site for this project is here.  When .NET 3.5 came out, if you opened System.Core.dll through .NET Reflector, you may have noticed that there was a namespace in there called Microsoft.Contracts.  Since that time, the Spec# team has worked with the Base Class Library team to help integrate this more thoroughly into the libraries as a language agnostic approach.  There are many decisions to be made as languages and frameworks evolve as to what goes where.  To make these features as library features allows for more rapid change and flexibility than if they were exclusive language constructs such as they were with Spec#.

To give it a go install the Code Contracts for .NET, which you can find here.  This integrates with Visual Studio 2008 and adds an additional property window to your project files.  This gives us the ability to enforce contracts using the Microsoft.Contracts.dll.

Comments (0)

Flash 8 isn’t dead yet

adobe_flash_8With the new hype of Flash 10 simmering in the background, it is apparent to me that delivery to Flash Player 8 and ActionScript 2.0 (AS2) is still the target for new projects and training courses across a range of clients. Specifications for projects that require Flash Player 8 as a minimum requirement restrict the language to AS2. Newer IT departments are upgrading to Flash 10 player, but it’s not guaranteed that laptop users, contractors, or users abroad will be using the latest versions. As such there is still a preference to deliver to the lowest spec.

AS2 has its uses; the ease of development from design to interactive is much quicker in AS2, (the language of Flash Player 8). AS2 publishable in the latest players, and has support for earlier players down to Flash Player 6 making interactives and training modules accessible to a wider audience. AS2 is much simpler to work with then its object-oriented successor ActionScript 3.0 (AS3), quickening development and deployment. As a developer, I commonly compare using 4 lines of AS3 to 1 line of AS2. From this perspective, AS2 is continually useful for quickly creating bespoke e-Learning content. AS3 may run more efficiently, have a greater range of features, and provide access to the latest libraries, but for many projects AS2 does the same job just as well and in a modest time frame.

Moving to Flash 10

Flash Player 10 brings with it a host of new features. The ones that caught my eye include advanced text support, the hardware accelerated rendering engine, and z-index support. Moving to Flash 10 is going to require Adobe CS4 across the whole team, as many of the new features are best implemented from the Flash editor from a designer’s perspective. From a developer view, the Flash 10 features have been openly available from the open source Flash/Flex compiler for some time, but trying to grasp their impact and utility from a purely programming perspective takes a bit more imagination.

Competition from JavaScript.

As a footnote, with JavaScript becoming an ever stronger development language, an essential part of web apps, Flash’s place on the front page of sites is finding itself ground down, replaced by comparatively clean JQuery fades and prototype.js animations. In my next article I might prod at how IE6 is still in the limelight despite being the weakest browser still in popular usage. Flash is largely immune to browser versions whereas JavaScript is still heavily dependent on the environment its loaded into. Even so, as the popular browsers (IE7, FF, Opera, Chrome) get better support for JavaScript, Flash Player’s strength as a client side programming platform is being worn away.

Comments (0)