Should preprocessors and includes be used in in OO?

Posted by Tung on 10-Jan-2017 05:47

Hi

I'd normally use include files only to define datasets, variables, etc. But we have code that uses preprocessors and includes to create and assign a temp-table record, perform a LOOKUP function on a list, etc.

They were used in our application's ABL windows but they've been carried over to the new .NET forms and classes.

Is this good practice or something to avoid?

Thanks

Tung

Posted by Mike Fechner on 10-Jan-2017 07:16

You’ll see probably others here that will fundamentally ban include and preprocessors from OO code.
 
My suggestion is to review if there are suitable alternatives! Many of the includes you describe may be replaced by static calls into helper classes. Others may not.
 
But other includes may still be useful. We have implemented loops on OO Enumerable classes (the foreach of C#) in include files. IMHO you can’t write better readable code in those cases without include files.
 
But that should be a careful case by case review.
 

All Replies

Posted by Mike Fechner on 10-Jan-2017 07:16

You’ll see probably others here that will fundamentally ban include and preprocessors from OO code.
 
My suggestion is to review if there are suitable alternatives! Many of the includes you describe may be replaced by static calls into helper classes. Others may not.
 
But other includes may still be useful. We have implemented loops on OO Enumerable classes (the foreach of C#) in include files. IMHO you can’t write better readable code in those cases without include files.
 
But that should be a careful case by case review.
 

Posted by Tung on 10-Jan-2017 08:11

I agree includes are necessary sometimes (or maybe I didn't know enough to do some coding without resorting to includes) but I avoid them if I can. And I understand using a preprocessor for a constant value, that may be similar to constants that I see in msdn examples.

As I'm at a new company, I'll try to persuade them away from preprocessors and includes where they can be done as methods in the new OO programs. They do use a lot of them so I'm not sure how successful I'll be.

Posted by Peter Judge on 10-Jan-2017 08:16

+1
 
You don’t have to remove them but there’s no reason to add more willy-nilly*
 
 
 
 
 

Posted by Patrick Tingen on 11-Jan-2017 14:34

I agree with the gentlemen above me; includes and preprocessors are fine tools, but you should use them with care and certainly not too much. Especially large preprocessor blocks (you can even nest them) can make your life horrible.

This thread is closed