Macros

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Macros

Post by LuX » July 7th, 2012, 2:33 pm

Well, I'm glad we got to some sort of an agreement,... wait... did we?
chili wrote:makes your code that much more difficult for other people to decipher
Maybe if I used some hardcore multiple lines long macro. My timer example would make it look a lot simple. You see I use timer macro -> look at the macro definition -> realize what it does.

Is it really nessesary to write my timer code over and over again, when a macro could be used? You don't need to see the clockwork each time to know how it works... It's not like we copy paste the line draw function each time we want to draw a line.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Macros

Post by Asimov » July 7th, 2012, 2:36 pm

Hi Lux,

Surely you don't have to write your timer code over and over again.
Surely you can put it in a class and just call the class. Same thing done without a macro and is safer.

And you can even call your time code class within another class.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Macros

Post by LuX » July 7th, 2012, 2:43 pm

True, I could even make a function of it. But I don't see the point in this case, as the risk of making a mistake is about 0.

To say it again, I never mean to use macros for anything more complex than this. I would rather use a function, maybe even an inline function which should be about the same as a macro, just safer.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Macros

Post by chili » July 7th, 2012, 2:48 pm

LuX wrote:Well, I'm glad we got to some sort of an agreement,... wait... did we?
chili wrote:makes your code that much more difficult for other people to decipher
Maybe if I used some hardcore multiple lines long macro. My timer example would make it look a lot simple. You see I use timer macro -> look at the macro definition -> realize what it does.

Is it really nessesary to write my timer code over and over again, when a macro could be used? You don't need to see the clockwork each time to know how it works... It's not like we copy paste the line draw function each time we want to draw a line.
Brah, if I saw this code chillin' out in the middle of your function, the first thing I would think is "LuX has gone and lost his mind" :lol: :

Code: Select all

Timer (Calc, 1000,                                           /* Calc = timer object, 1000 = interval */
    AVGT = 0;                                                /* Set average time to 0 */
    for (int n = 0; n < 60; n ++) {AVGT += AverageTime[n];}  /* Add all past execution times together */
    AVGT /= 60;                                              /* Divide for obvious reasons */
)
It's not standard syntax at all, and it would leave most people scratching their heads. Sure, they'd figure out what you're doing here eventually, but not nearly as easily as if you just typed it out (or better yet, refactored it into the form of a function).
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Macros

Post by Asimov » July 7th, 2012, 2:52 pm

Hi Lux,

I suppose it is like this God created the heavens and the Earth and in his wisdom he told people not to kill people, cause it ain't a good idea, but people did go about killing people LOL.

PS I don't believe in god heh heh, but it made a good analogy.

It is like the dreaded 'goto' command, which makes program flow hard to follow.
It is there, but it isn't really necessary to use it.
In the old days I used to use it for everything in BASIC, but up until recenlty I didn't even realise it was a C++ command, but so far haven't found a use for it heh heh.

PPS do you think Lordi is the best ever rock band to come out of Finland?

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Macros

Post by chili » July 7th, 2012, 2:54 pm

Hehe, I've always known about the goto in C, but to this day I have avoided using it even once. 8-) And I have written a fair amount of C code in my life.
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Macros

Post by LuX » July 7th, 2012, 3:01 pm

@chili
Hmm... Well, I'll still probably use something similar, maybe invest time on inline functions, which should be the optimal compromise?

But I hope you understand my need to get an actual argument as to why it's bad to use it rather than, "their evil because they are" or "they are bad because some experts say so" or "they are bad because I could come up with a couple situation where it was"

If someone told you 2 + 2 = 5, would you not try to convince this person otherwise, unless he can prove it somehow? I've so far read online about how they are bad, how they are not, and then people like me "if it's simple, do it".

@Asimov
do you think Lordi is the best ever rock band to come out of Finland?
No, never liked poser bands. I'm more into underground bands and classic hard rock/thrash metal.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Macros

Post by Asimov » July 7th, 2012, 10:51 pm

Hi Lux,

I don't like poser bands if they are just poser bands. I actually like the music too. I like the music of Kiss as well, and they are the biggest theatrical bands in the world. Even King Diamond were very theatrical and they've had about 10 albums out. Alice Cooper is one of my all time favourites and I have seen him live a few times. He does a good show.

I do like bands like Slayer, Megadeth, Metallica and Iron Maiden so it kinda balences out in the end heh heh.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply