Lies in education [was Re: The "loop and a half"]
bartc
bc at freeuk.com
Thu Oct 12 07:42:22 EDT 2017
On 12/10/2017 11:39, Stefan Ram wrote:
> bartc <bc at freeuk.com> writes:
>> (1) Define named constants; except (in C) they can't be used like
>> constant expressions, you can take their addresses, and accidentally or
>> maliciously change their values.
>
> When I think of »const«, I do not think of ROM.
>
> »const« makes code more readable, because it conveys the
> intentions of the author and simplifies the mental variable
> model of the reader.
>
> »const« helps to find inadvertend modifications.
>
> void f( const int i ){ if( i = 4 )putchar( 'x' ); }
That's two undesirable language features: (1) Having to use 'const' in
front of every simple parameter, so that 'const' now dominates every
program; (2) Mixing up '=' and '=='.
You're saying it's OK to use both as they sort of cancel each other out!
(Other languages solve the =/== problem by either not allowing
assignment within an expression, or by using a symbol for it that isn't
so easily mistaken for equality.)
--
bartc
More information about the Python-list
mailing list