www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bring back foreach int indexes

reply harakim <harakim gmail.com> writes:
https://forum.dlang.org/post/ssqeqbnesbiostjrnxrf forum.dlang.org

On Wednesday, 29 November 2023 at 14:56:50 UTC, Steven 
Schveighoffer wrote:
 I don’t know how many times I get caught with size_t indexes 
 but I want them to be int or uint. It’s especially painful in 
 my class that I’m teaching where I don’t want to yet explain 
 why int doesn’t work there and have to introduce casting or use 
 to!int. All for the possibility that I have an array larger 
 than 2 billion elements.
 -Steve
If I can only have one or the other, I would choose to enforce the cast. However, that is really annoying and not intuitive for newcomers. The strictness is one of the things I really value in D but I have also really hated along the way. I remember trying to figure out how to cast a mutable variable to immutable for the first time. I know it's immutable, just let me cast it! I appreciate it now. Even once I fixed it, I didn't know why. Anyway, I would be interested to see a list of the issues your students run into and if there is enough there that D could add a --simple or --beginner flag or something that allows you to hang yourself on the common beginner issues by just emitting a warning.
Mar 25
parent deadalnix <deadalnix gmail.com> writes:
On Tuesday, 26 March 2024 at 04:17:17 UTC, harakim wrote:
 https://forum.dlang.org/post/ssqeqbnesbiostjrnxrf forum.dlang.org

 On Wednesday, 29 November 2023 at 14:56:50 UTC, Steven 
 Schveighoffer wrote:
 I don’t know how many times I get caught with size_t indexes 
 but I want them to be int or uint. It’s especially painful in 
 my class that I’m teaching where I don’t want to yet explain 
 why int doesn’t work there and have to introduce casting or 
 use to!int. All for the possibility that I have an array 
 larger than 2 billion elements.
 -Steve
Could we just insert a runtime check that the array isn't more than 2G elements in case an int is used as key?
Mar 26