You are a stupid programmer, you can't have that

Steven Schveighoffer schveiguy at gmail.com
Mon Aug 9 16:27:28 UTC 2021


On 8/7/21 8:15 AM, IGotD- wrote:
> This is a general discussion which applies to all computer languages and 
> also under several decades. What I have observed is that language 
> designers see programmers misuse the language and introduce possible 
> bugs and therefore remove features in languages. An analogy would limit 
> the functionality of cars because people sometimes are involved in 
> accidents, like automatic speed limiter (soon to be law in several 
> countries).
> 
> Language designers seem to have a big brother attitude towards 
> programmers and think they will save the world by introducing limitations.
> 
> Examples.
> 
> 1.
> Array indexes should be signed instead of unsigned because somehow 
> programmers mess up loops among other things. Bjarne Stroustrup 
> considered his unsigned index to be a historic mistake. While unsigned 
> array indexes make perfectly sense, the bias towards signed seems to be 
> that programmers are stupid. The question is, if can't make a for loop 
> with unsigned math, shouldn't you look for another job?

If people who have made mistakes with unsigned math in loops were 
disqualified from programming, this place would be a ghost town.

Also note that signed indexes are allowed (you can also use negative 
indexes)! It's the array LENGTH being unsigned which is a problem. Note 
also due to D promotion rules, using any unsigned values poisons all 
your other values to be unsigned (usually unexpectedly).

> 2.
> Somewhat related. when Java was designed, the designer (James Gosling I 
> believe) claimed that programmers were too stupid to understand the 
> difference between signed and unsigned math (despite often several years 
> of university education) and removed signed math entirely from the 
> language. The impact is that when unsigned math is required, you are 
> forced to conversions and library solutions. Not ideal when an HW APIs 
> deals with unsigned numbers for example.

"too stupid" seems like an incorrect assessment. More like "too 
careless". Consider that it's not really unsigned math or signed math, 
but when you are doing math between signed and unsigned values, what 
should happen? That's where most people get into trouble. Note that 
signed math and unsigned math is identical, it's just most people aren't 
doing math around the value 2^31, but they do a lot around the value 0.

I would love for D to use signed indexes for arrays, especially with 
64-bit integers.


> The question is, do you think language designers go to far when trying 
> to "save" programmers from misuse or not?
> Do you think there can be approaches that both prevent bugs at the same 
> time do not limit the language?

Until the world of programming is ruled by perfect AI, please keep 
trying to fix my stupid human mistakes, thanks!

However, I do know of cases that have gone too far. Like Swift 
eliminating for loops -- that one stung.

-Steve


More information about the Digitalmars-d mailing list