Live data from Hacker News

Ask HN: How to learn proper systems programming?

news.ycombinator.com

61–70 of 97 posts

Re: Ask HN: How to learn proper systems programming?

#61

Years ago I modified the Postgresql source code (8.xx). It's something I was terrified of doing. But once I got in there and started poking around, I realized it was just ordinary plain-vanilla C code. Not C++. Just C code. With my local copy, I started to hack pg_dump to do something special that we wanted at the time. Even after 30 years of coding, I'm not that especially good of a programmer. But I ended up gettin…

> Those bits are just bits. And it's just code... and most of it was not written by wizards. Just ordinary people like you and me. Don't be afraid man. Code is easy and doesn't scare me. I'm scared about the platform though: code runs on platforms (POSIX, mostly), which are incredibly dated, ill-designed and full of terrible corner cases[1]. There's so many ways to shoot yourself in the foot I'm afraid to do anything…

Most POSIX APIs are crap, but most significant systems projects don't code to them directly. Almost all large projects have their own internal (or third party) libraries that either wrap or reimplement the underlying POSIX APIs.

That said, at some point knowing the POSIX APIs does become necessary, but that's usually relevant a bit later when you start becoming interested in modifying the toolkit of large projects.

If you're wanting to start a project on your own rather than jump into an existing project, in a nutshell, if you don't have hard real-time requirements, if you're using C, use glib, if you're using C++, use Qt. There are other libs that are useful for real-time usage (basically things that don't ever have hidden memory allocation), but I'm not familiar enough with that space to recommend one.

Re: Ask HN: How to learn proper systems programming?

#63
post #16

There are a few good YouTube channels of strong system programmers doing live coding. Watching videos takes time, but you can pick up lots of techniques, big and small, by watching people work. Since you're looking at rust, https://www.youtube.com/user/gamozolabs/videos could be a good fit.

Any channels you can recommend that have live system coding in C?

Re: Ask HN: How to learn proper systems programming?

#64
post #12

There are two books that taught me how systems work. - One system in isolation - Operating Systems: Three Easy Pieces . Covers persistence, virtualisation and concurrency. This book is available for free at https://pages.cs.wisc.edu/~remzi/OSTEP/ - Multiple systems, and how data flows through them - Designing Data Intensive Applications . Covers the low level details of how databases persist data to disk and how mult…

On OSTEP, there's a course in educative.io from the authors of the book:

- https://www.educative.io/courses/operating-systems-virtualiz...

Which is worth checking as an introductory course.

Re: Ask HN: How to learn proper systems programming?

#65

maybe you can start with the classic exercise of writing your own shell. That’s a great way to learn most of the fundamentals of systems programming (and usually the go-to exercise for that class on CS courses)

Yep. Write a grep and find (IO-loop, filesystem), a shell (child processes, signals), a simple nmap-replacement (network, DNS), a forking and a multithreaded webserver (more network, more children, synchronisation), a clock with seconds display and something that synthesizes and plays music on keypress (timing, waiting).

Everything just in the simplest sense, no fancy features needed: the grep just needs a string parameter to search for and some files, the shell doesn't need completion, scripting or variables, just execution and background jobs. For the webserver, just serve some static files from the URL, ignore security, concentrate on getting lots of clients served at the same time however. Bonus points if you make the main process/thread gather meaningful statistics/logs and not screw up concurrency. Make sure to learn the right synchronisation primitives and use them properly. For the clock, make sure to explore sleep-based, loop-based and signal-based approaches and compare them. Get all three second-ticks to be in sync with your pocket watch and not skip/delay/hang. The music exercise is similar, just event-based (you get to handle key input and buffer low or tick events), either with something like select/epoll or multiple threads. The music itself is not interesting, a simple sine or rectangle signal suffices. But of course reaction time should be low and sound should be glitch-free.

What is missing from the above but important are the security aspects of systems programming, most of which are either problems with certain languages (learn how to avoid, recognize and exploit a simple buffer overflow, format string exploit), security aspects around file creation (especially temporary files, but also general symlink attacks), SUID-bits, permissions/ACLs/MAC and generally privilege separation. Those aren't easy to put into learning-by-doing exercises, because you would need an attacker to slap you over the head when you make a mistake there ;)

As a programming language, for Linux/Unix I would strongly recommend using C, not C++, not anything else. Use libc or plain syscalls, nothing fancier. When you have mastered the above in C, you know how to appreciate other, better languages, but also know where those may be lacking. If you just do the above in Python, you learned nothing about systems programming and everything about Python lib idiosyncracies

Re: Ask HN: How to learn proper systems programming?

#67
post #61

Earlier quoted context omitted.

> Those bits are just bits. And it's just code... and most of it was not written by wizards. Just ordinary people like you and me. Don't be afraid man. Code is easy and doesn't scare me. I'm scared about the platform though: code runs on platforms (POSIX, mostly), which are incredibly dated, ill-designed and full of terrible corner cases[1]. There's so many ways to shoot yourself in the foot I'm afraid to do anything…

Most POSIX APIs are crap, but most significant systems projects don't code to them directly. Almost all large projects have their own internal (or third party) libraries that either wrap or reimplement the underlying POSIX APIs. That said, at some point knowing the POSIX APIs does become necessary, but that's usually relevant a bit later when you start becoming interested in modifying the toolkit of large projects. I…

How is that not just good old “application programming”?

My own definition of “system programming” is exactly “developing on top of the system” vs “developing in the comfort of a helper library” (and its limits). I consider myself a decent application programmer, but I'm not a system programmer (at least not yet ;).

The OP was talking about Postgres, if you don't know how the pitfalls of write(2), or don't know how to use mmap(2), you're going to have trouble making a database on your own.

Re: Ask HN: How to learn proper systems programming?

#69
Come up with a project and write code. For example you can just implement the web server you were mentioning. That is a good start. Build it and see how to scale it to handle millions of requests. Just creating the code to test it will be a good exercise. You can dig into a lot writing a web server. After that you can pick up another project in the kernel.

Re: Ask HN: How to learn proper systems programming?

#70
post #61

Earlier quoted context omitted.

Most POSIX APIs are crap, but most significant systems projects don't code to them directly. Almost all large projects have their own internal (or third party) libraries that either wrap or reimplement the underlying POSIX APIs. That said, at some point knowing the POSIX APIs does become necessary, but that's usually relevant a bit later when you start becoming interested in modifying the toolkit of large projects. I…

How is that not just good old “application programming”? My own definition of “system programming” is exactly “developing on top of the system” vs “developing in the comfort of a helper library” (and its limits). I consider myself a decent application programmer, but I'm not a system programmer (at least not yet ;). The OP was talking about Postgres, if you don't know how the pitfalls of write(2), or don't know how t…

Most people don't get into systems programming by writing a database completely on their own, and it's fair to say that the line between application and systems programming is fuzzy.

Here are a bunch of things I would broadly consider systems programming:

- Kernel and driver development

- Low level library development (pretty much anything involving bit wrangling)

- Platform abstraction libraries

- Database development (not usage)

- Message queuing systems

- Daemon / server development

Perhaps the recurring pattern there, and differentiated from application programming is that most of those are tools for other applications, rather than applications themselves. I don't think that all library / daemon development is systems programming, but a whole lot of it is.

I'm coming from a background of having done 5 of the 6 of those groups (though there could obviously be more listed there). For most significant projects, as noted, there will be internal APIs that wrap system APIs (or in the case of the kernel, where the system APIs are totally irrelevant, except for the parts that implement the system calls). Generally someone first jumping into those projects isn't going to immediately start hacking on the internal libraries.

As it were, I have actually written a database from scratch [1]. That database uses Qt and Qt-like APIs internally where possible. There are places in there where you need to know the intricacies of mmap, fsync and similar, but they're compartmentalized to a couple of classes. I'd still call code that isn't in those couple of classes "systems programming".

[1] https://blog.directededge.com/2009/02/27/on-building-a-stupi...

Post reply on HN