Public Group

# Using define to shorten things up

This topic is 4038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was wondering if this was a good idea, it works and seems flexible but could possibly lead to confusion and might just be bad form which is what Im here, to find out.
#define CLASS OTHER_NAME

class OTHER_NAME
{
CLASS(){};
~CLASS(){};
};

#define CLASS ANOTHER_CLASS

class ANOTHER_CLASS
{
CLASS(){};
~CLASS(){};
};


thats the basic idea, the CLASS would act like a "this" for decelerations, would make typing simpler, you wouldn't have to remember the exact spelling or punctuation of what your class is named (the idea here is that every class defines class as themselves) and might have a few other advantages but could also be confusing. I will be happy with anyone's take on this. Thanks for your time

##### Share on other sites
Wow.

Just...

That's a terrible idea.

I can't even put words to how ... yeah. I can't even put words to it.

If you're so..uh...lazy (or whatever), that you aren't even willing to remember the NAME OF THE CLASS that you're WRITING, then perhaps you should choose another hobby/job. Like lawn darts.

##### Share on other sites
It was hard for me to reply to this... as this is one of the worst ideas I have ever read so I wasn't sure what to say.

EDIT: well I guess I could have told you to start your lawn darts practice :)

##### Share on other sites
With the advent of sane tab/auto-completion, you don't need to remember the exact spelling or punctuation of your classes. #define should be used with the utmost caution.

##### Share on other sites
Why not push this further?

#define CLASS THE_NAMEclass CLASS{    CLASS(){};    ~CLASS(){};};#undef CLASS

Although I'm not sure that it actually saves any typing (the above version uses 17 characters more than if it had used the correct name. To have actual savings, you'd need to have a shortened name that's more than twice as long as the "self-ref" name, and even then, this assumes that a decent number of constructors-desctructors (most classes only have one constructor and no destructor).

##### Share on other sites
Well ok, yeah thanks for basically personally attacking me over an idea which I just thought of and just wanted your opinion on. I had no intention of following this convention as indeed I am not that lazy and think it would lead to code being unclear. As for people with respectable responses thank you. I should probably just kill the thread but as it seem that people are trying to do things more efficiently it seemed like something to mention.

Yeah I was pretty sure I would get responses saying what you guys did but thought I would throw it out there. You don't have to act personally offended or attack me.

It was an idea up for review you didn't NEED to say anything.

##### Share on other sites
Quote:
 Original post by raptorstrikeYou don't have to act personally offended or attack me.

Other than the Drilian's comment, all the posts were just attacking the idea. The idea is flat out bad.

In general macros should be avoided by better coding practices. Macros obscure code, confuse development environment, and (when they code functions) complicate debugging.

-me

##### Share on other sites
Look, it's like this:

if you ask for feedback, expect feedback. Don't expect only POSITIVE feedback. The world, and especially the Internet, is not filled with candy-cane slides and butterscotch waterfalls beneath a pure blue sky with rainbows in it. Asking for feedback means you'll get FEEDBACK, and all that that implies.

If you ask for feedback on a bad idea that seems designed for no other purpose than that (In your own words!) "you wouldn't have to remember the exact spelling or punctuation of what your class is named," expect harsh feedback accordingly, especially when it sounds like your rationale stems from not even wanting to have to know the name of whatever it is that you're programming.

If you EXPECTED people to be like "wtf?" then maybe you should have thought harder about the merits of your idea before posting it. You said you were here to find out if it was bad form: it is.

As Telastyn points out, #define should be used with caution. This idea is not cautious, it's just confusing. You still have to use the name of the class when allocating it (or casting to it), so why not when writing it?

I stand by my assessment. And if you don't want feedback (even though you say you do), don't ask for it.

And if you GET feedback when you asked for it, don't tell people that they "didn't NEED to say anything." That's disingenuous.

[Edited by - Drilian on May 4, 2007 3:32:08 PM]

##### Share on other sites
This is how defines can be abused to write pascal code in C, for example.

http://worsethanfailure.com/Articles/_0x23_include__0x22_pascal_0x2e_h_0x22_.aspx

##### Share on other sites
I agree with you Drillian and I dont expect all positive feedback but if your going to give feed back make it constructive. As I recall the most constructive thing your post mentioned was lawn darts, Palidine and Telastyn have given more constructive responses pointing out what was wrong with the IDEA. Anyway I wasnt sure to post on this topic and in the future I will not post on semi questional ideas on which I want someones opinion.

• 12
• 40
• 15
• 10
• 23