aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blog/2023-09-15-why-c/why-c.md120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/blog/2023-09-15-why-c/why-c.md b/src/blog/2023-09-15-why-c/why-c.md
new file mode 100644
index 0000000..60a2c25
--- /dev/null
+++ b/src/blog/2023-09-15-why-c/why-c.md
@@ -0,0 +1,120 @@
1# Why C?
2
3Love it or hate it,
4[C](https://en.wikipedia.org/wiki/C_(programming_language)) has
5consistently been one of the most popular languages for the last
650 years or so. How did it become so popular? And why are people
7(like me!) still using it?
8
9## Quirky, flawed, and an enormous success
10
11I have recently read
12[this article](http://cm.bell-labs.co/who/dmr/chist.html)
13by Dennis Ritchie. Besides summarizing the history of the language,
14in this paper Ritchie also tries to answer our first question. He
15gives four reasons for C's success:
16
17### UNIX
18
19C was the system language of UNIX, and the popularity of UNIX in
20the 70's and 80's made C popular too. In other words, UNIX was the
21[killer app](https://en.wikipedia.org/wiki/Killer_application) of C.
22
23### Simplicity
24
25Ritchie phrases the simplicity of C in terms of how close it was to
26machine instructions while still being sufficiently abstract. This
27means that C compilers are easy to write, and the language could be
28ported easily to different systems.
29
30### Pragmatism
31
32C was designed with a concrete goal in mind, not as some kind of
33abstract, ideal programming language. It was always in touch with
34the "real world" and the needs of programmers.
35
36### Stability
37
38Despite some changes throughout the years, C has always remained
39remarkably stable and free of proprietary extensions.
40
41## Why did I choose C?
42
43In 2019 I began working on a
44[Rubik's cube solver](https://nissy.tronto.net).
45At the time I had basic or intermediate level knowledge of multiple
46programming languages, but I was not an expert of any of them. I
47considered many languages for this project, including C, C++, Java,
48Python and Rust - this last one I did not know at the time, but I
49have wanted to learn it since 2013 or so.
50
51In the end I picked C, and these were the main reasons:
52
53### Ubiquity
54
55Since my program was going to be relevant to a small nice of people
56who are not necessarily programmers, I wanted it to be as accessible
57as possible in terms of required infrastructure (compiler, libraries).
58Sure, I could provide *some* compiled executables, but not for all
59systems. It would be much easier if people could just type `make`
60or `./compile.sh`, and then run my program.
61
62C compilers are everywhere, while the same cannot be said of e.g. Rust.
63
64### Simplicity
65
66Since C is a simple language, knowing a bit of C means knowing quite
67a big portion of it, in contrast to, say, C++. For this reason C
68was the language I was more confident picking up to start a big
69project, despite having more experience with Java or C++ at the
70time.
71
72### Stability
73
74I don't like to re-learn my language every couple of years for a
75project that I am working on in my spare time. Backward-compatibility
76is a thing, but, as languages introduce more features, the preferred
77idiomatic way to do certain things changes, and old code starts to
78"smell" without any good reason.
79
80[RANT]
81
82*Python2 was killed and now a bunch of tiny programs (mostly
83[Project Euler](https://projecteuler.net) solutions that I have
84no reason to "port" do not run anymore :( I want my print statements
85back!*
86
87*It seems Java has a new way of doing GUIs every time I look at it.
88When I read my first Java book,
89[AWT](https://en.wikipedia.org/wiki/Abstract_Window_Toolkit) was the
90standard. When I read a second book,
91[Swing](https://en.wikipedia.org/wiki/Swing_(Java)) was all the rage.
92Then I went to university and they taught me
93[JavaFX](https://en.wikipedia.org/wiki/JavaFX).*
94
95[/RANT]
96
97### Performance
98
99I knew from the start that performance was going to be important
100for this project, not only from the algorithmic point of view but
101also from the low-level side of things. I needed manual memory
102management and little overhead. This ruled out Java and Python.
103
104## Conclusion (and memes)
105
106I think there are some interesting similarities between the reasons
107of C's success acoording to Ritchie and the reasons I picked it for
108my personal project. I don't consider myself a C expert, and I know
109even less about the other languages I talked about in this post,
110so take my opinion as it is.
111
112Instead of pretending to be more knowledgeable than I am and writing
113some clever and insightful conclusion for this post, here is a short
114list of memes and folklore about the C programming language.
115If you know more of them send me an email and I'll update the list!
116
117* [[YouTube, song] Program in C](https://www.youtube.com/watch?v=tas0O586t80)
118* [[YouTube, song] Write in C](https://www.youtube.com/watch?v=1S1fISh-pag)
119* [[Text] Linus Torvalds on C vs C++](https://harmful.cat-v.org/software/c++/linus)
120* [[Wikipedia] Duff's device](https://en.wikipedia.org/wiki/Duff%27s_device)

Generated with cgit - Back to sebastiano.tronto.net