microsoft / pxt

Microsoft MakeCode (PXT - Programming eXperience Toolkit)
https://makecode.com
MIT License
2.09k stars 581 forks source link

It should be an error to leave out |0 when number is a 32-bit integer as in Microbit #3681

Closed mobluse closed 6 years ago

mobluse commented 6 years ago

I guess it's necessary that numbers in MakeCode on Microbit are integers, but that division is integer leads to nonportable JavaScript/TypeScript. Maybe you could have |0 as in asm.js in saved JavaScript to make it portable (asmjs).

I tested floats in the Adafruit simulator: 10/3=3.33. I'm not against fast integers as in Microbit 10/3=3, but think they should write them in JavaScript/TypeScript e.g. n/m|0 so that code is easier to port. It should be an error to leave out |0 when number is a 32-bit integer.

mmoskal commented 6 years ago

Thank you for the idea!

In fact you would have to add |0 to + and - as well (they can overflow), and also use Math.imul instead of * (as x*y|0 is different than Math.imul(x, y)). I don't feel we really want to push this on kids, who are just learning what a while loop is.

Also, enforcing such a discipline would be a breaking change. If we go for a breaking change, I would much rather add floats to micro:bit. I don't think they would take much more space, as we usually just use 31 bit integers.

@tballmsft @abchatra comments?

abchatra commented 6 years ago

I agree with you. There is a balance between what students can grasp and portability to javascript. Asm.js syntax is hard to understand for middle school students. Support for floats gels better with javascript.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.