If the C variant needs x hours less, then I'd invest that time in letting the algorithms run longer/again
"invest" isn't the right word here.
Build a working implementation in Python. You'll finish this long before you'd finish a C version.
Measure performance with the Python profiler. Fix any problems you find. Change data structures and algorithms as necessary to really do this properly. You'll finish this long before you finish the first version in C.
If it's still too slow, manually translate the well-designed and carefully constructed Python into C.
Because of the way hindsight works, doing the second version from existing Python (with existing unit tests, and with existing profiling data) will still be faster than trying to do the C code from scratch.
This quote is important.
Answer from S.Lott on Stack OverflowThompson's Rule for First-Time Telescope Makers
It is faster to make a four-inch mirror and then a six-inch mirror than to make a six-inch mirror.Bill McKeenan
Wang Institute
If the C variant needs x hours less, then I'd invest that time in letting the algorithms run longer/again
"invest" isn't the right word here.
Build a working implementation in Python. You'll finish this long before you'd finish a C version.
Measure performance with the Python profiler. Fix any problems you find. Change data structures and algorithms as necessary to really do this properly. You'll finish this long before you finish the first version in C.
If it's still too slow, manually translate the well-designed and carefully constructed Python into C.
Because of the way hindsight works, doing the second version from existing Python (with existing unit tests, and with existing profiling data) will still be faster than trying to do the C code from scratch.
This quote is important.
Thompson's Rule for First-Time Telescope Makers
It is faster to make a four-inch mirror and then a six-inch mirror than to make a six-inch mirror.Bill McKeenan
Wang Institute
Yes. Look at Cython. It does just that: Converts Python to C for speedups.
Are there any libraries that can easily convert Python to C/C#/or C++? Ones where a person doesn't have to "calibrate" it, just, pip install library and then they can have their Python code in C,C#,or C++?
Is there anything to translate Python to C code?
Switching from C to Python: A Mixed Experience
C or Python?
I learned Python as my first language. I am by no means good at programming, but I had to learn it so I did. It is pretty straightforward in terms of syntax and it reads kind of like English. I guess it was good for me to focus on the logic rather than the syntax and other things. Now I have to learn C++ and for the most part i am happy to have the logic part down and now it's just a matter of time to get used to the syntax and specific things of C++.
I think if I would have learned c++ first I would have been very overwhelmed, but I had no experience at all and everything was foreign to me so I can't say if this is the case for you.
More on reddit.comHow do I convert Python to C?
How do I convert Python to C++?
Can I convert C back to Python?
Are there any libraries that can easily convert Python to C/C#/or C++? Ones where a person doesn't have to "calibrate" it, just, pip install library and then they can have their Python code in C,C#,or C++?
After several weeks of working with C, transitioning to Python has felt like a relief in many ways—no more manual memory management, function prototypes, or compilation steps. Python’s built-in data structures, like lists and dictionaries, simplify many tasks that required linked lists and hash tables in C. Error messages are also clearer, making debugging easier.
C was the first language I learnt, so I'll always have a soft spot for it.
Despite the objectively simpler syntax in Python, I find myself instinctively trying to write code the "C way," which doesn’t always translate well. Writing Pythonic code requires a change in thinking, just like learning a new spoken language (something I've also embarked on after moving to a new country). Maybe I'm making slow progress, or maybe it's normal?
While I understand the logic of Python syntax, structuring loops and handling iteration in feels harder to manage, at least for me. The final problem in CS50’s Python set—DNA sequence matching—was particularly frustrating. I really struggled to adjust to Python’s looping and file handling, especially when combing both. Looking back the logic is somewhat trivial and in comparison to some of the C programs I have written, should have been a lot easier.
Python’s abstraction over iteration is both a strength and an adjustment—rather than controlling every step like in C, I need to embrace higher-level thinking. It's hard to break away from thinking the way you were initially taught, though.
Despite these hurdles, Python’s ease of use and powerful built-in tools are making coding feel more intuitive. I know that, like with C, things will click with time and practice. The goal now is to embrace "Pythonic thinking" and continue improving, at whatever rate that is.
If you have any thoughts or suggestions on what I can focus on going forward let me know.
I've started to read "Automate the Boring Stuff with Python", and I am considering MIT OCW Introduction to Computational Thinking and Data Science. Has anyone taken this course?