How not to add features.

At work I have recently got a new machine and it came with XP (it does have a Vista sticker on it so must be relatively recent).  This is where I encountered one of the annoying new features of XP: Search is broken.  When you search for a file only known file types are searched.  So the data files that I receive from an automated feed that are identified by a sequential file extension are silently ignored.

According to the following KB article this is a feature not a bug.
The claim is that by limiting searches to known file types the searches will be faster.
Faster yes, but also pointless as the files that I am actually searching for are ignored.
This should have been controlled by a simple registry setting with the default being the existing windows 2000 behaviour.

It appears that the drone that designed, coded and tested this has never actually worked outside of a software house.
Big hint: the real world has far more file types than those known by microsoft!

Learning from the DBA

In most places that I have been the SQL experts have been mostly self taught.
This has oftern left me being the most experienced SQL ‘expert’ on the team.

I am lucky at my current position to have a real Sybase expert around.
I am learning more about tuning stored procedures from him than I have in years of experimentation.

In the past I had avoided using temporary tables in sprocs as they only seemed to cause problems.
Now I am seeing temp tables in almost every procedure.
What would have been a join with a complex OR clause can be better implemented as a pair of insert statements plus a delete.  This can allow the use of an index for all of the select.

Another key point is to always be explicit about creating temporary tables.  Never use insert into #table to create the table.  This locks the temp db and can impact other users or reduce concurrency in the database.

The following construct looked wierd as part of a join:

col_b = Isnull(col_a, NULL)


Why would you replace a NULL value with a NULL?
Apparently in Sybase this converts the NULL into a comparable type so that NULL equals NULL.
However if this is used on both sides of the join:

IsNull(col_b, NULL) = IsNull(col_a, NULL)

Then this is a means of not allowing the column to be used in an index – which can ensure that the correct index is chosen!

Another construct that I had not seen before was using an update statement to populate a local variable:

        update MYTABLE
          set   REP_VERSION = @NewVersion,
                STATUS_IND  = ‘A’,
                @OldVersion = VERSION
          where MY_REF   = @Ref
            and STATUS_IND = ‘R’

This can lead to some highly efficient code – there is only one trip to the filesystem where normally there would have been two.

Use of these techniques alone has reduced the runtime of one set of sprocs that are run daily from 30 mins to 90s.
Give these are run concurrently with some oher time critical sprocs this is a big win.

The Purpose of Software Architecture

A recent task at work involved me reusing a technique that I had used approximately 10 years earlier (reuse of a form with a tightly coupled UI without displaying it).  This has got me thinking back about the various software projects that I have worked on over the years.

The first time I encountered an application with a strong architecture it was a bit of a shock to my system.  It slowed down my development since I had to solve the problem in the manner that would fit the architecture rather than however I felt like (which had been my previous experience).  Once I was familiar with the system my productivity was restored (other than the crazy manual version control process) and the fact that the system had three sub architectures depending upon the module that you were working in.

The purpose of software architecture is to make an application seem as if it has a single consistent author and design.  This speeds future development as a new developer (or user) only has to be shown one part of the system and the rest should behave (where possible) in the same manner. 

The opposite of this is where an application has no architecture and each screen could have been written by a different developer with no reference to their co-workers.  This makes enhancements more difficult as you need to work out the what and how of the screen/module.

Oh and by the way architectures are designed, not architected.

Piecemeal Deployment

There have been a lot of arguments about the relative benefits and costs of using stored procedures versus making direct inline sql calls.

The argument used to be that stord procs were faster (less sent across the wire from client to server plus precompiled results).  This is less the case these days with better caching technology in the databases.

Another argument is the security one.  If the application only allows the end users to call the sprocs then there is a much smaller surface area to attack/abuse.  If the users can call sql directly it only takes one technical user to start making direct calls from excel (or another freely available client tool) and one user can cripple server performance with a careless query.

Sprocs also make a great place to put business logic that needs to be identical across multiple client applications – especially if they don’t share a codebase (At work we have an inhouse app and an extensible third party application that need to call the same code).

Sprocs also make for very clean bugfix deployment.  Since you can freely replace it in a single place (per site intallation) this makes for a low cost option – compared to an application rollout which could affect hundreds/thousands of machines.

I wonder if that is the real attraction of a web application development.  You can freely replace a page without kicking out all of the users (at least that is the attraction of PHP – not sure that asp.net allows that much flexibility).

Microsoft Business Plan

The microsoft business model is based upon the perpetual upgrade cycle.
They make their users into part of the sales force.

For example some new versions of word seem to break backwards compatibility.  For example Word 2007 by default saves the documents in a docx file.  To the naive end user that means that if a friend or business partner starts sending these files then they must upgrade to the new version.  Microsoft has the cheek to call the GPL viral!

It is amazing the range of development tools that microsoft put out to make developers life easier – at a price.
The new workflow (WF), presentation (WPF) and communication (WCF) stacks are very compelling for the developer.  The catch is that you need to either write your apps as a web application or upgrade your entire workforce to XP or above.  There are plenty of companies that have a mixed W2k and XP environment – these new tools cannot be used without an upgrade!

Top 100 Languages

Here is the latest list of the top 100 languages.

How many of them do you use/have you used?

Position
Apr 2008
Position
Apr 2007
Programming Language Ratings
Apr 2008
Delta
Apr 2007
Status
1 1 Java 20.529% +2.17% A
2 2 C 14.684% -0.25% A
3 5 (Visual) Basic 11.699% +3.42% A
4 4 PHP 10.328% +1.69% A
5 3 C++ 9.945% -0.77% A
6 6 Perl 5.934% -0.10% A
7 7 Python 4.534% +0.72% A
8 8 C# 3.834% +0.28% A
9 10 Ruby 2.855% +0.06% A
10 11 Delphi 2.665% +0.33% A
11 9 JavaScript 2.434% -0.70% A
12 14 D 1.169% -0.35% A
13 13 PL/SQL 0.608% -1.28% B
14 12 SAS 0.572% -1.63% A–
15 21 Pascal 0.513% -0.06% B
16 17 Lisp/Scheme 0.476% -0.20% B
17 22 FoxPro/xBase 0.459% -0.09% B
18 18 COBOL 0.409% -0.24% A–
19 16 Ada 0.393% -0.29% B
20 31 ColdFusion 0.384% +0.11% B

21 to 50

Position Programming Language Ratings
21 Logo 0.383%
22 Lua 0.378%
23 ActionScript 0.362%
24 Fortran 0.335%
25 RPG 0.297%
26 MATLAB 0.257%
27 Prolog 0.244%
28 Awk 0.228%
29 Transact-SQL 0.206%
30 ABAP 0.204%
31 LabView 0.178%
32 Erlang 0.144%
33 Groovy 0.142%
34 Smalltalk 0.137%
35 Haskell 0.137%
36 PL/I 0.134%
37 Bash 0.127%
38 Objective-C 0.116%
39 Tcl/Tk 0.114%
40 CL (OS/400) 0.110%
41 ML 0.106%
42 Forth 0.102%
43 APL 0.102%
44 REXX 0.102%
45 R 0.101%
46 PowerShell 0.096%
47 Euphoria 0.092%
48 Ch 0.091%
49 Natural 0.090%
50 Caml 0.089%

The next 50:

  • ABC, Algol, Alpha, Applescript, AspectJ, Beta, Boo, cg, Clean, Csh, cT, Curl, DC, Dylan, Eiffel, EXEC, Factor, Felix, Focus, Icon, IDL, Inform, Io, Limbo, Lingo, MAD, Magic, Maple, Mathematica, Modula-2, MOO, MUMPS, Oberon, Occam, Oz, Pike, Postscript, Powerbuilder, Progress, Q, REALbasic, Rebol, S-lang, Scala, SIGNAL, SPSS, VBScript, Verilog, VHDL, XSLT

Personally I have no used Java in years, nor C/C++.

Visual Basic deserves to be split into its VB6 and Visual Fred components. (I have unfortuanately used both of these in the last 3 years).

I use php for a website that I maintain.

Perl, Python, C# and Delphi have all been used.
My raw pascal has not been touched for years.

Futher down the list I have used: Fortran (a long time ago), T-SQL, Tcl/Tk, APL.

Of the bottom items: Boo, Powerbuilder (powerblunder), VBScript

Not sure how accurate this list is.

Pure Boo WCF problem

I have been trying to create a pure WCF service that exposes metadata.
Learning WCF implies that MexHttpBinding exists as a class that can be used like HttpBinding.

Unfortuantely I get HTTP 405 errors!

The following host:

namespace IndigoService

import System
import System.ServiceModel
import System.ServiceModel.Description

host = ServiceHost(typeof(IndigoService.HelloIndigoService), Uri(“http://localhost:8000/HelloIndigo”))

mexBehaviour = ServiceMetadataBehavior()
mexBehaviour.HttpGetEnabled = true
host.Description.Behaviors.Add(mexBehaviour)

host.AddServiceEndpoint(typeof(IndigoService.IHelloIndigoService), BasicHttpBinding(), “HelloIndigoService”);
host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), BasicHttpBinding(), “mex”);

host.Open();
print “Press any key to terminate”
Console.ReadKey()

Running the service and calling:

C:devboowcf>svcutil /o:serviceproxy.cs /config:app.config http://localhost:8000/HelloIndigo/mex

Produces the following errors:

Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from ‘http://localhost:8000/HelloIndigo/mex’ usi
ng WS-Metadata Exchange or DISCO.
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: Cannot obtain Metadata from http://localhost:8000/HelloIndigo/mex

If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess.  For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error
    URI: http://localhost:8000/HelloIndigo/mex

    Metadata contains a reference that cannot be resolved: ‘http://localhost:800
0/HelloIndigo/mex’.

    Content Type application/soap+xml; charset=utf-8 was not supported by servic
e http://localhost:8000/HelloIndigo/mex.  The client and service bindings may be
 mismatched.

    The remote server returned an error: (415) Cannot process the message becaus
e the content type ‘application/soap+xml; charset=utf-8’ was not the expected ty
pe ‘text/xml; charset=utf-8’..

HTTP GET Error
    URI: http://localhost:8000/HelloIndigo/mex

    There was an error downloading ‘http://localhost:8000/HelloIndigo/mex’.

    The request failed with the error message:

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”><s:Body><s:Fault
><faultcode xmlns:a=”http://schemas.microsoft.com/ws/2005/05/addressing/none”>a:
ActionNotSupported</faultcode><faultstring xml:lang=”en-GB”>The message with Act
ion ” cannot be processed at the receiver, due to a ContractFilter mismatch at
the EndpointDispatcher. This may be because of either a contract mismatch (misma
tched Actions between sender and receiver) or a binding/security mismatch betwee
n the sender and the receiver.  Check that sender and receiver have the same con
tract and the same binding (including security requirements, e.g. Message, Trans
port, None).</faultstring></s:Fault></s:Body></s:Envelope>
–.

If you would like more help, type “svcutil /?”

It appears that mex must be enabled in a config file – you can’t do it in code!

wcf demo in Boo

This is the promised simple wcf demo in boo.

It is based upon the examples in Learning WCF by Michelle Leroux Bustemante.

### Contract.boo ###
namespace IndigoService

import System.ServiceModel

[ServiceContract(Namespace:”http://foo/bar&#8221;)]
interface IHelloIndigoService:
    [OperationContract]
    def SayHello() as string:
        pass

### Service.boo ###
namespace IndigoService

#import System.ServiceModel
   
class HelloIndigoService(IHelloIndigoService):
    def SayHello() as string:
        return “Hello Indigo”

### Host.boo ###
namespace IndigoService

import System.ServiceModel
import System

host = ServiceHost(typeof(IndigoService.HelloIndigoService), Uri(“http://localhost:8000/HelloIndigo&#8221;))
host.AddServiceEndpoint(typeof(IndigoService.IHelloIndigoService), BasicHttpBinding(), “HelloIndigoService”);
host.Open();
print “Press any key to terminate”
Console.ReadKey()

### Client.boo ###
namespace IndigoService

import System
import System.ServiceModel

try:
    ep = EndpointAddress(“http://localhost:8000/HelloIndigo/HelloIndigoService&#8221;)
    proxy as IHelloIndigoService
    proxy = (ChannelFactory [of IHelloIndigoService]).CreateChannel(BasicHttpBinding(),ep)
    Console.WriteLine(proxy.SayHello())
    Console.ReadKey()
except e:
    print “Problem with server – probably not there”
    # print e

### default.build ###
<?xml version=”1.0″ ?>

<project name=”wcfdemo” default=”build”>
<property name=”boo.dir” value=”C:/boo/bin” />
    <target name=”build” depends=”wcfserver,wcfclient” />
    <target name=”wcfserver”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
                 <booc output=”wcfserver.exe” target=”exe”>
            <references>
                <include name=”C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/*.dll” />
            </references>
            <sources>
                <include name=”Service.boo” />
                <include name=”Host.boo” />
                <include name=”Contract.boo” />               
            </sources>
        </booc>
    </target>
    <target name=”wcfclient”>
        <loadtasks assembly=”${boo.dir}/Boo.NAnt.Tasks.dll” />
                 <booc output=”wcfclient.exe” target=”exe”>
            <references>
                <include name=”C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/*.dll” />
            </references>
            <sources>
                <include name=”Client.boo” />
                <include name=”Contract.boo” />               
            </sources>
        </booc>
    </target>
</project>

Improved wpf demo

Here is an improved version of the wpf demo.  The older posts build script still applies.

I need to attribute this site for giving me hints to go in the right direction.

import System

import System.Windows

import System.Windows.Controls

import System.Windows.Navigation

  

class Exer1(NavigationWindow):

            para as TextBlock

            button as Button

           

            def constructor():

                        para = TextBlock(Text:”Hello World!!!”, FontSize:36)

                        para.VerticalAlignment = VerticalAlignment.Center

                        para.HorizontalAlignment =HorizontalAlignment.Center  

                        # create a button


//<![CDATA[

//]]>
                        button = Button(Content:”Click Me”, Height:30, Width:100)

                        # display the textblock when the button is clicked

                        button.Click += NavButtonClick

                        # display the button first

                        Navigate(button)

                       

            protected def NavButtonClick(sender as object, e as RoutedEventArgs):

                        Navigate(para)

                                   

                       

[STAThread]

def Main():

            app = Application()        

            Exer1().Show()

            app.Run()

Boo compiler warning

The latest Boo release is 0.8.1

Boo build 0.8.1.2865 appears to be broken.

Code that works fine under 0.8.0.2730 fails to compile.

Apparently the latest source from subversion works fine.

Some of my samples were blowing up with unknown key errors, mostlty when assigning events.