Using define to shorten things up

Started by
13 comments, last by MaulingMonkey 16 years, 11 months ago
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
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
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.
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 :)
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.
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).
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.
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:Original post by raptorstrike
You 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
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]
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

http://worsethanfailure.com/Comments/_0x23_include__0x22_pascal_0x2e_h_0x22_.aspx#25007

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.
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie

This topic is closed to new replies.

Advertisement