Hacker News new | comments | ask | show | jobs | submit login
Ask HN: Learning C as beginner better than learning C just after python?
22 points by philonoist on Oct 14, 2017 | hide | past | web | favorite | 31 comments
Freshman Year | Autodictact | Non-CS Major |Knows no programming language. Looking forward to learn coding for building with best design principles, gaining efficiency of data structures and thinking abstractedly in algorithmic rollercoaster of fun.

What is the cost benefit analysis of Going from 0 to C than Python to C?

I've already learned Python enough to where I can get almost anything I need to do with it done. This is probably the place you'll want to get to. Someone gives you a problem and then you solve it.

Python's development cycle is so fast that problem solving and debugging is a breeze. (All you need to do is write some code and then run it. No compile/run phase.) But then there comes a time when Python is just plain too slow for what you want to do. For example Image processing/Backend for web/Game development with intensive graphics. After this I found that it was time for me to start learning a faster compiled language such as C. Moving from python to C is a real pain. This is mostly because of all the really nice built in types: dynamic lists, strings, etc. that you get with Python already.

What's really cool is that Python allows integration between C libraries and python code. (ctypes) You can write something that may run really slow in pure Python. After that you can find the slowest parts with a profiler and replace them with external C library calls. (That you've written.)

In the end you end up with the lightning fast Python dev cycle plus the great optimizations and speed that C/native code gives.

In short form, Python is a great first language. C is a great first language too. You can have the best of both worlds with ctypes.

This post reminded me when I started programming, very nostalgic. I started out with C as my first programming language simply because the language rankings at the time said it was the most popular. Looking back, I don't think C helped me out as much as I wanted it too.

Now to answer your question by looking at your goals. "Knows no programming language" lets me know that you are starting from scratch. In my opinion, this means you need to answer the following question first: do I even like programming? The best way to answer this is to not abuse yourself with C but instead start with python to get a real feel for what programming is.

"Learn coding for building with best design principles" means you want to learn good habits early on. Python has a stable style guide (pip8) and the zen of python, so at least some good habits can be learned quickly. I don't think there is a comparable zen of C, but maybe that's because I haven't looked.

"Gaining efficiency of data structures" means understanding why data structures are important in program design. Python has some pretty solid built-in data structures (i.e lists, sets, dicts, tuples) that are good for beginners who want to experiment with data structures. C doesn't have lists, sets, dicts, or tuples, but you can implement them if you try hard enough.

"Thinking abstractedly in algorithmic rollercoaster of fun"...I think what you meant is the freedom to think about an algorithm and to implement it with ease. Python is fantastic for this, while C requires a lot more thinking to get a thought manifested to code.

This post kinda struck a chord with me because I wrestled with the same question when I started 4 years ago. Python helped me more than C because I was more creation oriented. I wanted to implement a useful tool as fast as possible. With your questions in mind, I think python would be better choice than C as a beginner.

I apologise with the vague description of question details. I have been to a workshop where they demonstrated both python and C. I was fortunate to have a hands on session with few programming tasks and solving problems. The conclusion I came to, is - I love programming.

As I said in other comments before, I was apprehensive if I could deal with initial frustration due to subconscious comparison of how easy life was with python. I asked myself If I would trip off; will I be able to cope up; will my brain be malleable enough or get hardened against the higher cognitive load C poses comparing to python, etc. with no good answers. Hence this question.

Every other commenter echo with your respected opinion and I appreciate your well explained suggestion. I just needed my answers through other's experiences to the above questions.

I will be "starting out with python"(amazon<dot>com/dp/0134444329).

Thank You.

You'll understand how things work more if you start with C. But, at the end of the day, programming is usually a way to get something done. You're going to get a lot more done in Python than C as a beginner. I have a good amount of experience working on real world embedded applications in C, and I would only recommend it as a first language to people who have a specific interest in real-time embedded electronics, drivers, and operating systems. You can actually emulate a lot of what other programming languages do in C, but you won't until you know it's there to emulate. Additionally, the "Compile/Run/Rewrite" cycle in C isn't as good for learning as the "Rewrite/Refresh" cycle in Python.

I've actually been recommending HTML, Javascript, CSS, and git (specifically with github's "GitHub Desktop" application) to my friends/family that want to start programming. But of the two you'd mentioned, I'd vote for Python.

Interesting that you recommend Javascript. I was under the impression that beginners have impressionable minds and it goes long way of how good a programmer is with first programming language itself. Maybe that is why Java is not recommended as a first programming language(i.e. "every solution needs hammer" mentality is hard to unlearn in the future I guess).

I am not intimidated by REPL/compile methods per se, but what path of learning these languages bring to the table. As emphasised in question details - "gaining efficiency of data structures and thinking abstractedly in algorithmic rollercoaster of fun.",for it, I will have to learn both. I will have to go through one door to another anyway, its just the order. Python-to-C or C-to-Python?.

Yes, I have operating systems in my bucket list. I must know the nuts and bolts without fail.

I see your point. Thanks!

In my experience, unless you really enjoy programming and want to learn how a computer works, dealing with C is hard. As a professional embedded software developer, even after 3 years of programming in C, I sometimes have to stop and think about complex pointer structures.

So if you just want to play around, do cool stuff quickly and get moderately good in programming start with python, beware it might be hard for you to come back to C.

But if you want to become more than good and really understand what advantages python gives you, start with C. There is little extra effort involved: just implement every data structure in C once and learn about pointers. You will become a much better programmer. Also, you will enjoy coding in python more, once you know C.

I guess the shorter answer is to start anywhere. The longer answer is the question of whether you want to enjoy the act of programming or the results that you achieve with programming. In the former its start with C, in the later its start with Python.

SIDE NOTE: As caseymarquis said, if you want to go the python route, go for javascript. There is little lost in the process, but the value of doing something cool is exponentially increased.

Actually, I apologise for my vague description. I did enjoy simple programming tasks and problem solving with python and C in a workshop held in my city. This workshop made me fall in love with code and it piqued my curiosity to know how a computer works. I am totally excited to make this my career.

I must learn C and Python without fail for learning Data Structures and Algorithms. I can't leave any one of them. It was just the order. I am getting more and more convinced with your line of suggestion as other's opinion keep pouring in.

Thank You!

C has become a niche language used in some tech companies (for OSes, drivers, embedded etc.), while Python has application also outside tech (finance, e-commerce, etc. etc.). The non-tech jobs far outnumber the tech jobs (maybe at 1000 to 1?), and are also more evenly geographically spread.

Regarding algorithms, even developers who do things algorithmically heavy, such as for example data compression or procedural 3D animation, claim to work on the actual algorithms for maybe 10% of their time. 90% of the job is actually the "everything else" - testing, optimising, polishing, chasing platform bugs etc.

This is something interesting and new to me. I will keep this in mind when I join an internship.


In my experience, learning C as a begginer is hard. But it also made me learn a lot of things including things like inline assembly. well one may ask how useful all that could be but undestanding the underlying mechanism is always good in my opinion. C would make one use get the habbit of using memory and resources judiciously. Python is an easy way gets things done fast but since it is not a strongly typed language, moving from python to C would probably be a bigger pain. I think 0 to C is better and worth the pain.

There's a really great course from Harvard called CS50[1][2]. This course teaches C with training wheels on so to speak and later removes them. Would highly recommend taking it. It's also free!

1. https://cs50.harvard.edu

2. https://www.edx.org/course/introduction-computer-science-har...

These are self-paced! Very handy. Thank You.

No problem! I forgot to add in my original post that after the first 5 or 6 lectures the course switches to Python from C. You'll end up hitting two birds with one stone.

Also, there's a very active community around CS50 on Reddit[1] where you can get help when ever you need it.

1. https://www.reddit.com/r/cs50/

I have tried learning C, C++, C#, Visual Basic, Java. I could not grasp much of these language. I found out Python while working on Ubuntu. Learning Python is much easier. Other languages I find easier are PHP and JavaScript. There are more content, help available online for these language. Most importantly, I enjoy Python.

Great Resource for start learning Python Python for Non-Programmers https://wiki.python.org/moin/BeginnersGuide/NonProgrammers

I've always found the premise that there's a good order to learn languages in a bit flimsy. If you're interested in Python and C, I say take advantage of that interest and learn both at the same time. I would echo others' suggestions to start a Python project, and then start writing small parts of it in C. I think that would be a great learning experience - comparing the different mental models, and learning how they can interface.

I would say learn C first, but only if you really want to understand how computers work. Assembly is too hardcore.

C is worth learning just until you understand malloc and pointers. Know about garbage collection, memory allocation, what an array really is, a lot of the low level efficiency stuff. You'll understand how strings and hash tables work.

I learned C in CS major. I was awful, could barely write working code.

Spent a few years writing Python, went back to C... and it was much easier to get right.

I was apprehensive if I could deal with initial frustration due to subconscious comparison of how easy life was with python. I asked myself If I would trip off; will I be able to cope up; will my brain be malleable enough or get hardened against the higher cognitive load C poses comparing to python, etc. with no good answers. Hence this question.

Your experience somewhat soothed me. Thank You.

I'd recommend learning C prior to Python. Although you've stated Non-CS Major, C language can introduce you to many important CS fundamentals better than Python (Not saying Python can't do that). IMO, it's like climbing a ladder, first grasp CS Basics with a simple language like C itself then head towards other language(s).

This sounds natural way to go. What exactly do you mean by CS fundamentals/Basics? Any resource I can grab on to learn them?


Learn them both at the same time. Pick two small projects. For project 1, implement it in Python, then implement it in C. For project 2, implement it in C, then re-implement it in Python. Repeat for the next two projects.

It will feel slow at first, but you will learn more quickly overall.

Python would be easier introduction to programming than C (https://automatetheboringstuff.com/ is great resource for this)

could you add some more details why you want to learn C as well?

The reason for me to learn C is I dislike keeping myself in the dark for far too long (which is the case with Python and other famous languages at production level). I agree with the popular opinion that I should be knowing one layer beneath the abstraction to be a better mechanic. With python its all Magic. I as a magician, oblivious to how my magic tricks work is tragic. If I know something under the hood, I might, just maybe, modify it for better solutions. Isn't that the point of coding anyway?

I am dead serious in writing beautiful code at production level. I am from India and a blanket cloud opinion of Substandard Coders(TM) is already looming heavy. I want myself to notch up and get noticed by differentiating myself apart. Maybe to the levels of Russian/East bloc European countries when it comes to algorithms (I emphasised this is question details). I intend to do freelancing in web products for bread and butter at the start of my career.[I apologize, but I don't intend to be racist here with sterotypes.]

At the same time, due to time constraints, I just can't touch Assembly. So, C.

see skymuse's detailed response...

for algorithms, highly recommend https://en.wikipedia.org/wiki/Introduction_to_Algorithms book.. it uses pseudocode and thus language agnostic

choice of language at production level depends on lot of factors. for ex: you might choose C for speed of execution but Python would win hands-down in time taken for you to write the code, including testing...

getting used to programming takes long time and learning continues life long..

Yes of course.

Thank you for the help.

i was told that c was a tough language and i was apprehensive to start with it in the beginning, i started learning it anyway and wondered what the fuss was all about? it seemed to be easy and i was able to follow without any problem. Mastering it with all undefined behavior,compiler quirks is a different story altogether. I would say give it a try and if you don't like switch to python. I also feel it is easier to go from c to python than vice versa as it takes some time to get around manual memory management in c which is taken care of by the interpreter in python.

Was C your first ever language?

Learning about memory management might be better decoupled from learning "programming" in the very beginning.

yes, it was..

In terms of actual programming, I would start with Python. It's easier to carry momentum and work through fun projects with high velocity. Starting with C, you get a great foundation, but it is a lot of time and work with less instant gratification when compared to Python..

To learn the actual "art of compute". Go from bare metal and then up. In your free time casually learn about logic gates, SR latches and clock cycles. Then to Registers, ALU, Instruction Sets and pushing/popping things on stacks. Then to memory mapping and data buses.Work your way up to the C level of abstraction.

It is a long and brutal road, but it gives a great CS/EE foundation.

I am recommending this route since when they talk about pointers, references,heaps in the C world. It will give you a tangible foundation to built these abstract ideas on.

I vaguely learned the "art of compute" from college via Digital Logic, Microprocessors, and other related classes. Since your in college, I would just sit-in the EE/Comp Sci classes. It is much easier to learn from lectures when you don't care about tests/notes or labs. Then use the internet/office hours to supplement your curiosity/questions.

In conclusion,I recommend casually learning from bare metal and then go up to C then Python. But in terms of actual programming, do Python and work your way down to the assembly level as needed.

I like Python since their are "defacto" ways of doing things. Matrix Math -> Numpy. Lightweight HTTP framework -> Flask. Everything-include web framework -> Django. Web scraper->Scrapy. Need packages -> pip. I know there are other contenders for the things I mentioned, but based on my perception, this is what the Python community is rolling with.

I wanted to recommend doing Javascript/HTML/CSS. It's really cool to work on a project, then publish it on the internet for the world to use/see. But things change so fast, it's hard for a beginner to "sort" through what's needed/useful. React or Vue? Grunt or Gulp? Packages npm,bower,yarn? Async/Promises or callbacks? Don't forget about webpack. Ember or Angular? But wait. There is Typescript,CoffeeScript,JSX which needs to be transpiled. ES6? Here comes Babel. Want to make dev process quicker. Start hot reloading.

The point is,it is a little tough to "sift learn" when picking up Javascript and friends.. The community is moving fast, but it incredibily exciting to watch/participate. But I don't reccomend starting with it.

If you really want to learn HTML/CSS/JS. Start at the Mozilla Developer Network and use vanilla JavaScript. Ignore all the trick frameworks and tools until you understand the problems they are solving. Use them only if they solve problems that you are having.

To go from Python to C. Write some Python app. Profile it. Then write optimized C functions to replace the slow parts of your Python program. Make a Python wrapper with SWIG. Best of both worlds in my opinion.

Wow! I am grateful to you for taking time to write this. You have been very lucid and resourceful on this.

I never knew programming community could be this gooood and welcoming.

Thanks a ton man!

No problem! I'm glad to help. Aim to build something cool and useful, the rest of the pieces will figure itself out. Enjoy your Sunday!

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact