food for thought - swift 5 released - bottom types, string interpolation, and stuff.

Dennis dkorpel at gmail.com
Fri Apr 12 11:38:58 UTC 2019


On Friday, 12 April 2019 at 11:03:21 UTC, Walter Bright wrote:
> Knowing what (x & 1) is is a superpower? What about (x + x) ?

Most new programmers have a math background and (x + x) is taught 
in middle school. CPU math can be very unintuitive however. You 
might not raise an eyebrow when I state `1/2 == 0` or `1.0 - 0.9 
- 0.1 != 0`, but it surprises newcomers.
(x & 1) assumes knowledge of bitwise operators and integer 
representations (it wouldn't work on negative integers in 1's 
complement).

This is part of a student's implementation of a hash function in 
Java, taken from an algorithms course I was teaching assistant 
for:
```
String bstring = Integer.toBinaryString(b);
if(bstring.length() > 31) {
   bstring = bstring.substring(bstring.length() - 31, 
bstring.length());
}
b = Integer.parseInt(bstring, 2);
```
The description of the last step was "H = (the last 31 bits of of 
b) mod s".
Many students did it like this. It's tempting to think they are 
just ignorant, but is it really reasonable to expect ANY 
programmer to be comfortable with bit-math?

> If you want isOdd() for your own personal library, feel free. 
> Putting it into Phobos, however, is not happening.

I can't speak for everyone, but I'm not vowing for anything like 
this in D. D is a system's programming language, and it can 
expect a certain of level of proficiency of its adopters.
I just feel like some responses here express the sentiment 'look 
what a dumb decision Swift developers just made', while I think 
that it can be very reasonable given the userbase of Swift.


More information about the Digitalmars-d mailing list