PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Language enhancement request 1 Generic programming
Language enhancement request 1 Generic programming
Débuté par BLS, 22 sep. 2008 20:27 - 2 réponses
Posté le 22 septembre 2008 - 20:27
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
.....

Now we can create our stack instance like :
intstack is cGenericStack([int])
or
objectStack is cGenericStack([object])
or
dateStack is GenericStack([date])

What do ya think ?
Bjoern Lietz-Spendig

Even better, cSpecialGenericStack( [T as cWindow] )
// only objects with cWindow as base class are allowed.

cWindowStack is cSpecialGenericStack([ cMDIChildWindows] )

Yeah, guess I am asking for too much now :)
Posté le 23 septembre 2008 - 02:00
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
International WinDev, WebDev and WinDev mobile Consulting

More information on http://www.fabriceharari.com


BLS wrote:
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
.....

Now we can create our stack instance like :
intstack is cGenericStack([int])
or
objectStack is cGenericStack([object])
or
dateStack is GenericStack([date])

What do ya think ?
Bjoern Lietz-Spendig

Even better, cSpecialGenericStack( [T as cWindow] )
// only objects with cWindow as base class are allowed.

cWindowStack is cSpecialGenericStack([ cMDIChildWindows] )

From: Fabrice Harari <fromweb@fabriceharari.com>
Newsgroups: pcsoft.us.windev
Message-ID: <48d7a96c$1@news.pcsoft.fr>
References: <86f0f302289b2ca1a1f6a40c7ade32ec@news.pcsoft>
Subject: Re: Full Text Search
Approved: moderateur@pcsoft.fr
NNTP-Posting-Host: 172.18.0.210
Date: 22 Sep 2008 17:00:43 +0100
X-Trace: news.pcsoft.fr 1222095643 172.18.0.210 (22 Sep 2008 17:00:43 +0100)
Approved: moderateur@pcsoft.fr
Lines: 37
X-Authenticated-User: moderateur
Path: news.pcsoft.fr!not-for-mail
Xref: saphir pcsoft.us.windev:15963


Hi Marco...

2 answers:

1. slow method: you read all records one after the other and do a
position in the memo (nothing to do to prepare, very slow to find results)

2. you create a dictionary:
Each time you add/modify the memo, you add each and every word contained
in it to a dictionary file organized as follow:
Key (not unique): The word itself
Record Number in which the word is contained
Optionally, File containing the word (can be done on multiple files)
Optionally, field containing the word (can be done on every text fields
of a record)
Optionally, position of the word in the field

When you want to search for a word, you search on the dictionary, then
you open display the corresponding records of the main files...

It's extremely fast to get an answer, but takes some time each time you
add/modify a record

Best regards
Posté le 24 septembre 2008 - 01:57
Fabrice Harari schrieb:
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

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

Even type-less parameter passing has nothing to do with generic
programming. It's just syntactice 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
(not 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 alorithms.

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

Kind regards, Bjoern