This C programming book is so funny.

VIAN

Diamond Member
Aug 22, 2003
6,575
1
0
It's called C - How to program by Deitel or something.

It's taught me everything, I'm up to Functions and stuff.

Chapter 5 called Functions, Chapter 6 is called arrays.

Chapter 5 teaches you functions and recursive functions.

And it says you don't need this, just for program readability and stuff and actually wastes performance using functions. I found that interesting, how hard recursive functions seem to be at this time and how much it's pushing you to learn, when you could just write a loop and solve it easier.

It also taught you a bunch of storage classes that pretty much said were useless because today's compilers automatically use the best class.

Are any of you guys seeing recursive functions very useful as compared to just writing the loops?
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
recursive functions are the more intuitive solutions for many problems eg transversing directories

and some types of recursive functions can't be solved with loops easily (some sort algorithms etc)
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
They may not be the fastest/most efficient, but there's just something really sexy and satisfying about an elegant recursive solution to a problem :p


(Ok, so I don't get out enough :D )
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Armitage
They may not be the fastest/most efficient, but there's just something really sexy and satisfying about an elegant recursive solution to a problem :p


(Ok, so I don't get out enough :D )

lol, I have to disagree about the function thing. Do you know how hard it would be to read a 2000 line program without classes or functions? Think about it.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
C doesn't have classes. What are you guys talking about?

And recursion has its place, like most things. And also, like most things, it's not the best solution for every problem. Just another tool in the toolbox.

lol, I have to disagree about the function thing. Do you know how hard it would be to read a 2000 line program without classes or functions? Think about it.

Who said anything about functions being useless?
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: BingBongWongFooey
C doesn't have classes. What are you guys talking about?

And recursion has its place, like most things. And also, like most things, it's not the best solution for every problem. Just another tool in the toolbox.

i think he's talking about sotrage classes like register, static, auto etc
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: dighn
Originally posted by: BingBongWongFooey
C doesn't have classes. What are you guys talking about?

And recursion has its place, like most things. And also, like most things, it's not the best solution for every problem. Just another tool in the toolbox.

i think he's talking about sotrage classes like register, static, auto etc

Aha. static is pretty useful IMO. I was actually just going through a patch for xterm and noticed that uses of register were being systematically removed. xterm is OLD. :p
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: BingBongWongFooey
C doesn't have classes. What are you guys talking about?

And recursion has its place, like most things. And also, like most things, it's not the best solution for every problem. Just another tool in the toolbox.

lol, I have to disagree about the function thing. Do you know how hard it would be to read a 2000 line program without classes or functions? Think about it.

Who said anything about functions being useless?

Chapter 5 teaches you functions and recursive functions.

And it says you don't need this, just for program readability and stuff and actually wastes performance using functions. I found that interesting, how hard recursive functions seem to be at this time and how much it's pushing you to learn, when you could just write a loop and solve it easier.

Seems like it was say it was useless.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: amdfanboy
Originally posted by: BingBongWongFooey
C doesn't have classes. What are you guys talking about?

And recursion has its place, like most things. And also, like most things, it's not the best solution for every problem. Just another tool in the toolbox.

lol, I have to disagree about the function thing. Do you know how hard it would be to read a 2000 line program without classes or functions? Think about it.

Who said anything about functions being useless?

Chapter 5 teaches you functions and recursive functions.

And it says you don't need this, just for program readability and stuff and actually wastes performance using functions. I found that interesting, how hard recursive functions seem to be at this time and how much it's pushing you to learn, when you could just write a loop and solve it easier.

Seems like it was say it was useless.

He said that the book said that functions just help readability, and then you said how hard it'd be to read a program without functions -- agreeing with him, while not realizing it.

Also, functions aren't entirely for readability. Try registering a signal handler (or any callback) that's not a function. ;)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
And it says you don't need this, just for program readability and stuff and actually wastes performance using functions.

I would say that in most cases readability is more important than the amount of performance you would lose.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Unless you are timing the speed of light over a 1 meter span, the so-called performance impact of moving something to a function is probably not even remotely noticeable.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: torpid
Unless you are timing the speed of light over a 1 meter span, the so-called performance impact of moving something to a function is probably not even remotely noticeable.


Well, it's a bit more then that depending on the situation. That's essentially why you have inline functions in C++, and I've had a few cases where turning off inlining had an appreciable performance impact.