Settings

Theme

Ask HN: How do I start learning about lower level compiled languages?

30 points by budafish 3 years ago · 33 comments · 1 min read


Hi HN

I work quite a lot with Python and JS, and some other higher level languages, but have recently wanted to get involved in lower level languages, particularly NIM. I have already started coding with it, but it comes with a whole range of new topics that are semi-unknown to me, heaps, stacks, memory management, pointers, compilers, debugging compiled applications, garbage collection, etc. Does anyone know of any material that can help demystify those topics and any other that come up.

I know the common answer will be to start coding and learn it as you go along. But I was curious to understand if there was any supplementary material that can support my introduction to this new works of coding?

HexDecOctBin 3 years ago

Learn C. Despite all the slander, it remains the easiest to learn and most widely applicable Systems language. I personally recommend this book (wish it was available when I learnt it): https://www.amazon.com/Effective-Introduction-Professional-R...

  • mbrodersen 3 years ago

    Yep exactly. If you truly want to understand low level then the only right answers are C or Assembly language.

colangelod 3 years ago

As other have noted, pick up a copy of this book https://en.wikipedia.org/wiki/The_C_Programming_Language it was written by the two guys that created C (and also contributed quite a bit to UNIX). Its perhaps one of the truly "original" programing textbooks (and it does not have some wacky animal on the front). The creator of C++ also has written many books on the topic https://www.stroustrup.com/books.html all that are pretty decent.

If you want to lean by doing my advice is to get an arduino and try and build stuff. The arduino has a C like language (and will also accept C code) which is a great way to learn the language with fun projects. More importantly it will force you to learn C in a very restricted environment where you actually have to think about clock speed, memory management and code efficiency due to the micro controllers limited resources.

itsmemattchung 3 years ago

Two recommendations:

  1. Switch to a team (or company) where they are developing in the language you want to learn. 
  2. Work through the book "Computer Systems: A programmer's perspective"
Nothing beats daily programming in said language on a daily basis. Similar to yourself, I was predominately writing in higher level interpreted languages. Although I did teach myself C by working through books, writing programs and more, it was not until I started writing C on the job that really accelerated my learning. Very quickly, hit my fair share of segfaults ... discovered that we never called malloc (i.e. allocating memory on the heap) during runtime, stepped through our mark-and-sweep algorithm.

As for the book recommendation, it will cover all the above topics you are interested in such as heaps, stacks, memory management, etc. There are lots of other books that I studied during my CS education but self studying "Computing Systems: A programmer's perspective" really switched a light bulb on in my head.

  • markus_zhang 3 years ago

    Thanks. I really like the first approach.

    Now that I work as half data engineer and half infra (cloud). I do have a few hobby projects using C/C++ (e.g. embedded for C and game programming for C++), but nothing really completed and polished. How do I convince someone to give me a job to work on low level systems, even as a junior?

    Should I continue working on low level projects and hopefully they are good enough, or there are other approaches?

    TBH I'm willing to do free part-time work on sys programming if given the chance, but industry doesn't work like this.

    • rramadass 3 years ago

      >How do I convince someone to give me a job to work on low level systems, even as a junior?

      >Should I continue working on low level projects and hopefully they are good enough, or there are other approaches?

      The way i had done this in the past was to really learn the language well (today you will also have a GitHub repo of projects to show), practice algorithms/data structures/interview questions in C/C++ and finally, understand the tight coupling between C/C++ and underlying OS i.e. "Systems Programming". This is the preparation phase.

      In the execution phase, you contact companies/recruiters/friends/anybody at all with suitable openings and make it very clear that you really really want the job even if it means taking a pay cut i.e. Salary/Money should not be the goal. Make it clear and open that you are looking for a break into that domain and you are willing to put in any Time and Effort reqd. Finally, try smaller companies rather than big ones at first; their requirements are less strict.

      HTH

  • tanganian 3 years ago

    Can get my hands on the 2nd edition for cheap, or is the 3rd edition required? It's quite expensive.

    • rramadass 3 years ago

      I have all three editions. The 1st one is 32-bit only, the 2nd covers both 32 and 64-bit and the 3rd is 64-bit only.

      If you can, buy the 3rd edition (this is one of the few books worth its price) and then pickup the 1st edition for cheap/free from somewhere. Try for Used/Secondhand copies to save money.

      There is a lot to learn from the book; all of them necessary for a beginner to connect the dots and get the full picture. So don't get stuck on any one chapter/problem but make sure to cover all the chapters in sequence skipping over unnecessary details in the first couple of passes. As an example you don't need to know the nitty-gritty of PIC/GOTs/PLTs/Assembly minutiae etc. in the beginning but just understand the concepts of Relocatable code and Executable vs. Shared Object files.

    • flyingfences 3 years ago

      The authors have written up a summary [0] of the differences: in short, 3e reflects the changes in typical computer hardware over the last decade or two.

      Note also that there are two versions of the third edition: the standard edition (colorfully striped shape on the cover) and the international edition (globe made of circuit boards on the cover) which is quite a bit cheaper. The contents of the chapters are the same, but the exercises at the ends of the chapters have been rewritten, by the publisher's lackeys, not by the original authors, for the international edition, very poorly by all accounts.

      [0] http://csapp.cs.cmu.edu/3e/changes3e.html

    • itsmemattchung 3 years ago

      Do the labs too: these exercises are the most valuable. In particular, the binary bomb forces you to really understand the stack, heap, assembly instructions.

    • itsmemattchung 3 years ago

      1st or 2nd edition is fine

cb321 3 years ago

Most well vetted material you will find on this will use regular old C, not Nim, like that Bryant & O'Halloran Computer Systems from a Programmer's Perspective mentioned in a sibling comment. It probably won't rely on C that dramatically, but your best bet today will probably be to learn the used subset of C and Nim analogues at the same time.

Your questions are a bit all over/vague. The Nim forum (forum.nim-lang.org) is generally very helpful and if you ask more specific questions then you can get better answers.

There is also https://ssalewski.de/nimprogramming.html which has some material on what you are asking about.

vrnmh 3 years ago

As someone who is currently learning Rust, which is lower level than Java (used at work). Having studied C and using some portion of C++ at university has been immensely helpful.

I would recommend learning C, as it is a relatively small language; and focusing on understanding the underlying assembly which is generated by the compilers. (Compiler Explorer gotbolt.org)

You can also refer to Stanford CS107 lectures taught be Jerry Cain when you are somewhat comfortable with C.

ActorNightly 3 years ago

Start with the basics. It will give you a basic foundation to appreciate how computers work.

https://www.nand2tetris.org/

https://nandgame.com/

After this, start learning C. There will be a bunch of semantics to learn, which are all important, however with every small program that you write , you should generate the assembly code with gdb, and aim to understand what the assembly is doing (calling convention for functions, registers, syscalls, e.t.c). This will

Then, figure out how linking and loading works (i.e turning assembly code into the shape of an executable understood by the OS). Objdump and readelf are going to be your friends, as well as getting familiar with gdb debugger.

https://eli.thegreenplace.net/tag/linkers-and-loaders.

This will give you a good foundation for low level development. You can then branch off to other areas like CUDA/OpenCL/AVX programming, microcontroller programming, kernel development, e.t.c

willcipriano 3 years ago

C snobs don't like this book, but it's free and fun: https://buildyourownlisp.com/

I ended up expanding the project pretty far: https://github.com/willcipriano/Connery

  • HexDecOctBin 3 years ago

    Neither C snobs nor Lisp snobs like this book, because it uses bad C techniques to implement Lisp is the most weird way (who uses a hand-rolled Parser Generator to parse Lisp?)

dzaragozar 3 years ago

I would suggest to read "The C Programming Language". It is a short and well written book on C programming.

vkazanov 3 years ago

Sure, C is the original low-level language and any low-level discussion should start with it.

There is problem with the classic introductory book though. "The C Programming Language" is a classic and ppl mention it all the time. But it's horribly outdated and doesn't cover the living language at all. It's more like a description of a language authors wanted C to be, not the real thing.

Take "C Programming: A Modern Approach" or something along the same lines. Go through it, get a hang of the language then follow up with something like "Effective C" or "Modern C", which are good recent mid-level books on the language. I also like "The C Puzzle Book".

Then there's a brilliant "Expert C Programming: Deep C Secrets" explaining subtle details of the language.

One thing that is missing from the books is POSIX. The language itself is very barebones so in practise people are always coding against some Linux/*nix/POSIX or equivalent APIs. These serve as a std library of sorts as otherwise even moderately involved projects become prohibitively big.

mikewarot 3 years ago

If you want to understand how things work at the lower level, I think the Compiler Explorer[1] might be a good place to start. You can enter a program in a while variety of languages, and see the code that results. Python and Nim are both supported, along with a wide variety of other languages.

[1] - https://godbolt.org/

shadowofneptune 3 years ago

My own introduction to this, and to understanding programming rather than writing a few scripts for calculations, was the book "C Programming: A Modern Approach." It covers reasonably up-to-date C, assumes no previous expertise and teaches not just the language itself but practices for structuring programs, how to optimize, etc. I picked it up in 2020 so it should still be useful.

I personally am dissapointed by people recommending "The C Programming Language." It's a terse book that doesn't go into the detail I found helpful when starting.

derbOac 3 years ago

"Memory as a Programming Concept in C and C++" was a helpful book for me. I'd stick to C as C++ is kinda kludgy syntactically with higher level constructs and they're not key to lower-level stuff anyway.

After that, you might look into Rust. I don't have any particular recommendations; there was/is an introductory text online by the original Rust developer I found helpful. Rust is sort of hyped the last few years, but there's good reason for it, and its approach to memory builds well on classic C-like ideas.

dusted 3 years ago

I don't know anyhting about NIM in particular, but you touch on points with which I'm right at home, and I suggest you have a look at programming in C, it's a simple and small language, and its syntax is less intimidating than C++, while at the same time introducing you to the concepts you mention.

The nice thing about C in your case, is that you won't get very far before being introduced to things like pointers, and allocating memory on the heap :)

bennysomething 3 years ago

https://www.goodreads.com/en/book/show/910789.The_Elements_o...

Also Google from and to Tetris as there are courses using the book called this. In fact that's what they were going to call the book.

philonoist 3 years ago

I hope you go through fundamentals first. You can't understand C without them[0].

Nothing explains systems programming like C[1], including Rust. Godspeed.

[0] Introduction to Computing Systems: From Bits & Gates to C/C++ & Beyond 3rd Edition by Yale Patt (Author), Sanjay Patel (Author)

[1] Books by Robert C. Seacord and/or Noam Nisan

sitkack 3 years ago

Folks recommending C are doing you a disservice, C is just one example of a systems programming language. And that example is now outmoded, Rust or Dlang would be fine first systems languages, I haven't looked at Nim in years, so I can't comment on that.

Someone else mentioned The Compiler Explorer, which is a great resource. I would second that.

Questions I would ask yourself are

1) How is a low level language different than the languages you are coming from? What do they solve for you vs what do you have to solve yourself?

2) What are the qualities you are solving for? Latency, predictable performance, memory bandwidth, IPC (instructions per clock cycle), etc?

All of the issues you would like to learn about can be learned directly in Python. So you have to figure out what exactly you want to learn and then learn that thing. Just learning about lower level compiled languages is like learning about rakes and shovels if you are a gardener.

  • flyingfences 3 years ago

    I have to disagree emphatically that C is outmoded. It may lack some of the polish and novelty of Rust et al, but it's still a fine language. More importantly, it's an industry standard, has been for ages, and will be for ages. So many of the resource and reference material out there (not just for low level / systems programming but especially for it) presumes a working knowledge of C that a person would do himself a disservice by not picking up the language.

  • UncleMeat 3 years ago

    I do agree that you can learn these things in a higher level language.

    I completely disagree that C is no long relevant. The amount of new C code written today across the world dwarfs the amount of new Rust, D, or Nim code combined.

  • rramadass 3 years ago

    This is really the wrong sort of response.

    It is quite clear from the post that the author had heard of some "low level concepts" but does not have a clear idea of what they mean much less understand them. This is NOT a "XY Problem" as your response seems to suggest. They are basically exploring in the dark and need guidance. As many have pointed out, "C" is the answer since those concepts are "natural" in that language and moreover is the "lingua franca" of low-level programming.

  • cb321 3 years ago

    I like your focus on better questions. "those topics and any other that come up" was especially vague as was "semi-unknown". ;-)

    FWIW, I doubt anyone was suggesting "large scale applications programming in C"..Just the nuts & bolts & basic vocabulary..the way a program/process interacts with an OS, etc. in the very simple cases/scenarios. The main (but not only) way people use Nim is through the C backend. { The code generated by the Nim compiler is not that easy to read or intended to be so, of course. } There are also OS books to consider like The Design of The Unix OS or Advanced Programming in the Unix Environment. These also use very minimal little C examples. Everyone learns differently, though. I think more delineated goals and background level would yield better advice for @budafish.

    Teaching has also evolved over the decades. Teaching of C was/is more "hand in hand" with the ideas the poster was asking about. For example, the K&R C book walks you through writing both stack allocators and heap allocators on top of raw memory.

  • mbrodersen 3 years ago

    Software written in C/C++ runs the world. Including the operating systems, VMs, interpreters etc. running (almost) all other languages. It is the bedrock that everything rests on. So learning C is highly relevant. It will take decades (if not forever) for Rust to get even close to achieving that kind of impact.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection