Re: Is this acceptable (i.e., compliant) code?

From: William L. Bahn (william_at_toomuchspam.net)
Date: 08/10/04


Date: Mon, 9 Aug 2004 23:33:52 -0600


"Mark F. Haigh" <mfhaigh@sbcglobal.net> wrote in message
news:f819a2fe.0408091425.7be1188c@posting.google.com...
> "William L. Bahn" <william@toomuchspam.net> wrote in message
news:<10heha3ab00pb84@corp.supernews.com>...
> > "Mark F. Haigh" <mfhaigh@sbcglobal.ten> wrote in message
> > news:vxDRc.1964$QJ3.1398@newssvr21.news.prodigy.com...
> > > William L. Bahn wrote:
> > > <snip>
> > >
> > > Although the code looks ok, I think the style can be
brushed up a bit.
> > >
> > > Suggestions:
> > >
> > > 1. printbits may be able to be static. Move it up in the
file so the
> > > definition serves as the prototype.
> >
> > I require my students (first year engineering students, not
computer science
> > majors)
> > to have main() be the first function in the file - primarily
so that the
> > grader can find
> > it quickly and efficiently. I also only have them place those
prototypes
> > above main()
> > that are for functions called by main(). The rest of the
function protorypes
> > go after
> > main() just before the function definitions themselves.
>
> So you're trying to teach first year, non-CS students C? I can
only
> hope, both for you and these kids, that you require some kind
of prior
> programming experience as a prerequsite.

Unfortunately no - most of them have basically none although it
varies quite a bit. The most frustrating part is the lack of
mathematical preparedness that even the brightest among them
have. Last semester I was working with my two sharpest students
after class talking about the properties of modulo arithmetic and
some other things such as logarithms to an arbitrary base and
both of them (from different high schools) remarked that they had
never actually seen the log function used to solve a problem -
that they had merely been taught that when you see it in an
equation you punch this button on your calculator. The calculator
generation.

I now spend the first two weeks covering what a positional
numbering system is and how to do basic math using one. The
pre-req for the course is Calc I, but very few of them have any
understanding of how to work with exponents or the relationship
between a logarithm and an exponent or even how do perform long
division. One of the first example problems I work in class when
we get to functions is writing a function that computes x^y
without using the pow() function. It gives me the opportunity to
link the problem statement to the basic logarithmic relationship,
solve it for the quantity of interest, and then write a simple
function to spit back the result. I warn them that a problem like
this is probably going to be on the exam. Come the exam, almost
no one gets it right and the most common attempt is to write a
for loop multiplying x by itself y times - even though in class I
stressed how repeated multiplication doesn't work for exponents
that are not positive integers and gave examples and on the test
the problem stressed that x was a positive floating point value
and y was any floating point value. The most frustrating part is
that, after getting dinged on one exam, walking though the exam
in detail when it is handed back, and warning them that problems
that people struggled with are likely to appear on the next exam,
the same thing happens.

Heck, I have a hard time getting them to understand the
difference between "the first positive number greater than a
hundred" and "the first positive number that has greater than a
hundred digits".

> As with other people here, I do not agree with your constraints
on the
> location of the main function. I'm sure the graders can be
trained to
> use the search feature of their favorite editor.

A couple of the other responders provided tangible benefits for
locating main() last, in particular to make any recursive
relationships readily apparent. That's a demonstrable benefit I
can accept and express and impose, so I'm changing the style
standards accordingly.

The same with the return statement. As long as it was merely what
someone terms "ugly" I have a hard time changing my standards
since I saw a benefit. Any of these students that ever write much
code are likely to be doing it at the level that I do - namely
small programs to perform specific tasks as a minor part of
completely unrelated duties. I design full custom integrated
circuits - and occasionally I write a C program to perform some
utility or task to support that. So rules that get them to make
fewer mistakes when working at that level have merit.

But getting a different compiler message if you mistype the
return statement (I'm particularly prone to putting in 'retrun'
statements) is something worthwhile to look at and I can also see
the merit in emphasizing that return is not a function - but then
why should it be different than if(), while(), for(), and others
that are not functions but yet require the associated expression
to be in parentheses? Why should the return statement be
different? Just because the standard will let you get away
without the parens I don't see as being a good justification for
not including them.



Relevant Pages

  • Re: GCSE - over two decades of decline into crap
    ... And we still have the turnips like Walker spouting that standards are ... Either the people taking the exam are getting more intelligent each ... i 100% as confirmed by a ballot of the earnest and diligent members of the ...
    (uk.politics.misc)
  • Re: GCSE - over two decades of decline into crap
    ... And we still have the turnips like Walker spouting that standards are ... Either the people taking the exam are getting more intelligent each ...
    (uk.politics.misc)
  • Re: GCSE - over two decades of decline into crap
    ... And we still have the turnips like Walker spouting that standards are ... Either the people taking the exam are getting more intelligent each ... i 100% as confirmed by a ballot of the earnest and diligent members of ... Kids are less able to differentiate themselves, ...
    (uk.politics.misc)
  • Re: RAE (or whatevertisnowcalled)
    ... I would defend the need for a central moderation of marks, ... defined percentage of candidates through. ... standards of the candidates. ... the CW requirement to be dropped before taking the exam. ...
    (uk.radio.amateur)
  • Going through hell to pass 70-292
    ... I am having a really hard time to pass the exam 70-292. ... I am using the Self-Paced Training Kit and have ... the exam is managing audit events. ...
    (microsoft.public.cert.exam.mcse)