Join Kit Eason for an in-depth discussion in this video Underscores in numeric literals, part of What's New in Visual Studio 2017 for F# For Developers.
- [Instructor] In this chapter of the course which is comparatively brief, we're going to have a look at some of the changes that have been made to make F# code in the environment a little more readable and friendly. Specifically we've got underscores in numeric literals which lets you make things a little more readable when you're dealing with long numbers and we've got error message improvements which has some really, really nice improvements to the way error messages are rendered by the compiler. So here we have some code where we're declaring some literals so we're binding some literal values. On line five we're making a count and it's quite hard to see it at glance whether that's ten million or a 100 million or one million but now in F# 4.1 you can put underscores in arbitrary places in these literals and they will not effect in any way the value that's generated but they do make it much easier on the eye and you can tell at a glance that's ten million so just to reiterate that point F# is not caring where you put those underscores.
They don't effect the value. It's not like commas where by convention you have them in certain places in a number. They're simply there to aid the reader's eye. Not just pure decimal numbers, here we have an x representation of a binary number, we've got some fs there and it's much more readable if you split it at the halfway point with an underscore. Here's a binary representation and there's no way of really spotting it off by one error in the way we've typed that but if we divide it up into so called nibbles, groups of four with underscores, you can see it at glance where for instance the little groups of solid ones are.
Just a tiny caveat. You can't have an underscore straight after, for instance, an x where you're specifying something is x. It has to be represented so that actually is an example of from one of the blog post announcements of this feature. It's incorrect. You can't have the underscore at the beginning. And that's it for underscores in numeric literals.
Kit Eason discusses the new value types that provide an opportunity for performance gains, the new result type which gives you access to the railway oriented programming style of error handling, and program organization and readability changes. Plus, he explores the evolution of tooling for F#, and explains how F# tooling has changed in Visual Studio 2017. To wrap up the course, he shares how you can contribute to the F# language and tooling by getting involved in the open-source community.
- Working with struct tuples
- Marking a record type as a struct value
- Marking a discriminated union as a struct type
- Using the fixed keyword to mark a value
- F# result type and associated functions
- Resolving potential naming clashes between modules and types
- Error message improvements
- The past and future of visual F# tooling in Visual Studio
- Reviewing F# tooling changes