.comment-link {margin-left:.6em;}
Marc Boizeau's blog
Sunday, January 23, 2005
  Code generation and self description
A few weeks ago I proposed here an example of C# code generation.
It remind me an old exercise I used to do when discovering a new language.
"The shortest program which produce its own source code on the standard output."
Of course, programs which read explicitly their source code to reproduce it are not accepted.
The idea of the exercise is to find self reference possibilities offers by the language.
I've put the executable here and the source code is hereJust download and then launch the echo.exe then click the "itself" button , the complete source code is displayed in the upper richtext box. Then click the "compile" button , the source code is compiled and saved in c:\echo.exe (be careful not to replace a program of your owns).
Just launch this new program and compare with the first one.... If you want, you can try to change the code to see effects (debug information shown in the second box).

Briefly the principles:
I used a double coding representation. The C# code contains in one point a string array declaration with all the lines of the code between "" and coma separated. All the line of the code ? Not exactly, the array declaration is replaced into the array itself by an arbitrary string (I choose a French poet's famous verses). When you click the "it self" button this exact string is replace by a construction of the array declaration. So at this time the array contains all the code including its own declaration. Then a "foreach" instruction join all the lines into one big string which is the exact source code.
When you push the "compile" button the text box content is compiled .

There is two key factors in this very solution (I'm sure there is at least another solution ).
- The declaration syntax of an array in C# which authorize long static arrays.
- The compilation feature of the .Net framework.

The main part of the code is writed two times. Maybe there is no true connection with this but I can't help comparing this to the double-helix DNA in living cells.

The comparison with living cells ends here. This code isn't (AFAIK) a kind of virus or worm and can't be used for malicious purpose. (For instance, runtime compiling features can't be used during an in-line context).

Ok, now, two questions :

- Is it possible to code that kind of program in PL-SQL? (;-))
Maybe next time !
- The array based solution is interesting but it doesn't imply the Icodegenerator interface. Is there a solution using a more sophisticated structure than an array?
For instance is it possible that a program build its own abstract description usng this interface?

That's all folks !
Remember there is 10 sorts of people : those who understand native binary code and the others !

Comments, answers and suggestions are welcome!
Tuesday, January 18, 2005
A few links today:

C# tutorial and offshore development - dotnetspider offers online training, C# tutorials, offshore development, software outsourcing, link search and sample C# projects with source code.

http://blog.spsclerics.com A Colleague of mine. This blog is mainly about Microsoft Sharepoint portal Server. But you will also find things about C#, .net technology (and the authour's hollidays;-)
that's all folks
Thursday, January 13, 2005
  Oracle data dictionary
Hello everybody (Happy coding and merry source code for 2005! )

Today I would like to talk about Oracle data Dictionary.
Without any administration tool it's possible to retrieve information about tables,views and constraints.
To understand this article you need an Oracle client connected to a valid schema.
(SQL+ for instance)

First I suggest you to try this syntax:
select * from DICT
This query returns all the views dealing with this schema's dictionary, very useful to retrieve the exact name of a view. The dictionary contains a big amount of views, let's focus on a few one:

Imagine you want to list all the tables you can acces in a schema, you may then try the following:

If you're not a DBA but a developer you may just be interested in your own tables. So try this one:
WHERE OWNER ='My_name'

The same thing about views:
WHERE OWNER ='My_name'

Now imagine you need to know all the constraints of a table :
table_name= 'My_table'

That is useful, but you may want something more fine tunned:
What are the foreign keys?:
and table_name= 'My_table'

What is the primary key? :
and table_name= 'My_table'

That's interesting but most of the time you need the name of a field. So, the following retrieves the list of all the fields included in the primary key:
and C.TABLE_NAME= 'My_Table'

That's all folks !
Hope this helps, comments are welcome!
You are a developer and work with Oracle and Microsoft technologies? Have a look!
How to:
Use updatable views in Access
Get data in Excel from Oracle 1
Get data in Excel from Oracle 2
Draw the Mandelbrot set using C#
Use the "Grouping Sets" SQl Syntax
Use the "Rollup" SQl Syntax
Use the "Rank over" SQl Syntax

Go to knol
When does the next bus pass?
two lines in the datagrid header
Context saving with persistent datasets
.net webservice session
Winform, Web Services & credential
back to work
just a link
October 2004 / November 2004 / December 2004 / January 2005 / February 2005 / March 2005 / April 2005 / June 2005 / July 2005 / August 2005 / September 2005 / December 2005 / February 2006 / December 2006 / March 2009 /

Powered by Blogger