Using Python for conceptual learning or jump straight into C?

So I've been contemplating the idea of learning to code to help out with the project and address some aspects of it I feel are lacking. Presumably one would learn C if they'd like to get into contributing to FreeBSD. However, I'm torn as to how I should approach this. I understand C could be a difficult language as a first one, but my interest in contributing to FreeBSD sort of overshadows that notion. On the other side, I'd hate to get frustrated and give up on my attempts to learn due to my lack of prior programming experience. Should I "learn programming" first with a something like Python, or is a C good candidate as a first language as well? I imagine I could save myself the time by just using one language, but I also would like to learn programming concepts, correctly, with the least amount of friction.

Any thoughts?

Thanks.
 
Python is object oriented, C is not. While constructs like loops, if..then..else are largely the same in any kind of language, object oriented programming is different from procedural languages like C. In this respect Python may not be the best option to start with.

I once started with BASIC on the good old C-64. Then went straight to assembler. Learning C came much later. But knowing a bit about assembler definitely helped with grasping some of the interesting aspects of C; pointers.
 
My first programming language (not counting Atari Basic or Karel) was Modula-2, which I learned in college. But my second language was C. I think you could start there. It's not that difficult. Sure, it does less to stop you from programming wrong than just about any other language, but a good teacher is more important.
 
I think the most challenging part of C compared to Python is that it makes the programmer responsible for managing heap memory. It also provides weak support for organizing a large code base, but that's not so important to someone who's just starting.
 
The most important thing: what do you want to do/achieve? - if you don't know maybe just define a field for yourself...
If you want to contribute to FreeBSD, learning C is probably the best idea. Not only because the kernel, drivers and many system tools are written in C, but also because if you know C by heart you know how a computer really works. Thats one very strong asset you get from learning C. When you know C, learning Python happens really fast. For automation/automated test or so basic knowledge in Python is probably enough - you probably won't need the inner parts. Furthermore, Pythons C API is a big advantage: use your modules/programs written in C from Python is very straight forward.

This advice comes from one who programmed C/embedded and is now using Python almost exclusively for everything. Personally, if I had the time or the money so I could quit my work, I would go back to C and improve the things I don't like about FreeBSD, and there are some (improve bhyve, bring encryption to various tools like ggated, improve HAST, improve fuse/sshfs, enhance jails + ecosystem/linuxAPI so we could use docker/docker-like containers, maintain some cluster filesystems like glusterfs, bring smbv3 protocol support, port OpenBSDs PF version, security/performance improvements ... just an idea if you want to start somewhere hehe)
 
The hard core vi(1) fans will spank me, but for me, when learning programming 30++ years ago, the most helpful thing was a visual symbolic debugger, which let me set breakpoints and step through the code and examine changes of the variables, registers, bulk memory while the code is executing. You see your errors immediately and the effects of corrective measures as well. That time it was MacPascal and then Think Pascal on a Mac (Classic) - I still remember how the pre-release of MacPascal was advertised: "If you think this is something, then wait till we get out the bugs."

That said, my advice to all beginners is to look out for a decent IDE with a perfect integration of a visual symbolic debugger. Nowadays, I mainly do coding in C, Objective-C and C++ targeted to FreeBSD, however, I use Xcode on macOS because of the unbeaten integration of the debugger (lldb).

Chances are that the IDE's for C type of languages are more complete than for others. You want to ask for a decent IDE for your preferred desktop system, and then start with, and expand on the obligatory "Hello, World" project.
 
If you want to, start with C. It's not bad for learning programming. What you need (no matter what language) is a good teacher or book or guide. Once you know programming, you can learn new languages with just references and example code.

C has one drawback for learning: "undefined behavior". While modern languages are fully defined, which means you WILL get some (more or less meaningful) message or indicator on any programming error, this isn't the case with C. So, if you have written a C program that *seems* to work correctly, that's no proof it is correct after all -- it could crash and burn on some other system, or compiled with different settings, etc. I think it's obvious why this is a bit difficult for learning. On the other hand, it forces you to work conscentiously from the beginning and understand every bit of your program :)

About OOP: You can do OOP in C, all the primitives (pointers and structures) needed are there, but you have to implement the concepts yourself, so it's not a good language to learn OOP concepts in the first place. But I'd recommend everyone who already knows objects and methods to do some OOP in C. It helps a lot for your understanding how these concepts can be mapped to an actual machine.
 
People are telling you they started with BASIC and then waving you off Python, something incredibly more powerful. That doesn't make a lot of sense to me. ?‍♂️

Python is not my favorite language, but it has enough resources, is good enough for beginners, and can scale up into "useful" programming. It would be a fine starting place for learning how to program.

C on the other hand is full of sharp knives. I program in C and like it, but it is not particularly nice. As others have pointed out, managing memory manually is a challenge and, really, is a huge security problem. People are explicitly creating memory-managed languages like Rust that are attempting to "kill C" in order to stop these classes of errors but retain speed.

If you want to get into directly contributing to FreeBSD without any C experience as fast as possible, that's going to be a very difficult road. I would suggest creating a roadmap that will eventually lead you to where you want to go. Do you prefer quick results or long periods of study? First you need basic concepts like loops. Then you'll need more involved stuff like composition and other large program organization concepts. Basically, a compressed Computer Science course. In the meanwhile, you'll have to actually practice what you've learned, so you'll need some kind of program to work on. Again, I would suggest something in Python so you don't cut yourself on stuff that will just get in the way of learning. All code is garbage, eventually. Don't get too hung up on what you make.

Pivoting to C will be easy if you don't lean too hard into Python-specific stuff. It will be kind of like going on a campout and realizing all you have are sticks and twigs to work with. Then you'll learn the value of libraries.

What do you do as your day job, anyway? How much time will you have to devote to this?
 
From my experience, learning an language for it's own sake does not work. One can only learn a language when there is a task that needs to be coded. And then, the language should match the task.
So, if there is a piece of hardware with some ports, and it is necessary to make it talk to the computer, then C is a good choice. And if there is some logical entities that interact and change behaviour, some OO would be appropriate.
 
So I've been contemplating the idea of learning to code to help out with the project and address some aspects of it I feel are lacking. Presumably one would learn C.....

Yes, of course learn C because it is a very simple language (few keywords, few big ideas) and you must learn C to read and understand the code you are actually running (FreeBSD kernel, the POSIX utilities, graphics layers, audio processing, and almost all desktop software is written in C/C++. You must learn C before C++ so start by learning C.

A good course is Introduction to Programming in C (youtube playlist).

Learning to read code is important. Get a used copy of Code Reading: The Open-Source Perspective. The goal is to be code-literate. I guess right now most of us are illiterate. We shouldn't be -- code is important!
 
From my experience, learning an language for it's own sake does not work. One can only learn a language when there is a task that needs to be coded. And then, the language should match the task.
For initially learning programming *at all*, I don't agree. I'd say you are right for people who already programmed and want to learn a new language -- the best way (and reason) for this is indeed having a problem to solve, for which this new language is a good match, or maybe even a necessity because you want to extend some tool via scripting, plugins, whatever.

But for the programming newcomer, picking a task would often lead to something like "I want to write a cool game" ... (seen that quite often). It's much better to first follow a course and solve some example tasks, aimed at learning how to program.
 
Wow. These are all great responses. Thank you, I'll keep all of this in mind. I'm glad I asked my question here. :)

I think I'm going to take a plunge and dive straight into C given my end goal. My main motivators are desktop related things; ie. WiFi, Bluetooth, USB, ACPI, real time audio, etc. Especially WiFi and bluetooth. I hope to make FreeBSD a better in that domain. I don't expect this to be a smooth path to take, like others have said, it requires a great deal of studying and practice with C, but I think I'll enjoy the challenge. I have plenty of time on my hands so I'm not too worried about quick results; I just want to learn correctly.

From my research Python was suggested as a first language due to it's readability and ease. I agree with the sentiment that with a good teacher and/or guide (books) I should be ok. I might've glossed over that aspect in my thinking. I intend on reading this book, then follow up the K&R book i've read many others have suggested. There's a huge list of PRs and ideas from the wiki I can keep myself busy with too.
 
My main motivators are desktop related things; ie. WiFi, Bluetooth, USB, ACPI, real time audio, etc. Especially WiFi and bluetooth

If you've already made up your mind, choose USB first. The other things in that list have large and infuriating problems to the most experienced developer.

I have the ANSI K&R book. This should be fine if you're patient.
 
.....Should I "learn programming" first with a something like Python, or is a C good candidate ..... but I also would like to learn programming concepts, correctly.....

I put in my recommendation to learn C, heck and enjoy! C -- but I'm concerned about "I also would like to learn programming concepts".

For programming concepts you read Structure and Interpretation of Computer Programs. The appropriate lectures would be Berkeley CS61a Spring 2008 with Brian Harvey or MIT 6-001 Spring 2005 with Harold Abelson himself. Each of those courses has a full set of notes, assignments, and video lectures. SICP uses a language that is even simpler than C, Scheme, and the scheme you should use would be Racket. A entire approach to learning computer programming uses Racket. That's called How to Design Programs (HtDP) and there are courses and lectures for that. The HtDP courses are excellent and definitely teach concepts that are part of real code literacy.

Happy Journey!
 
I can never decide which is easier to start with C or C++.
I have a strong opinion that the answer to *this* question is C. C++ isn't completely bad, but it has a lot of complexity, and some of it is really unnecessary -- it has proven to be too complex for professionals in some (rare) cases, so I'd say it's definitely too complex for someone looking for a language to use while learning to program.
 
I intend on reading this book, then follow up the K&R book i've read many others have suggested.
I think that's backwards. K&R will be shorter and easier to get through but it might not be as up-to-date or inclusive as Modern C which I also hear is a good book.

EDIT: I see the Modern C book is under 300 pages which, I think, is about the same as the Ansi K&R book.
 
If you've already made up your mind, choose USB first. The other things in that list have large and infuriating problems to the most experienced developer.

Thanks for the suggestion. I figured USB would be the least difficult interface to work with. I'll probably start there.

I think that's backwards. K&R will be shorter and easier to get through but it might not be as up-to-date or inclusive as Modern C which I also hear is a good book.

EDIT: I see the Modern C book is under 300 pages which, I think, is about the same as the Ansi K&R book.

From what I've read, the modern approach book is better as an introductory/structured approach to programming using C; which I see as a plus for a beginner such as myself. It also teaches the language itself, hence it's length I believe. Whereas the K&R book is a supplementary book to it.
 
C++ isn't completely bad, but it has a lot of complexity, and some of it is really unnecessary.

I do see your point. Possibly it is easier to learn up to about 10% 3% and then once RAII, templates and exception safety kick in, its learning curve skyrockets. Whereas C doesn't really have a learning curve haha.

Is that in jest?

Nobody should start with C++ or Java if they want to learn OOP.
I don't necessarily believe the OP should learn OOP (at this stage it is not ideal to get locked into that mindset). The C++ was mainly so that they could experience C without the entirely raw memory handling (which can be tricky for anyone starting out).
 
I can never decide which is easier to start with C or C++.
C++ provides a lot of utilities (string, vector, etc) but ultimately C is a simpler language.

Once you have nailed something like a hangman or card game, for something more visual than command line, the following tutorials are great to follow whilst learning C or C++.


Thanks for the suggestion. It looks like another great resource. I hear a lot of game programmers do "C-style C++" and use only a small subset of it's exclusive features that may be lacking in C. But that's another topic. Also, I wonder if that's what the KDE guys do.
 
Back
Top