News for hackers. Stuff that matters.
Re:Go 1.13 Release Notes by skunkworker on Tuesday September 03, 2019 @02:38PM (#20869680)
It brought one of my favorite parts about writing numbers in languages such as Ruby over to Go. From 10000000 to 10_000_000 is such a readability improvement and should be no-cost.
Re:Go 1.13 Release Notes by JNRowe on Tuesday September 03, 2019 @03:32PM (#20870262)
While I too like the change, there can be a user cost. For example, it makes using grep across a project slightly more annoying. Much like the flexible identifier rules in nim, it feels great but using common tools suddenly needs more thought.
Re:Go 1.13 Release Notes by Cthulhu_ on Wednesday September 04, 2019 @05:08AM (#20875320)
Would it make sense to have an editor display a number in a more readable fashion while the source code itself has the grep-able version? I'm not a fan of ligatures myself but that is also done purely as presentation logic.
Re:Go 1.13 Release Notes by cjensen on Wednesday September 04, 2019 @12:08AM (#20873915)
You guys are going to make me cry again that C++ rejected using underscores in favor of... single-quote.

O_o

Re:Go 1.13 Release Notes by patrec on Wednesday September 04, 2019 @05:14AM (#20875357)
Only someone with no typographic taste whatsoever would prefer 10_000 over 10'000, so personally I'll rather cry about only C++ getting this right.
Re:Go 1.13 Release Notes by rebolek on Wednesday September 04, 2019 @05:49AM (#20875529)
Not only C++. Rebol and Red also get this right. And they also allow comma instead of a dot as a decimal separator, oh the horror!
Re:Go 1.13 Release Notes by mseepgood on Tuesday September 03, 2019 @04:31PM (#20870856)
> From 10000000 to 10_000_000 is such a readability improvement and should be no-cost.

1e7

Re:Go 1.13 Release Notes by masklinn on Wednesday September 04, 2019 @02:08AM (#20874453)
> 1e7

Is a float literal.

Re:Go 1.13 Release Notes by majewsky on Wednesday September 04, 2019 @04:43AM (#20875208)
Not in Go. Number literals don't have a type until they're assigned to a variable or used in a place that implies a type (e.g. a function argument). For example, the following is valid:

  var u uint32 = 10000000000.0 / 100000
even though 10000000000 overflows uint32 and it's also written like a floating-point literal.
Re:Go 1.13 Release Notes by masklinn on Wednesday September 04, 2019 @05:18AM (#20875382)
> Not in Go.

Yes in go. `var u = 1e7` gives a float. That means 1e7 is a float literal. You can coerce it to an integer by explicitly typing the target, but it's still a float literal.

Re:Go 1.13 Release Notes by yencabulator on Thursday September 12, 2019 @02:11PM (#20954505)
`1e7` is an untyped numeric constant with a default type of float64.

https://blog.golang.org/constants

https://golang.org/ref/spec#Constants

Re:Go 1.13 Release Notes by lacampbell on Tuesday September 03, 2019 @07:34PM (#20872480)
Mysterious hacker news downvoting! This my preferred way of writing numbers with lots of 0s as well.
Re:Go 1.13 Release Notes by rbonvall on Tuesday September 03, 2019 @09:15PM (#20873083)
But underscores also work for numbers that don't have lot of zeros. Compare:

    12_345_678
    1.2345678e7
Re:Go 1.13 Release Notes by lacampbell on Tuesday September 03, 2019 @11:43PM (#20873816)
good point.

Kind of realising how much of my daily work could use bytes as the main numeric type

Re:Go 1.13 Release Notes by paulddraper on Tuesday September 03, 2019 @02:59PM (#20869914)
Underscores are nice.

10 * 1000 * 1000 worked pretty well too.

Re:Go 1.13 Release Notes by derefr on Tuesday September 03, 2019 @03:06PM (#20869982)
Compile-time integer exponentiation in Go would be neat, e.g. 5 * (1000**4).

I know we have scientific-notation integer literals, but it's not the same thing, especially when trying to calculate e.g. Mebibytes.

Re:Go 1.13 Release Notes by pkaye on Tuesday September 03, 2019 @03:18PM (#20870110)
In go you can use scientific notation for integers

   var x int = 1e9
Re:Go 1.13 Release Notes by Cthulhu_ on Wednesday September 04, 2019 @05:11AM (#20875335)
You say that, but I find that a lot harder to read (and using `e` notation) than just the number - and readability / clarity is more important than cleverness, especially in Go.

10_000_000 can be read, 5 * (1000**4) and 1e7 has to be decoded. By me anyway, I'm just an average developer that never did well in maths - and you have to write code for the average developer, not for yourself and not for the top 10% smartest people.

Re:Go 1.13 Release Notes by big_chungus on Tuesday September 03, 2019 @03:35PM (#20870289)
Not sure about go, but you can do this in C as a compile-time constant:

  #define foo 1.34E8
Maybe go would benefit from a pre-processor? Though it can be somewhat byzantine in C (and result in very unpredictable final source, if abused), it's very helpful to have a complete functional language available for code transformation. It might help go in some cases, too.