вторник, 11 августа 2015 г.

Briefly. I exported the dictionaries

Original in Russian: http://programmingmindstream.blogspot.ru/2015/07/blog-post_29.html

Follow-up to - Briefly. Wonder of words redefining.

The example:

Here is our code:

UNIT uA
 
PROCEDURE A
...
; // A
 
...
 
UNIT uB
 
USES
 uA
;
 
PROCEDURE B
...
 A // - compilable due to USES uA
; // B
 
UNIT uC
 
USES
 uB
;
 
PROCEDURE C
...
 B // - compilable due to USES uB
 A // - NOT compilable due to no USES uA
; // C

How can we improve it?

Here’s an option:

UNIT uA
 
PROCEDURE A
...
; // A
 
...
 
UNIT uB
 
USES
 uA
;
 
PROCEDURE B
...
 A // - compilable due to USES uA
; // B
 
UNIT uC
 
USES
 uA
 uB
;
 
PROCEDURE C
...
 B // - compilable due to USES uB
 A // - compilable due to USES uA
; // C

Another option:

UNIT uA
 
PROCEDURE A
...
; // A
 
...
 
UNIT uB
 
USES
 uA
;
 
EXPORTS uA // - exports module uA, it would be visible for THOSE containing OUR module uB
 
PROCEDURE B
...
 A // - compilable due to USES uA
; // B
 
UNIT uC
 
USES
 uB
;
 
PROCEDURE C
...
 B // - compilable due to USES uB
 A // - compilable due to EXPORTS uA in module B
; // C

Why do we need it?

It is very useful for writing the “facade layers” in case we need to isolate layers, on the one hand, and let them "do more than they can"? on the other hand.

It is really useful.

It is more so since we have the FORGET word that allows making the word not visible.

There is also a structure:

EXPORTS *

It means “export all dictionaries added to our dictionary through USES".

There is another structure:

EXPORTS A :: X

This one means “export the X word in the A dictionary from our dictionary”.

There is one more structure:

EXPORTS A :: X AS Y

This one means “export the X word in the A dictionary from our dictionary with the name Y”.

Actually, there is a problem.

We’ve got Enum = (one, two, three) in the module A.

The B module defines the X function that works with Enum.

It is clear that B does USES A and can see the members of Enum.

Finally, the C module does USES B and uses the X function.

So, in order to use the elements of Enum, it has to do USES A.

The aim is to “see” one, two, three.

We can also do EXPORTS A in the B module or EXPORTS A :: Enum.

As a result, the C module will not have to do USES A.

It will see what it needs using due to USES B and EXPORTS A :: Enum.

When I was writing these USES with my hands - that is quite fun… But when you place arrows on the model that is crazy...

That is where EXPORTS come for help.

Yes, C++ has through include, but there are other problems about architecture layers isolation.

I understand why it has something in common with Python.




Комментариев нет:

Отправить комментарий