One thing that I find easier in C compared to Python is that loops are not as expensive. And sometimes, things are easier to implement when you can think of them individually.
For example, to render characters with different styles, we can do this in C:
for (index = 0; index < SIZE; index++) { render_character(characters[index], styles[index]); }
This is cheap in C. But in Python, it is expensive. So to make this fast in Python, we might want to do something like this:
for (substring, style) in split_parts(text): render_text(substring, style)
Assuming we can write split_parts without looping over all characters, this will perform better in Python because of fewer loop iterations.
in #c
This is a short note about my experience with C.
I've previously written about how I feel that C slow me down. Partly because it is a lower-level language than I'm used to. Partly because I don't know it that well.
But yesterday when I worked on rlworkbench I felt that making a change was not that hard. It might even have felt slightly easier.
This feels like a breakthrough for me in my C journey. Perhaps I've learned C well enough for it to not be in my way? Perhaps I've got enough primitives implemented so that I can do some high level programming without more effort? Perhaps the C programming paradigm is more productive? I don't know. But I'm starting to like C more and more.
in #rlworkbench #c
in #newsletter #c
in #c
in #c
in #c
in #c
I couldn't resist programming some C today.
The program that I worked on was a program to print unique lines:
rick@fedora:~/projects/cunique$ cat test.txt hello world hello there rick@fedora:~/projects/cunique$ ./cunique <test.txt hello world there
I managed to write it, but I also wanted it to perform well. When I try the above with a 1GB file it seems to take forever, but my Python equivalent finishes in around 5s.
That made me feel discouraged and made me think that I should work more on Computer, Enhance! before I think I have an idea about how to write performant C code.
However, I got to program C and that was fun.
in #c
in #c
in #rlworkbench #c #aoc
What is Rickard working on and thinking about right now?
Every month I write a newsletter about just that. You will get updates about my current projects and thoughts about programming, and also get a chance to hit reply and interact with me. Subscribe to it below.