Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-01

Classes with abstract methods

15 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Damien Gerard

With fpc you can get "myfile.pas(77,47) Warning: Constructing a class "xxxx" with abstract methods"
I just would like to know why it is allowed to build classes with abstract methods. AFIK it is different from other compilers and it is a bit strange for me.

Damien Gerard Le temps n'a pas d'importance. Seul le code est important -- (f00ty)
Michael Van Canneyt
to Damien Gerard
Damien Gerard wrote 6 lines
With fpc you can get "myfile.pas(77,47) Warning: Constructing a class "xxxx" with abstract methods" I just would like to know why it is allowed to build classes with abstract methods. AFIK it is different from other compilers and it is a bit strange for me.

Delphi gives exactly the same warning.

It is allowed to create such instances: as long as you don't call any of the abstract methods, there will be no problem.

Michael.

Damien Gerard
to Michael Van Canneyt
Michael Van Canneyt wrote 15 lines
On Mon, 14 Jan 2008, Damien Gerard wrote: > > With fpc you can get "myfile.pas(77,47) Warning: Constructing a > class "xxxx" > with abstract methods" > I just would like to know why it is allowed to build classes with > abstract > methods. AFIK it is different from other compilers and it is a bit > strange for > me. Delphi gives exactly the same warning.

I don't remember that.

It is allowed to create such instances: as long as you don't call any of the abstract methods, there will be no problem.

Is there a way to abort the compilation in this cases instead of a warning ?

Damien Gerard Le temps n'a pas d'importance. Seul le code est important -- (f00ty)
Michael Van Canneyt
to Damien Gerard
Damien Gerard wrote 19 lines
On Jan 14, 2008, at 10:27 AM, Michael Van Canneyt wrote: > > >On Mon, 14 Jan 2008, Damien Gerard wrote: > > > > >With fpc you can get "myfile.pas(77,47) Warning: Constructing a class > >"xxxx" > >with abstract methods" > >I just would like to know why it is allowed to build classes with abstract > >methods. AFIK it is different from other compilers and it is a bit strange > >for > >me. > >Delphi gives exactly the same warning. I don't remember that.

D:\Temp>dcc32 unit1
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Clear' Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Delete' Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Insert' Unit1.pas(32) Hint: Value assigned to 'T' never used Unit1.pas(36)
37 lines, 0.11 seconds, 475 bytes code, 8 bytes data.

Show quoted text 6 lines
>It is allowed to create such instances: as long as you don't call any of the >abstract methods, there will be no problem. Is there a way to abort the compilation in this cases instead of a warning ?

Currently not.

Michael.

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
> > Is there a way to abort the compilation in this cases instead of a warning ? Currently not.

If you want to be that strict, then use Interfaces instead of Abstract classes.

-
Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Damien Gerard
to Michael Van Canneyt: D:\Temp>dcc32 unit1 Borland Delphi Version 15.0 Copyright (c) 1983,2002 Borland Software…
Michael Van Canneyt wrote 40 lines
On Mon, 14 Jan 2008, Damien Gerard wrote: > > On Jan 14, 2008, at 10:27 AM, Michael Van Canneyt wrote: > >> >> >> On Mon, 14 Jan 2008, Damien Gerard wrote: >> >>> >>> With fpc you can get "myfile.pas(77,47) Warning: Constructing a >>> class >>> "xxxx" >>> with abstract methods" >>> I just would like to know why it is allowed to build classes with >>> abstract >>> methods. AFIK it is different from other compilers and it is a >>> bit strange >>> for >>> me. >> >> Delphi gives exactly the same warning. > > I don't remember that. D:\Temp>dcc32 unit1 Borland Delphi Version 15.0 Copyright (c) 1983,2002 Borland Software Corporation Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Clear' Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Delete' Unit1.pas(32) Warning: Constructing instance of 'TStrings' containing abstract method 'TStrings.Insert' Unit1.pas(32) Hint: Value assigned to 'T' never used Unit1.pas(36) 37 lines, 0.11 seconds, 475 bytes code, 8 bytes data.

Yes I trust you don't wory, just my mind is playing with me :)

Show quoted text 10 lines
> >> It is allowed to create such instances: as long as you don't call >> any of the >> abstract methods, there will be no problem. > > > Is there a way to abort the compilation in this cases instead of a > warning ? Currently not.

Thanks

Damien Gerard Le temps n'a pas d'importance. Seul le code est important -- (f00ty)
Damien Gerard
to Graeme Geldenhuys: If you want to be that strict, then use Interfaces instead of Abstract classes. - -…
Graeme Geldenhuys wrote 9 lines
On 14/01/2008, Michael Van Canneyt wrote: >> >> Is there a way to abort the compilation in this cases instead of a >> warning ? > > Currently not. If you want to be that strict, then use Interfaces instead of Abstract classes.

Indeed I should do this. Thanks

Damien Gerard Le temps n'a pas d'importance. Seul le code est important -- (f00ty)
Matt Emson
to Graeme Geldenhuys: If you want to be that strict, then use Interfaces instead of Abstract classes. - -…
Graeme Geldenhuys wrote 8 lines
On 14/01/2008, Michael Van Canneyt wrote: >> Is there a way to abort the compilation in this cases instead of a warning ? >> > Currently not. > If you want to be that strict, then use Interfaces instead of Abstract classes

I always found (and still do in C#) that interfaces are good for forcing structure but bad for forcing good inheritance trees. The good thing about classes with abstract methods is that they form a point for inheritance. Interfaces - well, I regularly use interfaces to create a common structure, e.g. an API that will have both a webservice interface and a local interface. The common API is an interface in a separate assembly, used on both client and server to implement an identical API (client code can then link to either the local API or the webservice via a client that implements the same interface.) DotNet also makes reflection (RTTI) quite useful with interfaces too, but I digress. The point is that the webservice class, the client and the local API that the webservice wraps all implement the interface (the webservice usually just delegates responsibility to an internal instance), but none of them inherit from each other.

Peter Vreman
Show quoted text 7 lines
> >It is allowed to create such instances: as long as you don't call any of the > >abstract methods, there will be no problem. > > > Is there a way to abort the compilation in this cases instead of a warning ? Currently not.

You can abort compilation in case of any warning with the -Sew option. The same goes for note or hint with -Sen or -Seh, but those are only usefull for compiler tests.

Peter

Michael Van Canneyt
to Peter Vreman
Peter Vreman wrote 10 lines
>> >It is allowed to create such instances: as long as you don't call any of the >> >abstract methods, there will be no problem. >> >> >> Is there a way to abort the compilation in this cases instead of a warning ? > > Currently not. You can abort compilation in case of any warning with the -Sew option. The same goes for note or hint with -Sen or -Seh, but those are only usefull for compiler tests.

The problem with this mechanism is that if you have another warning which occurs first, that will stop your compilation, you'll never get to the abstract warning...

Michael.

Damien Gerard
to Michael Van Canneyt
Michael Van Canneyt wrote 23 lines
On Mon, 14 Jan 2008, Peter Vreman wrote: >>>> It is allowed to create such instances: as long as you don't >>>> call any of the >>>> abstract methods, there will be no problem. >>> >>> >>> Is there a way to abort the compilation in this cases instead of >>> a warning ? >> >> Currently not. > > You can abort compilation in case of any warning with the -Sew > option. The same goes for note or > hint with -Sen or -Seh, but those are only usefull for compiler > tests. The problem with this mechanism is that if you have another warning which occurs first, that will stop your compilation, you'll never get to the abstract warning...

I agree.
May be a new option in a future release of fpc ? :) It would be nice to have a switch to do it.

Damien Gerard Le temps n'a pas d'importance. Seul le code est important -- (f00ty)
Jonas Maebe
to Damien Gerard
Damien Gerard wrote 10 lines
On Jan 14, 2008, at 11:55 AM, Michael Van Canneyt wrote: > The problem with this mechanism is that if you have another > warning which occurs first, > that will stop your compilation, you'll never get to the abstract > warning... I agree. May be a new option in a future release of fpc ? :) It would be nice to have a switch to do it.

There is already a feature request for the ability to turn off/on certain warnings in Mantis. Upgrading certain warnings (and hints/ notes) to errors is quite related. It should be quite doable for an outsider to implement this sort functionality, but until now no one has volunteered yet.

Jonas

Damien Gerard
to Jonas Maebe
Jonas Maebe wrote 19 lines
On 14 Jan 2008, at 14:43, Damien Gerard wrote: > On Jan 14, 2008, at 11:55 AM, Michael Van Canneyt wrote: > >> The problem with this mechanism is that if you have another >> warning which occurs first, >> that will stop your compilation, you'll never get to the abstract >> warning... > > I agree. > May be a new option in a future release of fpc ? :) > It would be nice to have a switch to do it. There is already a feature request for the ability to turn off/on certain warnings in Mantis. Upgrading certain warnings (and hints/ notes) to errors is quite related. It should be quite doable for an outsider to implement this sort functionality, but until now no one has volunteered yet.

I see. I will see what I can do next month.

Damien Gerard Le temps n'a pas d'importance. Seul le code est important -- (f00ty)
Peter Vreman
Show quoted text 14 lines
>> The problem with this mechanism is that if you have another >> warning which occurs first, >> that will stop your compilation, you'll never get to the abstract >> warning... > > I agree. > May be a new option in a future release of fpc ? :) > It would be nice to have a switch to do it. There is already a feature request for the ability to turn off/on certain warnings in Mantis. Upgrading certain warnings (and hints/ notes) to errors is quite related. It should be quite doable for an outsider to implement this sort functionality, but until now no one has volunteered yet.

Upgrade a warning to error can already be done by editing (replace a W with an E) the errore.msg yourself and pass the modified errore.msg to the compiler with -Fr.

Peter

Jonas Maebe
to Peter Vreman
Peter Vreman wrote 9 lines
> There is already a feature request for the ability to turn off/on > certain warnings in Mantis. Upgrading certain warnings (and hints/ > notes) to errors is quite related. It should be quite doable for an > outsider to implement this sort functionality, but until now no one > has volunteered yet. Upgrade a warning to error can already be done by editing (replace a W with an E) the errore.msg yourself and pass the modified errore.msg to the compiler with -Fr.

You can similarly downgrade a warning to a note or hint by changing the W with a N or H, but the problem is that you have to redo this for each release.

Jonas