Welcome! Log In Create A New Profile

Advanced

Language enhancement request 1 Generic programming

Posted by BLS.pcs.crosspost 
BLS.pcs.crosspost
Language enhancement request 1 Generic programming
September 22, 2008 06:26PM
Hello WD community.

A thing I really miss in W-Language is Generic, respective Meta-Programming.

For instance :
I would like to implement a simple stack class ...

cStringStack is class()
PRIVATE
stack is array of 0 string

PROCEDURE push()

PROCEDURE pop()

PROCEDURE count()


In case that I need a Integer stack class I've to redefine the whole stuff..

Otherwise, if we have generic support we are able to do something like
that :

cGenericStack is class( [T] )
PRIVATE
stack is array of 0 T // That's the point
Message forwarded from pcsoft.us.windev
Peter Holemans
Re: Language enhancement request 1 Generic programming
September 22, 2008 09:04PM
Hi Björn,

Moving to C# or Java might resolve this... I know this sort of features is native within .Net C#.

Of course there is the fact that the W-language is pretty proprietary with very small user communities (creating open/commercial source projects) but it certainly has its place and merits for certain development projects. Most of my customers are pretty happy on a cost/result basis with what's coming out of WinDev/WebDev. For larger complex composite distributed software projects on the other hand I recommend one of the languages (C#, Java) above where you'll find numerous (free and commercial) frameworks (supported by global large communities) you can choose from to support your development. e.g. ORM (Object Relational Mapping) frameworks, RAD fetaures etc...

Just my 2 cents!
Mourillon
Re: Language enhancement request 1 Generic programming
September 23, 2008 03:57AM
Have you tried to define the stack as an array of variant?
Quote
Mourillon
Have you tried to define the stack as an array of variant?

Yeah, nice .. what about a stack class that should be able to push and pop my brand new FancyClass instances


s is cVARIANTStack

c is FancyClass

s
s.push(c) // Njet. Ne, Never, You stink


The crosspost stuff don't work 50 percent of my msg; from news.pcsoft.fr has a nirwana party now..

So here my answer to Fabrice H. answer. Hope that clarifies the stuff a bit smiling smiley

Hi Bjorn...

considering that you do NOT HAVE TO specifically type the parameters in
a class, nothing prevents you from coding it for multiple types of
parameters and testing which type was sent...

If I understood correctly your question of course :-)

Best regards
-- Fabrice Harari

Bonjour Fabrice,
Malheureusment tu n'as pas raison ...

Even type-less parameter passing has nothing to do with generic programming. It's just syntactic sugar.

consider :
#1
cGenericStack is class
PRIVATE
stack is array of 0 TYPE
constructor(TYPE)
...
/*
Sure... this will not compile !
But is doable in
Java, C#, C++ D .....
*/

Next, a NOT WORKING RUNTIME EVALUATION -Generic programming try :

#2
cGenericStack is class

    constructor(TYPE)

    SWITCH TypeVar(TYPE)
        CASE wlInt
            stack is array of 0 int
           
        CASE wlReal
            stack is array of 0 real   // FAILS
           
           
        CASE wlInstance
            stack is array of 0 object dynamic /FAILS
    END   
END


FAILS :
Erreur :La déclaration de la variable locale 'stack' est interdite car il existe déjà une variable locale 'stack' .

While
#3
COMPILE TIME EVALUATION // Mr. Compiler is generating adequate code!
cGenericStack is class([T])  // syntax stolen from Eiffel ...
    PRIVATE
    stack is array of 0 T
will work, and in opposite to # 2 this is a compile time solution, not a (non working) runtime solution. (Sanity and Speed.)

Fabrice,
I am not asking for features that will enable me to implement STL in WINDEV ... ridiculous ... I am just asking for a minor language enhancement that will give "Average Joe Coder" the chance to implement some simple algorithms.

Too difficult for 4GL developers ? Not nessesarily, I mean a 4/5GL tool should make this a piece of cake.

Kind regards, Bjoern


Hello Peter! How are you ? Glad to here your noise again smiling smiley

Seems you are diving into C#. (like this language very much too) ... I am using the D programming language instead (native compiler) .. Java sure, as WB replacement but wait, not at all.
Link to an interview with SUN employee Geertjan Wielanga and me ...
(if you like) [blogs.sun.com]

Regarding language enhancement req:

I am NOT asking for features that will enable me to implement STL in WINDEV ... ridiculous ... I am just asking for a minor language enhancement that will give "Average Joe Coder" the chance to implement some simple algorithms; without writing too much code. This should be conguent to 5GL philosophie

Well crossposting don't work ... I use : news.pcsoft.fr

Kind regards, and all the best, Bjoern
Alexandre Leclerc
Re: Language enhancement request 1 Generic programming
September 23, 2008 09:27PM
Hi Bjoern,

If you think about it a bit, this is almost possible. (Except for the complex type... maybe someone can find a way: in my first test, the Compile() function was not able to see my global structure. But any-way there might be a way - or maybe I made a mistake in my test... Your's to discover! smiling smiley)

But you can have a fully dynamic type class. I made a small project example... but since we can't send attachments... Here is the code. The first class is full dynamic. The seconde almost.

In both cases, there is certainly a better way to manage "Pop" but I let that part of the job for someone else. I just wanted to demonstrate that is was possible.

(But I agree, such a feature could be added easily.)

The fully dynamic class: (example of what could be done)

CFullDynamic is class
	m_ptabStack is array dynamic
END

PROCEDURE Constructor(sDataType is string)

sAllocProc is string = [
PROCEDURE AllocMyArray(MyArray)
MyArray = new array dynamic of 0 %1
]

sCom is string = Compile("AllocMyArray",StringBuild(sAllocProc,sDataType))
IF sCom="" THEN
	Exécute("AllocMyArray",:m_ptabStack)
	Compile("AllocMyArray","")
ELSE
	Error(sCom+CR+ErrorInfo())
END


PROCEDURE Destructor()


PROCEDURE Push(Item)
ArrayAdd(:m_ptabStack,Item)


PROCEDURE Pop(LOCAL Item)
i is int = :Count()

Item = :m_ptabStack
ArrayDelete(:m_ptabStack,i)

RESULT Item


PROCEDURE Count()
RESULT ArrayCount(:m_ptabStack)


The half-dynamic class (example of what could be done)

CDynamic is class
	m_ptabStack is array dynamic
END


PROCEDURE Constructor(sDataType is string)
SWITCH sdatatype
	CASE "integer": :m_ptabStack = new array dynamic of 0 int
	CASE "string": :m_ptabStack = new array dynamic of 0 strings
END


PROCEDURE Destructor()



PROCEDURE Push(Item)
ArrayAdd(:m_ptabStack,Item)


PROCEDURE Pop(LOCAL Item)

i is int = :Count()

Item = :m_ptabStack
ArrayDelete(:m_ptabStack,i)

RESULT Item


PROCEDURE Count()
RESULT ArrayCount(:m_ptabStack)


Example of usage:
// In declaration for example:
gclMyIntegers is CDynamic ("integer")
gclMyStrings is CDynamic ("string")

gclMyIntegerstongue sticking out smileyush(1)
gclMyIntegerstongue sticking out smileyush(2)
gclMyIntegerstongue sticking out smileyush(3)

gclMyStringstongue sticking out smileyush("Ya!")
gclMyStringstongue sticking out smileyush("Yes!")
gclMyStringstongue sticking out smileyush("Oui!")

gclFullString is CFullDynamic ("string")
gclFullStringtongue sticking out smileyush("Eins")
gclFullStringtongue sticking out smileyush("One")
gclFullStringtongue sticking out smileyush("Un")

// in a button (for example):

i is int
s is string
Info((gclMyIntegerstongue sticking out smileyop(i)+gclMyIntegerstongue sticking out smileyop(i))+" and "+gclMyIntegerstongue sticking out smileyop(i)+" rest "+gclMyIntegers:Count())
Info(gclMyStringstongue sticking out smileyop(s)+" and "+gclMyStringstongue sticking out smileyop(s)+" rest "+gclMyStrings:Count())

Info(gclFullStringtongue sticking out smileyop(s)+" and "+gclFullStringtongue sticking out smileyop(s)+" rest "+gclFullString:Count())


I hope that all this can give you some ideas if you have a problem to solve "now"...

Best regards.




Edited 1 time(s). Last edit at 09/23/2008 09:30PM by Alexandre Leclerc.
Hi Alexandre,
WOW, You did this in 5 minutes ? Good stuff. To quote Pulp Fiction / Y'a ma nigga smiling smiley
Seriously, your code looks pretty reasonable. Haven't tested, though.

I wrote this feature request because I prefer to write code like this in a C# /D way -> in W Language. Ands still. Generic programming generated code at compile time, your code will be evaluated at runtime. (Slower, less flexible)

However, I think your code shows why generic programming is also usable in an 4GL environment : Just compare your real world code with the pseudo code of mine. Guess the pseudo generic stuff is much easier to read/understand.
So what is your vote ? vote++ or vote--

Kind regards, and many thanks for your effort !
Bjoern Lietz-Spendig
PS / Your code should be stored somewhere...


Alexandre Leclerc
Re: Language enhancement request 1 Generic programming
September 24, 2008 03:35PM
Hi Bjoern,

I vote ++ since this is much easier if we can do something that is nearer your pseudo code. This would be an interesting feature to add to WinDev.

Also, the point is that this is kind of already possible to do it. This example I provided just proves it. From the class user perspective this is exactly like the pseudo code (but not the class internals).

So if some syntax is added to do that kind of stuff behind the scene, and support easily complex types, then we have a superb feature that allows very flexible programming.

This will also open the door to many other features that can be built around that.

Best Regards.
Hi Alexandre,
Thank you !! (hope others will join the club)
the situation reminds me a bit on a message I wrote approx. 15 month ago:
What I miss ... variadic parameters ....
Feedback was ..ahem... lousy. Nevertheless I wrote a feature request to PSS and after exchanging quit a lot of emails WD 12 comes along with variadic parameters.

Please note that I'm not saying : Hey, I made it. (Most probabely not)

Who cares, however the long time "information" exchange with the PCS engineers shows me that you need very good reasons to ask for a new language feature. (Especially the standard answer : WINDEV's W Language is a 4 GL, SO NO ! ) makes a discussion difficult. However WD 12 has variadic parameters Now.

SO : Picking Up Your Generic Stack Example and the Generic stack example will probabely convince them.


We'll see.
All the best, Bjoern
PS Peter .... Are you really voting for a language stand still sad smiley , can't believe it


To pick on your nerves, or just another good reason for generics

m_ptabStack is array dynamic // m.p. heap allocated (new)

m_ptabStack is array of 0 T // stack allocated
bjoern


Hello

I think that topics such as this are really interesting because they make me think about my current methods and expose me to new ideas, so in that spirit I would like to add to the discussion.

I appreciate the concept of STL, but I would find it hard to justify the development cost when there is little overlap in my projects and many are custom built per client in a variety of fields. At this moment I am engaged in writing a document manager, starting the design for a mobile data collection project and maintaining a large acounting project and sundry other projects. They all have vastly different graphical look and feel, but they do share some common coding which is done partly through reference to a common set of global procedures. I can't see how a template process could cover all my possibilities. In Windev I am primarily dealing with data and that data is unique to the application and its handling is unique to the application and the standard Windev tools allow me to manipulate that data any way I can think off so what is the advantage in going off to a parameterized set of procedures to do what I can already do ?

I am unfamiliar with the integer stack class concept. I know it is essentially an array where elements are added and removed but can someone give me an example of how it is used in a real life example.

Regards
Al
Hi Al,

The Java VM is a stack based machine Okay a WINDEV real life example.

A graphic editor which is able to handle (draw, move, delete) geometric objects. (circle, rectangle, etcwinking smiley

Further we would like to enable the user to group several of these objects together. (f.i. Drag them into an rectangular area ) This new graphic .object , let's call it COMPOSITE, should behave like a single simple object. In other words: a move(10,20) message send to our brand new COMPOSITE object should move all COMPOSITE members.

Ergo : Our class which represent a COMPOSITE should know about hist members.
"Hey, I am made out of 2 circles and 1 rectangle"

The first idea you probabely have is to store your members into an dynamic array, like :
COMPOSITE is class
    member is dynamic array of 0 shape // shape is the abstract base class of circle, rect..
END

// a better solution is to use a stack !
Why ? Consider your user wants to remove an element from your composite graph. object.
(By dragging it outside of the composite graph. object)

Remember : Our Stack is a LIFO stack; Last In, First Out...

See
Gang of Four composite pattern

Bjoern
Beside such a graph editor is a great learning resource for OOP Noobs.
Bad example; should not write messages without having enough coffee. Sorry B
Hello Bjoern

Thanks for the explanation, I am glad my programming world is centred around data, and that I am unlikely to ever need to code anything like a graphics editor.

Regards
Al
Alexandre Leclerc
Re: Language enhancement request 1 Generic programming
September 25, 2008 03:30PM
Hi Bjoern,

Well, a simple example where I use home made stack in WinDev is when I must create a process that "should" be called recursively many times. Since WinDev does not "support" recursivity and since many times when you do recursivity you need starting / state maintaining / ending parameters, well, when you do a "loop" (instead of a recursive call), you must save the previous state of the parameters in a stack and process the new data. Once this data is processed, you must Pop() the previous information and process it in light of the just-processed data (which would have been a recursive call instead of a simple loop).

So a stack is required there.

Another recent example in this forum is the thread How to store a changed treeview??????? (http://forum.mysnip.de/read.php?27131,13495,13495#msg-13495).

This loop could fail but using a stack and a loop you have no problems. (The following pseudo code is not good but gives the idea why a stack is useful).


PROCEDURE IterateTree(theTree, node is string = "")
....
Stack.Put(theTree, node)

IterateAgain:
WHILE Stack.Count>0
Stack.Pop(theTree, node)
IF isNode() THEN
SaveNode()
Stack.Put(theTree, theCurrentNode) //IterateTree(theTree, thecurrentNode)
Goto IterateAgain
ELSE // Leaf
SaveLeaf()
END
END

Meta-Programming would save me a lot of work, since for every procedure I must handle false-recursive calls (loops) I must create yet-another-stack-thing for my loops. One generic class would save me a lot of time.

My two cents.
BLS.pcs.crosspost
Re: Language enhancement request 1 Generic programming
September 25, 2008 06:47PM
Alexandre, may be we should create a WD programming BLOG smiling smiley
(to publish the results, I should better say : concrete code, of our
discussion)

Bjoern
Message forwarded from pcsoft.us.windev
BLS.pcs.crosspost
Re: Language enhancement request 1 Generic programming
September 25, 2008 06:50PM
Alexandre Leclerc schrieb:
> Hi Bjoern,
> Well, a simple example where I use home made stack in WinDev is when I must create a process that "should" be called recursively many times. Since WinDev does not "support" recursivity and since many times when you do recursivity you need starting / state maintaining / ending parameters, well, when you do a "loop" (instead of a recursive call), you must save the previous state of the parameters in a stack and process the new data. Once this data is processed, you must Pop() the previous information and process it in light of the just-processed data (which would have been a recursive call instead of a simple loop).
> So a stack is required there.
> Another recent example in this forum is the thread How to store a changed treeview??????? (http://forum.mysnip.de/read.php?27131,13495,13495#msg-13495).
> This loop could fail but using a stack and a loop you have no problems. (The following pseudo code is not good but gives the idea why a stack is useful).
>
> PROCEDURE IterateTree(theTree, node is string = "")
> ...
> Stack.Put(theTree, node)
> IterateAgain:
> WHILE Stack.Count>0
> Stack.Pop(theTree, node)
> IF isNode() THEN
> SaveNode()
> Stack.Put(theTree, theCurrentNode) //IterateTree(theTree, thecurrentNode)
> Goto IterateAgain
> ELSE // Leaf
> SaveLeaf()
> END
> END
> Meta-Programming would save me a lot of work, since for every procedure I must handle false-recursive calls (loops) I must create yet-another-stack-thing for my loops.. One generic class would save me a lot of time.
> My two cents.
>
>

Hi Alexandre :
Quote :
Since WinDev does not "support" recursivity ....
End Quote

Windev supports recursive function calls. I already had a nice
discussion with Fabrice H. regarding this subject.

Means both of you are wrong. W-Language has support for resursive
function calls.
But, well W-Language recursive function calls have a limit :
stack-size is limited.

PROCEDURE OverFlow(LOCAL _newVal is int = 0, _iterations is unsigned int
= 500)
newval is int = _newVal
IF newval < _iterations THEN
newval++
OverFlow(newval)
ELSE
RESULT newval
END

//works ...
//BUT increasing _iterations to 600 -> OverFlow() already fails.*

"old school" languages like Pascal and Modula have limits similar to
W-Language. again : stack-size is limited.
The remaining question is / Is WINDEV's limited recursive function call
capability usefull ?

Give it a try : Implement a recursive GCD (greatest common divisor)
algo. in W-Language. Doable n'est pas.

In case of a Treeview control ... Can you imagine a TreeView Node that's
coming along with 500 Child nodes ?
(Will not work anyway ... See MSDN)

Bjoern
I'll pick up your (very smart) code .. generic stack and
IterateTreeVview... let's see how far we can go with it.

Many, many thank's for your feedback ! Bjoern

Beside :
The only language (I'm aware of) which lacks this feature, is FORTRAN.
(YEP, I grow up with a PDP 11)
========================================================================


Message forwarded from pcsoft.us.windev
Alexandre Leclerc
Re: Language enhancement request 1 Generic programming
September 25, 2008 07:05PM
Hi Bjoern,

Yep, I also use Recursive calling with one of my project where recursivity is under the limit, and will always be. So yes WinDev support it, to a certain "depth" (until the stack maximum limit is reached).

As for the "capability useful" aspect of such a limit, I see that it is useful in, for example, an infinite loop where the code or user code (MCU - with Compile(), etc.) has not done properly and loops forever. Then the W-Language "Errr-What-Are-You-Doing" before-crash-and-explode protection can safely say that the code is wrong and has lead to an error at line x in function so-and-so. (And maybe this is possible to catch a stack overflow error in a exception block? I don't know about that...)

Well, my 2 cents, I guess.

That was a nice thread / talk indeed.

Best regards.
Hi Alexandre,
I've enjoyed that discussion too.
Thanks, Bjoern
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: