Taoffi's blog

prisonniers du temps

MOD: Mur Oriented Development

MOD est un pattern connu de gestion de projets. Il s'agit de réussir son entrée dans le mur !

Sa pratique est assez simple : elle consiste justement à éviter, au dernier moment, de rentrer dans le mur. Adopter MOD est facile. Le maîtriser et le réussir est une autre affaire !

Object Visibility and learning cycle… just a vision of

In everyday work, we come through new tools or new versions of tools we knew before.

The cycle of playing with and manipulating these tools’ objects to attain a reasonable level of mastering… is often daunting!

To minimize the learning cycle of tools, some helpful features have been introduced: like documentation, tooltips… etc.

Documentation is of course important, but, for me, tooltips are much more helpful. They just appear when I need them in the context of using the object or the property.

The thing is: when you manipulate an object for the first time, you really know few things about its composition and, even less, about its role in the global mechanics of the tool in question. You just know it is there, and it should be there for some reason and that you should spend some time to understand: its role, its structure, and finally how can it be useful for you (if at all it could be!)

One way to shorten this learning cycle is to let others show you how to use the tool and its object. Quite useful, but, on one hand, this occults some side of self-experience (important)… and also negatively interferes in your critical view of the tool (which is often useful for the tool’s enhancement itself)

What we do to know about (most) simple toys seems more rational: You just set something on or off (left/right or up/down…)… then put the toy on work and see... after some cycles you end up by figuring out what is the ‘best’ position for your needs (or mood!).

Another representation, which may also give an interesting slant related to this subject, is the DeepZoom technology used in maps applications where you can first see the whole world map, and then, zooming-in on the map you get more details about a given country, city, streets, buildings… etc.

A good path for reducing the time and effort needed to learn a subject or a tool would be:

  • To be able to see (explore) the global image of the subject or tool’s structure in action;
  • Be able to zoom-in on its objects and see their properties (progressively detailed according to your zoom level);
  • Be able to change the value of a give object’ property… and perceive the impact of the change on the global behavior.

This proposed path cannot of course be applied in all situations or contexts, but can be useful in many (most) cases.

We may, for instance, need to create a simulation context inside which we can ‘run’ the specific tool or object. An approach which may also be useful for product tests and benchmarking.

Some interesting works have been done on some aspects (like The Property Grid project)… More is to be done on the visualization of objects and properties by zoom level. Will try to write a sample on this in a future post.

 

Learning from Nature: Towards a 'Nucleotidic' modeling - part I

 

 

 

During several years, I worked on a DNA sequence-analysis software project where I learned about DNA structures and several DNA engineering techniques.

(That is not to be confused with what is commonly called ‘genetic algorithms’ and ‘genetic programming’).

 

Elements and structures used (and manipulated) in molecular biology engineering sphere are fascinating and, above all, source of interesting knowledge. In some way, they define the representation of ‘Life hood’ structures and mechanisms for every living creature (plant, animal, bacteria, virus…)

Molecular biology teaches us that ‘Life’ is based on few nucleotides: A, T, G and C.

Like in music partitions, sequences composed of these few number of nucleotides can give unlimited number of combinations each representing the structure of a specific biological function and, in the end, a specific individual being.

 

Here are some sample (random) fragments of DNA sequences:

 

3’à…GCAATGGTTTCTTACTGTGGAGGACATAAAAATACAGCAAGGGT…à5’

3’à…TTGTGTTGCGAGATGTCGTCGTTAAAGACACTCTTTCTCCCGGAGTCAC…à5’

3’à…CTCTACAGTATAAAGTTCTAGTAAGAGCACAAACTCCTGGACAATTC…à5’

 

Note that DNA sequences are read in a specified direction (noted 3’à5’ in the above sequences).

Nucleotides are considered in complementary (attracted) pairs. A is complementary to T, and G to C.

Each DNA sequence strand has a ‘complementary’ sequence strand where complementary nucleotide pairs are arranged face-to-face in reversed direction to compose part of the well-known helicoidal presentation.

 

Example:

The complementary strand for

3’à…GCAATGGTTTCTTà5’

Is

5’ß…CGTTACCAAAGAAß3’

 

A DNA sequence has its mapped amino acid (protein) sequence. In this mapping, different combinations of three nucleotides (A, T, G or C) compose codons, each mapped to one amino acid (one amino acid may have several codon mappings… see below).

Here are some codon/amino acid mappings:

 

Amino acid

Amino acid Symbol

Codon

Alanine

A

GCA

GCC

GCG

GCT

Arginine

R

AGA

AGG

CGA

CGC

CGG

CGT

Asparagine

N

AAC

AAT

Methionine

M

ATG

 

A sequence may have several “reading frames” in which amino acid codons mapping interpretation may vary. Essentially, to read a sequence, you must first find a starting codon… otherwise; your sequence is the representation of nothing in biological life (real world!)

 

Another interesting aspect is that a specific DNA sequence (with ‘significant’ length) seems to represent one part of a global ‘predefined’ structure… that is, in a way, similar to a known melody in music. If you start to play the first specific notes of, say, a Beatles’ song, everyone can tell the rest of the melody. If your first notes are not specific enough, the result may lead to so many different melodies.

This phenomenon is used in PCR (Polymerase Chain Reaction) in molecular biology engineering to amplify or clone DNA sequences using partial sequences (rigorously selected!).        

 

Useful lessons for software design

Many (if not all J) real world problems seem to follow DNA sequences structure and representations:

§  Basic elements (A, T, G, C)

§  Related each to one another (AT, GC)

§  Composing a global sequence (unique for a specific area)

§  The sequence can be presented differently (DNA /Amino acid)

§  The translation between representations is done through specific mappings (codons / amino acids)

 

PCR technique also seems of great interest to some software areas (OCR recognition for example)

 

I will continue, in future posts, to explore these fascinating structures and propose some applications that mimic and benefit from their behaviors.

 

SQL recursive schemas

SQL recursive schemas

 

One of the interesting features of relational databases is the possibility for a table to reference itself.

Suppose we want to represent the file folder system in a database. We can define a table having, for example, 3 fields: id, parent_id and name:

 

We can then create a self referencing relationship between the id and parent_id field.

Simple (and elegant) solution!

Yes, but that also let us inherit all specific constraints of recursive patterns.

 

The figure above shows the simple (and somehow elegant) of the table schema or pattern.

What it doesn’t show is how the ‘real world’ records will look like when stored in the table:

 

 

Two important constraints of such recursive schema are:

·         Path readability: i.e. as the schema allows an infinite nest levels, reading an item path may cause a stack overflow;

·         Cyclic references: i.e. a folder that references itself (or one of its children) as a parent (which may end up by creating infinite path readability loop;

 

The Nest level problem

A function or stored procedure for reading an item path may look like this:

 

CREATE FUNCTION dbo.Read_path

(

       @item_id int

)

RETURNS nvarchar(max)

AS

BEGIN

       declare             @parent_id   int,

                    @path        nvarchar(max),

                    @name        nvarchar(50)

      

       select @parent_id   = parent_id,

             @name        = name

       from dbo.sample_folders

       where(id = @item_id)

      

       if @parent_id is null

             return @name

 

       -- recursive call  

       return dbo.Read_path ( @parent_id) + N'\' + @name

END

GO

 

 

Such a function will work nicely as long as the folder’s nest level remains in a ‘reasonable’ value. For example, in MS SQL Server, nest level (recursive call stack whose value can be returned at any time by the @@nestlevel system function) has a maximum of 32.

 

So, it is more precautious to test current @@nestlevel value before proceeding:

 

if @@nestlevel >= 32

       return N'Path nest level exceeds allowed value'

 

However, doing so breaks the efficiency and usability of our pattern. The best solution would be to get rid of the recursive call inside our function. Here is an example using a goto label:

 

       DECLARE @folder_name       nvarchar(255),

              @parent_id   int,

              @cur_item_id int,

              @path        nvarchar(max)

 

       SELECT @path        = N'',

              @cur_item_id = @item_id

 

-- recursion label

get_nested_path:

       SELECT @folder_name = f.name,

             @parent_id   = f.parent_id

       FROM   dbo.sample_folders AS f

       WHERE( f.id = @cur_item_id)

 

 

       if @parent_id is null

       begin

              -- We are on the root

              return @folder_name + @path

       end

 

       select @cur_item_id = @parent_id,

              @path        = N’\’ + @folder_name + @path

 

       -- goto recursion label

       goto get_nested_path

 

 

Cyclic references problem

Our read path function can still be trapped into an infinite loop that can be caused by cyclic references… i.e. a folder referencing itself or one of its children as a parent:

 

 

One way to prevent cycling references is to create a constraint on the folders table that tests for cycling references. The constraint may call a function that returns true (1) if the item is not valid:

 

CREATE FUNCTION [dbo].[Is_cyclic_folder]

(

       @item_id            int,

       @parent_id          int

)

RETURNS bit

AS

BEGIN

       -- if this is a root item: OK

       if @parent_id is null

             return 0

      

       -- self referencing?

       if @parent_id = @item_id

             return 1

      

       declare             @parent_folder_id   int,

                    @folder_id          int

      

       -- initial parent folder

       select @parent_folder_id = @parent_id

      

       while NOT @parent_folder_id is null

       begin

             -- if the current parent folder is one of children folders:

             -- then this item is cyclic (NOT VALID)

             if @parent_folder_id = @item_id

                    return 1

            

             select @folder_id   = @parent_folder_id

            

             select @parent_folder_id   = parent_id

             from dbo.sample_folders

             where( id = @folder_id)

       end

      

       return 0

END

 

The constraint may look like this:

 

ALTER TABLE dbo.sample_folders ADD CONSTRAINT

       CK_sample_folders_cyclic CHECK ([dbo].[Is_cyclic_folder](id, parent_id) = 0)