Recent

Author Topic: Funny and dangerous..  (Read 3352 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Funny and dangerous..
« 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...)
« Last Edit: September 06, 2018, 10:44:35 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Funny and dangerous..
« Reply #1 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.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Funny and dangerous..
« Reply #2 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.
« Last Edit: September 07, 2018, 08:37:32 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

guest58172

  • Guest
Re: Funny and dangerous..
« Reply #3 on: September 08, 2018, 04:10:04 am »
This anti pattern is also known as Pokemon Exception Handling.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Funny and dangerous..
« Reply #4 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.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018