Microsoft’s open sourcing of .NET not only has sped up the development of the platform, but also has allowed new languages and features to be built on top of the .NET runtime and compilers. At the same time, the extensibility features of Visual Studio Code make it easy for developers to provide the tooling we need to use those new platform capabilities. One of the more interesting new projects to build on .NET is a Go-like language, G# , that targets both systems programming and mobile applications, with the intent of delivering small, secure, applications and libraries that can be used in other .NET applications. G# is a way to take the lessons learned in Go, Kotlin, and Swift and deliver code that works with .NET assemblies and libraries, taking advantage of NuGet and other similar repository services to build on top of the mature .NET platform. It’s being developed on GitHub , with an impressively rapid release cycle. Getting started with G# Getting started with G# is easy . You’ll need a supported version of .NET and the appropriate SDKs for your target operating systems. G# will produce code that’s compatible with .NET 8 through .NET 10, though .NET 10 is preferred. The G# SDK and templates are available from NuGet, which ensures that you can install and run G# from the .NET CLI. The quickest way to get started is to install the G# templates and then use these to create a console application that you can then open in your choice of development tool and start extending. The structure of a basic application is quite simple, with a project file, the program .gs file, and a NuGet configuration to manage packages and libraries, with support for local SDKs (useful if you’re building G# from source). Building and running the default console template is quick, delivering output in a little over four seconds on an Arm-based Windows PC, which bodes well for building and debugging larger applications. The installed templates give you options for several different classes of application and library beyond the basic console implementation. Additionally, there’s a Visual Studio Code extension for G# that can be downloaded from the Visual Studio Marketplace, which should speed up development as it includes the appropriate language server bits. The documentation includes a command-line option for installing the extension, which avoids having to search for the necessary files and gets you ready to start coding with G# next time you open VS Code. Alternatively, you can use the G# language’s own gsc compiler directly, rather than it being called by MSBuild from the .NET CLI. This approach is useful when you want to output code that targets a specific .NET version or compiles as an assembly for use with other .NET languages. This approach avoids using interpreted code and lets you go straight to delivering pre-compiled binaries. Inside the G# language The G# language itself is straightforward . Code is structured in packages, with executable sections defined as funcs . By default, G# uses the .NET System namespace, so you can use familiar constructs without having to learn different ways to do the usual things. If you don’t want to bring in System by default, you can disable imports as part of the compiler configuration. Each function can take parameters and return values, with types declared as part of the parameter list. The parameter list can end with type declarations for any returns, so you can ensure that you’re returning the expected data. Most types include lengths, for example int64 , though there are aliases for familiar types as used in other languages. Strings allow you to add alignments and formatting information. In addition to functions, you can define structs and classes to help handle variables, with structs handling values and classes handling references. Similarly, data structs and classes let you treat variables as data, applying copies and assigning values. Much of the language structure will be familiar, especially if you’re used to working with languages like Go . There are some interesting shortcuts, using features like if let to check for nulls when parsing function parameters. You can use if let alongside G#’s exception handling to manage more complex program flows. Other features include using for in to iterate through collections, allowing you to deliver and use arbitrary length arrays with a function, without having to determine lengths before running operations. Using G# in distributed systems G# is designed to support asynchronous programming , which is essential for working with distributed applications. It uses the familiar async and await constructs, though here it’s an async func . Interestingly, there’s the option to wrap a set of asynchronous operations in a scope, which allows you to run a series of operations and manage failures, keeping the results of successful operations for use elsewhere in your application. This lets you tie together parent and child operations so that the parent always returns after the child. You can use an async sequence to work with streams, but if you prefer, there’s also support for Go-like channels if you use the Go extensions package. This last option provides alternative asynchronous operations, including fire-and-forget go calls, which allow you to trigger external functions concurrently without needing to wait for a response. Your main function will carry on operating, without needing a success or failure. There’s an interesting option here of mixing and matching .NET style asynchronous programming with Go’s fire-and-forget concurrency, as well as its built-in publish-and-subscribe channels. Bringing together .NET and Go The more you drill down into the language structure of G#, the more you can see it as a hybrid of the .NET approach (which comes from it being part of the family of Pascal and similar languages) and Go (with its structured C language heritage). That makes G# a very flexible tool, and one that could work very well with .NET-based Kubernetes applications. Another key feature is the ability to interoperate with the rest of the .NET ecosystem, importing namespaces and using methods in functions. Imported packages can be given aliases to simplify calls, with G# supporting .NET types and collections alongside its own constructs. There’s even support for events and delegates, as well as for working with unmanaged code via DLL and library imports. Usefully, the project documentation includes tables comparing G# with Go and C#, helping you transition between different ways of working by showing direct comparisons with familiar features. If you’re currently working in .NET, it’s worth keeping the C# comparison open while you’re writing your first G# applications. What G# is good for One interesting option for G# is as an educational language. It’s small and predictable, which makes it suitable for the classroom, simplifying both teaching and marking assignments. You can then use G# as an on-ramp into the wider .NET ecosystem, or to move from mobile development with Swift or Kotlin to C# and other .NET languages, using the two together as you develop more enterprise development skills. Having a smaller surface than other .NET languages makes G# an interesting candidate for working with WebAssembly and with microVMs in Hyperlight . By writing code that works in a more constrained environment than C# but still compiles to .NET running on WebAssembly , there’s the prospect of using G# to deliver fast modules for use in Kubernetes and other distributed programming environments, where fast-loading serverless components provide the response times needed by both applications and users. For now, don’t expect to see G# supporting all the language constructs used by C# or VB.NET. It’s still very early days for what is intended to be a smaller language, and not all the intended features are available. That shouldn’t stop you trying it out, especially if you’re coming from an iOS or Android development background and you want to bring your code to Windows and Azure. The similarities of G# to this class of programming language should make it easier both to embrace the new platform and to port your existing code.


