www.pantsfactory.org/?action=comments&linkid=1260
Okay, Ive seen it done a lot, but hes gonna have trouble when he starts doing languages much more insistent on using the entry functions canonical signature. My main gripe with that part, tho, is that if hes gonna depart from standard in making main TAKE void, why not make it RETURN void too? Sure, void is one more char than int, but hed get to drop the whole return 0;
Re: Thu, Mar 25, 2004 08:09 PM GMT viega The lack of newline doesnt concern me. The result should be illegible, just like all the other scrawl Ive been forced to do for a teacher. The mainvoid thing is actually a very good thing to do, but NOT in that context. The explicit denotation of void for the parameter list denotes that the function never takes any arguments. This is in stark contrast to , which is often used that way, but in C actually means that the arguments could be anything one would have to use va macros or something like it to read the arguments.
Sat, Mar 27, 2004 07:01 PM GMT dave Sure, Ill go learn the main idioms of a language, like when Matt tasked me to write some stuff in Python, which I had read about before but never actually seen. What you seem to condone, though, is assuming that the future maintainers will learn the idioms, and be skilled and alert and so on. I dont think this is a good assumption to make, when the cost of doing otherwise is merely a few extra characters at least, now that disk space is so cheap. As for recursion, that would still require a way to compare the number of times it has recursed, to the number desired. Sure it could check the stack or something contorted like that, but a variable is still at least the obvious way, unless maybe you dont consider an argument a variable. Even so, why be so worried about one variable, if youre going to create a whole stack frame for each recursion level?
Sat, Mar 27, 2004 07:20 PM GMT viega Dave, recursion in that context isnt an efficiency issue, its a style issue. Tail recursion can be compiled just as efficiently as iteration, but thats beside the point. My whole point is that programming style is not even close to a science. Look at the massive flame wars over whether Pythons indentation is a good thing or a bad thing. Theres no right answer, as much as some of us prefer the Python way which, by the way, doesnt involve braces.
Sat, Mar 27, 2004 11:49 PM GMT dave Execution efficiency wasnt the reason I was objecting to using recursion for this. Using recursion where iteration is more natural, or vice-versa, generally leads to code that is less clear. Yes, there are times when iteration may be more natural in one language, while recursion is more natural in another, for the same task. I dont care about the extra milliseconds a CPU may spend on the problem unless of course it will be executed a gazillion times. What concerns me more is the extra time a programmer has to spend figuring out WTF a piece of code does, and how, so he can make some fix or other change. Unclear code can multiply severalfold the time it takes to grok code in fullness. Ive been that poor sod too many times not to be concerned about that. Off the top of my head no Im not gonna bother trying them, compare: void WriteStringNTimesRecursive char str, int times if times > 0 printf sn, str;
Sure theres probably a counter internally, but its not a variable the programmer has to bother with. As for idioms, yes, learning them including whether recursion is generally favored over iteration is part of the job, but frankly idioms is a minor consideration. The main danger is just plain old making of mistakes, whether due to being unaware of idioms, mistakenly assuming there was an opening brace before an indented line, everyday stupidity, etc. Surely youve seen your share of incompetent programmers, who still somehow manage to get hired to work on complicated stuff.
Sun, Mar 28, 2004 07:31 AM GMT viega Uhhh, I find them both perfectly clear. Certainly dont hire such people in any company Im ever involved with. Anyway, I certainly agree that there are cases where iteration is far more natural for most C programmers. And, there are cases where one of the two is so clearly a more appropriate construct that the other ends up being far less clear. And, much of the time, either construct is clear enough that its more a personal preference.
|