G#: A Go-like language for .NET

theanonymousone3 pts0 comments

Introducing G#: A Go-like language for .NET | InfoWorld

Search

Menu

Topics

Close

Analytics<br>Artificial Intelligence<br>Careers<br>Cloud Computing<br>Data Management<br>Databases<br>Development Tools<br>Devops<br>Emerging Technology<br>Enterprise Buyer’s Guides<br>Generative AI<br>IT Leadership<br>Java<br>JavaScript<br>Microsoft .NET<br>Open Source<br>Programming Languages<br>Python<br>Security<br>Software Development<br>Technology Industry

by Simon Bisson

Contributing Writer

Introducing G#: A Go-like language for .NET

analysis

Aug 20, 20268 mins

Microsoft&rsquo;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&rsquo;s being developed on GitHub, with an impressively rapid release cycle.

Getting started with G#

Getting started with G# is easy. You&rsquo;ll need a supported version of .NET and the appropriate SDKs for your target operating systems. G# will produce code that&rsquo;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&rsquo;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&rsquo;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&rsquo;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&rsquo;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&rsquo;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&rsquo;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#&rsquo;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...

rsquo language code like development languages

Related Articles