←Back to posts


C’s ugliest syntax and Rust

2021-09-09

Programming

First of all, I think I need to start by declaring that I am, by no means, a C hater. It is indeed one of my favorite languages of all time. The minimal and principled syntax makes it hard for any language to beat it. The pointer arithmetic seems a bit weird at first glance, but once you get used to it, it gives you the feeling of full control over the memory of your computer. I believe it is the best choice to make a operating system. Believe me, I love C.

However, there is an element of C that has annoyed me and it is not a trivial matter at all. Consider the snippet below,

int a = 10;
int *a_ptr = &a;

If you are an experienced C programmer, the problem would not be obvious to you at all. Now see this.

int a = 10;
&int a_ptr = &a;

The latter syntax is better than the former in so many ways but let me point this one thing out. In int *a_ptr, int * is type and a_ptr is the value, which can be quite confusing unless you are too used to this weird syntax.

And then I realized I was not alone who thought this way. The Rust language designer did exactly the right job, by choosing the latter syntax over the former one. Much respect to the designer who made this world a better place.