On 11/4/22 09:47, Scott Lurndal wrote:
> Juha Nieminen <nos...@thanks.invalid> writes:
..
>> I'm 99% certain that the main (if not even only) reason why you don't
>> like
>> static_cast is because it's longer. That's it. No other reason.
>
> Actually, I don't like it because it doesn't add anything useful over
> a plain c-style cast.
It's advantage over the plain c-style cast lies in what it won't do: it
won't do any of the things for which const_cast<> or reinterpret_cast<>
are needed instead. It also won't do what dynamic_cast<> does, but
that's also true of the c-style cast.
Particularly in a language that allows overloading and template type
parameters, the consequences of a c-style cast can be hard to
anticipate. The named casts help ensure that only the desired type of
change can occur without triggering a mandatory diagnostic.
>> I have noticed a very common psychological phenomenon that for some
>> reason beginner programmers try to write code that's as short as
>> possible,
>> even when that comes at the cost of legibility (a phenomenon that I have
>> named "the brevity-over-clarity style of programming"). Way too many
>> programmers never learn out of this bad habit.
>
> Some of us learned by punching programs on cards and on 110 baud
> teletypes on computers
> with 4k words of memory. Brevity was to be celebrated.
In 1974 my high school provided computer programming classes, when
almost no one else did, because an alumnus donated a long-obsolete IBM
1620 with a Fortran I compiler, using punched cards and a teletype. It
being a decimal machine, I seem to recall it had 10000 decimal digits of
memory.
While I learned touch typing at an early age, I was always prone to
errors. On punched cards, that meant a lot of wasted cards. Cards that
were correctly punched were a precious resource for me. I took to using
some really bad policies when writing my programs. I used very short
generic variable names, allowing me to re-use them for very different
purposes in different programs. If I typed a variable name incorrectly
on my first try, that incorrect spelling became the new correct spelling
for the variable. I gave statements widely spaced statement numbers,
allowing me to insert new statements between them.
I dropped all of these absurd policies like hot potatoes the instant I
started working on a computer which allowed me to save and edit programs.