Why Go? – Key advantages you may have overlooked

yourbasic.org/golang

Go makes it easier (than Java or Python) to write correct, clear and efficient code.

Choosing a programming language isn’t easy. The separate features of a language may look great at first, but it takes time and experience to spot the drawbacks.

As a CS professor and longtime Go and Java developer, I’d like to share some of my thoughts and explain why I prefer Go to Java or Python – Go makes it much easier for me to write good code.

Go has been my main programming tool since 2012, replacing Java, which in turn replaced C in 1998. I use Python mostly for teaching. My journey as a pro­gram­mer started back in 1978 on a TI-57 with 50 program steps and 8 registers.

Minimalism

Go is a minimalist language, and that’s (mostly) a blessing.

The formal Go language specification is only 50 pages, has plenty of examples, and is fairly easy to read. A skilled programmer could probably learn Go from the specification alone.

The core language consists of a few simpleorthogonal features that can be combined in a relatively small number of ways. This makes it easier to learn the language, and to read and write programs.

When you add new features to a language, the complexity doesn’t just add up, it often multiplies: language features can interact in many ways. This is a significant problem – language complexity affects all developers (not just the ones writing the spec and implementing the compiler).

Here are some core Go features:

See Go vs. Java: 15 main differences for a small code example, and a sample of basic data types, methods and control structures.

Features for the future

Go omits several features found in other modern languages.

Here’s the language designers’ answer to Why does Go not have feature X?

Every language contains novel features and omits someone’s favorite feature. Go was designed with an eye on felicity of programming, speed of compilation, orthogonality of concepts, and the need to support features such as concurrency and garbage collection. Your favorite feature may be missing because it doesn’t fit, because it affects compilation speed or clarity of design, or because it would make the fundamental system model too difficult.

New features are considered only if there is a pressing need demon­strated by experience reports from real-world projects.

There are a few likely major additions in the pipeline:

Currently, some minor additions are considered to help create and test a community-driven process for developing Go.

However, features such as optional parameters, default parameter values and method overloading probably won’t be part of a future Go 2.

Java comparison

The Java® Language Specification is currently 750 pages. Much of the complexity is due to feature creep. Here are but three examples.

Java inner classes suddenly appeared in 1997; it took more than a year to update the specification, and it became almost twice as big as a result. That’s a high price to pay for a non-essential feature.

Generics in Java, implemented by type erasure, make some code cleaner and allow for additional runtime checks, but quickly become complex when you move beyond basic examples: generic arrays aren’t supported and type wildcards with upper and lower bounds are quite complicated. The string “generic” appears 280 times in the specification. It’s not clear to me if this feature is worth its cost.

A Java enum, introduced in 2004, is a special type of class that represents a group of constants. It’s certainly nice to have, but offers little that couldn’t be done with ordinary classes. The string “enum” appears 241 times in the specification.

Code transparency

Glen Beck and Betty Snyder programming the ENIAC

Your project is doomed if you can’t understand your code.

  • You always need to know exactly what your coding is doing,
  • and sometimes need to estimate the resources (time and memory) it uses.

Go tries to meet both of these goals.

The syntax is designed to be transparent and there is one standard code format, automatically generated by the fmt tool.

Another example is that Go programs with unused package imports do not compile. This improves code clarity and long-term performance.

I suspect that the Go designers made some things difficult on purpose. You need to jump through hoops to catch a panic (exception) and you are forced to sprinkle your code with the word “unsafe” to step around type safety.

Python comparison

The Python code snippet del a[i] deletes the element at index i from a list a. This code certainly is quite readable, but not so transparent: it’s easy to miss that the time complexity is O(n), where n is the number of elements in the list.

Go doesn’t have a similar utility function. This is definitely less convenient, but also more transparent. Your code needs to explicitly state if it copies a section of the list. See 2 ways to delete an element from a slice for a Go code example.

Java comparison

Code transparency is not just a syntactic issue. Here are two examples where the rules for Go package initialization and program execution order make it easier to reason about and maintain a project.

  • Circular dependencies can cause many unwanted effects. As opposed to Java, a Go program with initialization cycles will not compile.

  • When the main function of a Go program returns, the program exits. A Java programs exits when all user non-daemon threads finish.

This means that you may need to study large parts of a Java program to understand some of its behavior. This may even be impossible if you use third-party libraries.

Compatibility

A language that changes abruptly, or becomes unavailable, can end your project.

Go 1 has succinct and strict compatibility guarantees for the core language and standard packages – Go programs that work today should continue to work with future releases of Go 1. Backward compatibility has been excellent so far.

Go is an open source project and comes with a BSD-style license that permits commercial use, modification, distribution, and private use. Copyright belongs to The Go Authors, those of us who contributed to the project. There is also a patent grant by Google.

Python comparison

If you’re a Python developer, you know the pain of having to deal with the differ­ences between Python 2.7.x and Python 3.x. There are strong reasons for choosing Python 3, but if you depend on libraries that are only available for an older version, you may not be able.

Java comparison

Java has a very good history of backward compatibility and the Compatibility Guide for JDK 8 is extensive. Also, Java has been freely available to developers for a long time.

Unfortunately, there are some dark clouds on the horizon with the Oracle America, Inc. v. Google, Inc. legal case about the nature of computer code and copyright law, and Oracle’s new Java licensing model.

Performance

The exterior of Go is far from flashy, but there is a fine-tuned engine underneath.

It makes little sense to discuss performance issues out of context. Running time and memory use is heavily influenced by factors such as algorithms, data structures, input, coding skill, operating systems, and hardware.

Still, languageruntime and standard libraries can have a large effect on perfor­mance. This discussion is limited to high-level issues and design decisions. See the Go FAQ for a more detailed look at the implementation and its performance.

First, Go is a compiled language. An executable Go program typically consists of a single standalone binary, with no separate dynamic libraries or virtual machines, which can be directly deployed.

Size and speed of generated code will vary depending on target architecture. Go code generation is fairly mature and the major OSes (Linux, macOS, Windows) and architectures (Intel x86/x86-64, ARM64, WebAssembly, ARM), as well as many others, are supported. You can expect performance to be on a similar level to that of C++ or Java. Compared to interpreted Python code, the improvement can be huge.

Go is garbage collected, protecting against memory leaks. The collection has very low latency. In fact, you may never notice that the GC thread is there.

The standard libraries are typically of high quality, with optimized code using efficient algorithms. As an example, regular expressions are very efficient in Go with running time linear in the size of the input. Unfortunately, this is not true for Java and Python.

Build speeds, in absolute terms, are currently fairly good. More importantly, Go is designed to make compilation and dependency analysis easy, making it possible to create programming tools that scales well with growing projects.

Why Go? – Key advantages you may have overlooked的更多相关文章

  1. What are the advantages of different classification algorithms?

    What are the advantages of different classification algorithms? For instance, if we have large train ...

  2. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  3. (转) Graph-powered Machine Learning at Google

        Graph-powered Machine Learning at Google     Thursday, October 06, 2016 Posted by Sujith Ravi, S ...

  4. 高效的两段式循环缓冲区──BipBuffer

    Simon Cooke,美国 (原作者) 北京理工大学 20981 陈罡(翻译) 写在前面的话: 循环缓冲区是一个非常常用的数据存储结构,已经被广泛地用于连续.流数据的存储和通信应用中.对于循环缓冲区 ...

  5. The Bip Buffer - The Circular Buffer with a Twist

    Introduction The Bip-Buffer is like a circular buffer, but slightly different. Instead of keeping on ...

  6. Mysql基本架构及查询流程

    mysql体系结构简单概述: Connectors:接入方,支持协议很多 Management Serveices & Utilities:系统管理和控制工具例如:备份恢复,mysql复制集群 ...

  7. [转]OpenVPN官网的HOWTO

    因为墙的原因,打不开.特此转一下: HOWTO Introduction OpenVPN is a full-featured SSL VPN which implements OSI layer 2 ...

  8. [AWS] Deploy react project on EC2

    如何在aws部署项目 申请到亚马逊AWS免费账户后,我们可以拥有很多的免费云服务产品项目,其中包括: EC2云服务器. Amazon S3存储. Amazon RDS数据库. Amazon Cloud ...

  9. a no-risk path to IEEE P1687

    You’ve heard all about IJTAG (IEEE P1687) [1,2,3], a new standard for accessing embedded test and 
d ...

随机推荐

  1. VS2010 如何在调试的时候输入参数

    VS2010 如何在调试的时候输入参数 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 很明显,好多算法程序实现的时候提供的例程都是需要在命令行中输入参数,比 ...

  2. with as用法 --Python

    有些任务,可能事先设置,时候做清理工作,如下面一段程序: f = open('tmp.txt') data = f.read() print(data) 是不是忘了什么?没错,很明显忘记关闭文件句柄. ...

  3. 记一次Spring Cloud压力测试

    前言 公司打算举办一场活动,现场参与活动人数比较多.针对于可能访问比较密集的接口进行压力测试.使用jmeter进行测试,请求并发稍微多些,系统就会挂起. 针对压力测试出现的问题,因为并发超过1秒钟10 ...

  4. 解决RabbitMQ消息丢失问题和保证消息可靠性(一)

    原文链接(作者一个人):https://juejin.im/post/5d468591f265da03b810427e 工作中经常用到消息中间件来解决系统间的解耦问题或者高并发消峰问题,但是消息的可靠 ...

  5. asp.net core-14.JWT认证授权 生成 JWT Token

    源码下载 语言组织能力不好 ,看这个 视频 用visual studio code打开文件,运行dotnet watch run 之后在postman里面去访问 拿到Token后

  6. 怎样用sql语句复制表table1到表table2的同时复制主键

    原文:怎样用sql语句复制表table1到表table2的同时复制主键 在从table1表复制到table2的时候,我们会用语句: select * into table2 from table1 但 ...

  7. linux 用户切换组

    问题: 因为默认的的网站路径 /var/www/html 是root 用户 root组的, 想要修改什么的需要用sudo 很麻烦. 解决: 将当前用户 hehecat加入至root组,使之有权限对目录 ...

  8. zblog2.X 连不上数据库原因

    数据库配置Dim ZC_MSSQL_DATABASEZC_MSSQL_DATABASE="zb20" Dim ZC_MSSQL_USERNAMEZC_MSSQL_USERNAME= ...

  9. springboot启动流程(八)ioc容器refresh过程(下篇)

    所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 正文 上一篇文章,我们知道了解析过程将从解析main方法所在的主类开始.在文章的最后我们稍微看 ...

  10. C++ sizeof(struct) 的注意

    今天在测试将C++代码导出的NavMesh二进制文件用一套C#改写的代码导入时,发现导入的数据出现不一致的问题. 分别在C++和C#AddTile的函数内设置断点,观察最后得到的tile有大部分的字段 ...