Recent

Author Topic: Unexpected deprecated warnings at end of constructors  (Read 3461 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 19131
  • Glad to be alive.
Re: Unexpected deprecated warnings at end of constructors
« Reply #15 on: September 08, 2023, 09:43:21 am »
Everyone that needs to call FreeAndNil is not a proper programmer.
It means that your code is not safe and you have to review your code to avoid such nonsense.
It is very rare that FreeAndNil adds anything useful to code, very rare.
But it seems endemic on this forum... >:D
« Last Edit: September 08, 2023, 09:47:26 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Unexpected deprecated warnings at end of constructors
« Reply #16 on: September 08, 2023, 09:45:41 am »
Everyone that needs to call FreeAndNil is not a proper programmer.

It's 25 years I am not a proper programmer.
And it will be 25 years more I won't be, if God wants.
« Last Edit: September 08, 2023, 09:47:14 am by Чебурашка »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Unexpected deprecated warnings at end of constructors
« Reply #17 on: September 08, 2023, 09:49:49 am »
Everyone that needs to call FreeAndNil is not a proper programmer.
It means that your code is not safe and you have to review your code to avoid such nonsense.
It is very rare that FreeAndNil adds anything useful to code, very rare.
But it seems endemic on this forum... >:D

The equation

<you use FreeAndNil = your code isn't safe>

is undemonstrated so is just an opinion.

FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

WooBean

  • Sr. Member
  • ****
  • Posts: 303
Re: Unexpected deprecated warnings at end of constructors
« Reply #18 on: September 08, 2023, 10:57:07 am »
Everyone that needs to call FreeAndNil is not a proper programmer.
It means that your code is not safe and you have to review your code to avoid such nonsense.
It is very rare that FreeAndNil adds anything useful to code, very rare.
But it seems endemic on this forum... >:D

Lazarus is full of "FreeAndNil"s, especially at various "Clear" methods implementations.
Let us say that at least not every Lazarus co-author is not a proper programmer.



Platforms: Win7/64, Linux Mint 22.1 Xia

Bart

  • Hero Member
  • *****
  • Posts: 5715
    • Bart en Mariska's Webstek
Re: Unexpected deprecated warnings at end of constructors
« Reply #19 on: September 08, 2023, 11:07:01 am »
This is getting off-topic (the discussion about FreeAndNil).

This post is about he compiler misplacing the warning (e.g. the x,y coördinates in the message are wrong).
To me that sounds like a bug and it may be worth while posting it in the bugtracker with a small demo.

Bart

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Unexpected deprecated warnings at end of constructors
« Reply #20 on: September 08, 2023, 11:27:46 am »
Quote from: Bart link=topic=64516.msg490862n't #msg490862 date=1694164021
This post is about he compiler misplacing the warning (e.g. the x,y coördinates in the message are wrong).
To me that sounds like a bug and it may be worth while posting it in the bugtracker with a small demo.
Actually is about compiler generating an extra warning at the place the OP doesn't expect it, i.e. doesn't call Destroy explicitly, but the compiler puts an implicit call there in the case of unhandled exception.   
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Unexpected deprecated warnings at end of constructors
« Reply #21 on: September 08, 2023, 11:56:28 am »
I am very sorry that some replies included this things related to the usage of Destroy/Free/FreeAndNil, that have nothing to do with my original question. In my opinion, I find that it has been already told many times about this, and the ones who continue to point it out are somehow wasting other's time.

If I knew I'd write the software example direclty in the "recommended way" in order to avoid them to write the usual useless replies.

Code: Pascal  [Select][+][-]
  1.   x := TMyClass.Create();
  2.   try
  3.     // ...
  4.   finally
  5.     {$IFDEF Thaddy}x.Free();{$ELSE}FreeAndNil(x);{$ENDIF}
  6.   end;
  7.  
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Unexpected deprecated warnings at end of constructors
« Reply #22 on: September 08, 2023, 12:00:46 pm »
Quote from: Bart link=topic=64516.msg490862n't #msg490862 date=1694164021
This post is about he compiler misplacing the warning (e.g. the x,y coördinates in the message are wrong).
To me that sounds like a bug and it may be worth while posting it in the bugtracker with a small demo.
Actually is about compiler generating an extra warning at the place the OP doesn't expect it, i.e. doesn't call Destroy explicitly, but the compiler puts an implicit call there in the case of unhandled exception.

The point could be summarized/generalized as: is it right that an implicit call (made by compiler) to a deprecated method generates a warning like explicit calls (made by programmer) do?
« Last Edit: September 08, 2023, 12:02:37 pm by Чебурашка »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Unexpected deprecated warnings at end of constructors
« Reply #23 on: September 08, 2023, 01:10:24 pm »
@Чебурашка
I'm curious, why would you declare the destructor as deprecated?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Unexpected deprecated warnings at end of constructors
« Reply #24 on: September 08, 2023, 01:18:38 pm »
@Чебурашка
I'm curious, why would you declare the destructor as deprecated?

Because I need the compiler to tell me all places where objects are used/constructed/destructed, because I need move this class' usage within a wrapper class and I want the compiler to help me to do the transition process and prevent (actually warn) from future access to the deprecated. The final goal is that this class can be manually constructed destructed in special cases (and in that case I will manually silence tha warning), but normal usage has to be mediated by a wrapper. Just to add mode details is a set of objects related to database connections, transactions, queries and so on.

Databases are the Viet-nam of programming.
Except for proper programmers.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Unexpected deprecated warnings at end of constructors
« Reply #25 on: September 08, 2023, 01:38:39 pm »
@Чебурашка
I'm curious, why would you declare the destructor as deprecated?

Because I need the compiler to tell me all places where objects are used/constructed/destructed, because I need move this class' usage within a wrapper class and I want the compiler to help me to do the transition process and prevent (actually warn) from future access to the deprecated. The final goal is that this class can be manually constructed destructed in special cases (and in that case I will manually silence tha warning), but normal usage has to be mediated by a wrapper. Just to add mode details is a set of objects related to database connections, transactions, queries and so on.

Databases are the Viet-nam of programming.
Except for proper programmers.
I see. But usually Destroy never gets called directly and deprecated is used for old/bad methods, etc. IMO that warning is quite reasonable.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Bart

  • Hero Member
  • *****
  • Posts: 5715
    • Bart en Mariska's Webstek
Re: Unexpected deprecated warnings at end of constructors
« Reply #26 on: September 08, 2023, 11:44:49 pm »
Reported as issue #40434.

Bart

 

TinyPortal © 2005-2018