The More I Write Go - Episode IV

The More I Write Go - Episode IV

Go has become a very popular language in recent years. The fact that it came from Google it a big boost. The fact that you can deploy rather small, statically linked binaries, without a large runtime distributable makes it especially attractive for Docker containers and Kubernetes deployments in the cloud.

The Go language was influenced by different languages, but C is cited as the primary influencer, and yet some of the differences from C-style languages, like C, C++, C#, Java, JavaScript, do not make sense to me. Further, rather than make the syntax more lenient and user friendly, it was made more rigid and the compiler complains over every little thing.

In this first episode we will take a look at the Unary Increment and Decrement operators, ++ and --, respectively. In other C-style languages, the unary increment and decrement operators can be either statements or expressions. Further, they come in two flavors, postfix (e.g. i++), and prefix (e.g. ++i).

In Go, the Unary Increment and Decrement operators, or IncDec, as they are referred to in the Go Language Specification [1], are only available in postfix format, but that really isn't the issue as it wouldn't have made a difference if a prefix format was allowed: in Go these operators are not allowed as expressions. That means that you can only use it like so:

i++

That's it!

So the following C-style construct

arr[i++] = v

Would become

arr[i] = v
i++

And of course

arr[++i] = v

Becomes

i++
arr[i] = v

Would it kill me to add another line? Probably not. Does it feel more modern and user friendly? Absolutely not! That language "feature" is so useless that someone actually proposed to remove it in a future version [2].

And while I'm off ranting here... Hey LinkedIn! Would it kill you to add some basic code formatting to articles? It's 2018 (and even that statement would be outdated in a couple of more weeks)!

[1] https://golang.org/ref/spec#IncDec_statements

[2] https://github.com/golang/go/issues/21263


要查看或添加评论,请登录

Igal S.的更多文章

  • Fraud on LinkedIn! Beware!

    Fraud on LinkedIn! Beware!

    I've been meaning to post this article for some time now. For some reason I am being targeted by scammers, or maybe…

    73 条评论
  • Farewell Windows (it's not you, it's me)

    Farewell Windows (it's not you, it's me)

    Farewell Windows, it's been a great ride but I've outgrown this relationship and it's time for me to move on. People…

    71 条评论
  • Getting Started with Lucee in Docker

    Getting Started with Lucee in Docker

    In this video I show how to get started with Lucee in Docker: I am using the project that I recently published at…

    2 条评论
  • Cockpit - Linux Web Console

    Cockpit - Linux Web Console

    So I installed CentOS 8 in VirtualBox today. Why, are you asking? Because that's what I "do for fun".

    14 条评论
  • I ?? Lucee

    I ?? Lucee

    Last month I gave a talk titled "I Love Lucee" at the Tomcat track of ApacheCon (link to video below though the preview…

    22 条评论
  • Easily Run Postgres in Docker

    Easily Run Postgres in Docker

    I made a video tutorial with an introduction to running Postgres in Docker. There are plenty of tutorials with lots of…

    12 条评论
  • Gotta love Postgres Procedural Languages

    Gotta love Postgres Procedural Languages

    I recently had to parse some text that was stored in a Postgres database. The text in each record had multiple lines of…

    5 条评论
  • How to use your regular IP when connected to a VPN

    How to use your regular IP when connected to a VPN

    Consulting for different Enterprise and Government organizations means that each of them requires me to connect to…

    11 条评论
  • Gotta Love Postgres Arrays

    Gotta Love Postgres Arrays

    I recently helped a client migrate their database from SQL Server to Postgres. Some of their tables, e.

    8 条评论
  • time.Format(layout) in Go

    time.Format(layout) in Go

    A common task in programming is to format a point in time in a certain layout that is easily understood by humans or…

    12 条评论

社区洞察

其他会员也浏览了