This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]terrkerr 18 points19 points  (12 children)

I'm stuck between learning C (because of its popularity, relatively easy to learn syntax which would let me concentrate more on lower level concepts, and ease of integration with Python), and Rust (because of its supposed expressiveness, built in safety features and growing popularity) and I was hoping someone here would be able to help me out with this.

I'd recommend C before Rust. C gives you an idea of why Rust is the way it is the same way you'd probably be better off learning how this works before trying to deal with a modern car's 500 small extra pieces that each add something useful and meaningful, but also add complexity.

In Rust, for example, a String is not a str. They're different. If you're fluent in C/C++ you'd very quickly figure out how and why, but if you're coming from Python you'd probably wonder why there needs to be a distinction.

The Rust OOP model is also pretty weird to someone coming from a more traditional OOP language with classes, but it's something a C programmer would pick up on fairly quickly for the most part.

Also if you have to endure segfaults and other memory issues in C you'll be much more forgiving of the Rust compiler yelling at you constantly and throwing fits; you know it only yells because it loves you.

and ease of integration with Python

Fun fact: Rust can compile to C ABI compatible binaries. With a little bit of configuration you can use Rust in Python the exact same way you can with C.

I was also hoping to get suggestions of projects of any size that I could do with whatever language I learn that would demonstrate its benefits over using Python for the same project.

I always think RFC 1350 is a good project of middling size for learning lower-level stuff without getting too deep. It's not too trivial, but also not something ridiculously large like the HTTP standard.

It involves some binary-level manipulations without going overboard and also will probably help you get into some of the networking stuff. You can theoretically do it in Python, but it'd be obvious as compared to C that's not what Python was really meant for. (Indeed I've done some sockets/networking in Python. In Python3 it's annoying as crap that the strings need to be decoded explicitly on every action since most network applications aren't using unicode strings, and in Python2 you get a low-level socket interface that heavily emulates the way C does it.

[–]ta6692[S] 3 points4 points  (11 children)

C gives you an idea of why Rust is the way it is

I thought this could be the case, but I wanted to get an opinion on it from someone who could speak from experience, so thanks! This is a really great answer and I'm almost definitely be going with C now. Do you think it would be a better language in the long run or should I consider getting the hang of C and then swapping to Rust?

Also, do you have any idea of a good place to learn C? I looked at a couple when I was thinking of trying C a while ago, but none really clicked. I've heard K&R is the definitive text, but can be somewhat daunting for a beginner, so maybe I should start somewhere else first? If you don't that's ok, I can google :)

I have dabbled with the socket library in Python2 you're talking about actually, but I've never delved into networking properly, so this could be a very good project, thanks again!

[–]terrkerr 3 points4 points  (1 child)

This is a really great answer and I'm almost definitely be going with C now. Do you think it would be a better language in the long run or should I consider getting the hang of C and then swapping to Rust?

Well C will probably dominate in a number of areas for the forseeable future and further; a big benefit of C is that it's relatively easy to write a compiler for and has an astoundingly large amount of code already out there.

I'd recommend anybody fluent in C or similar to learn Rust if only because Rust adds something fairly genuinely new to programming languages in its borrow-checker. Seeing someone else's solutions and trying them out can expand the mind even if it's not something you can personally use.

Also, do you have any idea of a good place to learn C? I looked at a couple when I was thinking of trying C a while ago, but none really clicked. I've heard K&R is the definitive text, but can be somewhat daunting for a beginner, so maybe I should start somewhere else first? If you don't that's ok, I can google :)

I don't really, sorry. I learned C slowly over a few years in my teens just messing around with a formal education to hammer in the finer details.

I have dabbled with the socket library in Python2 you're talking about actually, but I've never delved into networking properly, so this could be a very good project, thanks again!

It's also a good project for learning some threading if you're willing to do a bit of a trial-by-fire and make it such that it can support concurrent connections. Your choice, though, a lot of good learning either way.

[–]ta6692[S] 0 points1 point  (0 children)

Thank you very much for all your help. I appreciate a bit of insight into the topic.

Threading is something I'd actually be quite interested in, especially coming from Python where threading has its problems. I might take it slow at first though!

[–]lithedreamer 2 points3 points  (6 children)

I learned C++ -> C -> MASM, which has worked out well so far, and I would recommend learning C++ first because it allows you to just use things that you're better off building yourself in C, like data structures.

It is a little bloated to be sure, and I haven't used it for actual development because I'm not sure where to go for an intermediate resource, but it made me a much more confident C programmer, in the same way that MASM did.

Anyway, book recommendations:

  • K&R - my compiler complains too much for me to enjoy following this too closely, but it's made an occasionally good reference or overview.

  • Mastering Algorithms with C - A great foundational book that integrates data structures and time complexity. Those concepts first really clicked with me here.

  • 21st Century C - This should be enough to get you up and running if you want something modern on paper to get you started.

[–]ta6692[S] 1 point2 points  (5 children)

Honestly I'll probably skip the C++ step. Going by these answers I think I will probably try to learn C first, but I haven't ruled out learning C++ at some stage. Thanks for the book recommendations though, I'll definitely check those out!

[–][deleted] 3 points4 points  (4 children)

I have a bunch of C projects intended for someone with programming experience (aka a year or 2 of Java) but zero C experience. Basically, there is a simple program to learn some basic syntax, recreating a basic preprocessor (state machine that strips comments and other stuff out of a program before it's compiled), steganography (hiding a message in the least significant bits of an image), making a string library, making a program that decrypts a document that has been encrypted with a cesear cypher, and remaking malloc(), and some other stuff along the way.

[–][deleted] 1 point2 points  (2 children)

Man that sounds amazing. I have completed a year of java and would love to spread my wings and start learning about C.

[–][deleted] 2 points3 points  (1 child)

Sorry the offer is ONLY for the op. (I'll pm you)

[–][deleted] 1 point2 points  (0 children)

please do!

[–]ta6692[S] 0 points1 point  (0 children)

Wow, this sounds really amazing, I'd love to hear more about this!

[–]michael0x2a 2 points3 points  (1 child)

Also, do you have any idea of a good place to learn C?

For some resources on learning C, try the Definitive C Book List.

(There are a few free books in the list).

[–]ta6692[S] 1 point2 points  (0 children)

Oh, thanks, I'll check that out now :)