Lazarus

Free Pascal => General => Topic started by: Thaddy on September 06, 2018, 10:31:30 am

Title: Funny and dangerous..
Post by: Thaddy on September 06, 2018, 10:31:30 am
I ran into this this morning (code is over-simplified).
It is both funny and dangerous:
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode delphi}{$H+}{$endif}{$assertions on}
  2. uses
  3.   sysutils;
  4. var
  5.   a:integer = 100;
  6.   b:integer = 0;
  7. begin
  8.   try
  9.   // somebody decided to test his code with assertions
  10.     Assert( a = b );
  11.   except
  12.   // some time later, somebody (else?) decided to eat all exceptions....
  13.   end;
  14. end.

The other thing is that with this code - if you remove sysutils - the assertion is thrown anyway in FPC.

Morale: never eat exceptions: sooner or later you will choke on it....

Simplified but a true story reduced to the issue at hand: I found this in production code....
When I found it it made me sick and put on a wry smile.... 8-) O:-).

(p.s.: Delphi code, but also  Fpc...)
Title: Re: Funny and dangerous..
Post by: Ñuño_Martínez on September 07, 2018, 06:36:56 pm
Ignore exceptions is always a bad bad idea, as well as ignoring data returned by functions.  I really don't understand people who do that.
Title: Re: Funny and dangerous..
Post by: Thaddy on September 07, 2018, 08:23:41 pm
Ignore exceptions is always a bad bad idea, as well as ignoring data returned by functions.  I really don't understand people who do that.
I do: manager demands quick fix. This is how this happened. Crash-Fix-NOW!
I only do code reviews nowadays, because of my health (nothing to worry about), but this wasn't an obvious one at first sight.
There are several tens of lines in between and generally well written.

I agree, but pressure can force people into making mistakes.
Every programmer should realise that....
Even if you tell the manager this was a quick fix, you won't get the time to fix it properly....usually...
That's why they pay me. To spot those things...
Also in this case the programmers - none of them - fully understood assertions.
Title: Re: Funny and dangerous..
Post by: guest58172 on September 08, 2018, 04:10:04 am
This anti pattern is also known as Pokemon Exception Handling (http://wiki.c2.com/?PokemonExceptionHandling).
Title: Re: Funny and dangerous..
Post by: Thaddy on September 08, 2018, 07:37:23 am
Yup. but in this case - much - worse: --> I still can't stop laughing about the assertions I found and will never raise.
I believe we always warn about the "pokemon" pattern - didn't know that name - here anyway.
TinyPortal © 2005-2018