[Python-ideas] real numbers with SI scale factors
João Santos
jmcs at jsantos.eu
Tue Aug 30 09:56:42 EDT 2016
On Tue, 30 Aug 2016 at 12:48 Sven R. Kunze <srkunze at mail.de> wrote:
> On 30.08.2016 04:34, David Mertz wrote:
>
> On Mon, Aug 29, 2016 at 1:55 PM, Sven R. Kunze <srkunze at mail.de> wrote:
>
>> There was no reasonable real-world code examples taken from important
>> projects, that would be significantly improved by underscores in numbers.
>>
>
> I recall dozens of real world examples that came up during the discussion,
> and have written very numerous such examples in code of my own. This is
> something that directly affects readability in code I write almost every
> day, and is a clear and obvious win.
>
> I taught examples *today* where I would have badly liked to have
> underscore separators, and it was obvious to me and students that
> awkwardness. Writing, e.g. `range(int(1e7))` feel contrives (but usually
> the way I do it). Writing `range(10000000)` is nearly impossible to parse
> visually. In contrast, writing `range(10_000_000)` will be immediately
> clear and obvious.
>
> None of those things can be said of SI units as Python literals.
>
>
> Hu? None of those things? I do think you exaggerate quite a lot here.
>
> If your real-world example works for underscores, it works for SI units
> and scales as well.
>
>
There is obvious way now:
G = Ghz = 1000
frequency = 1 * Ghz
You can even have a non naive version Ghz that supports conversions and
unit checking when doing arithmetic with it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160830/45a8e79a/attachment.html>
More information about the Python-ideas
mailing list