Aboutcs student at Paul Allen school of computer science and engineering
Joined devRant on 9/1/2017
Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
Does any of you have the compulsion to micro-optimize every bit of code that you write? How do you deal with it?
I'm not just talking about algorithmic optimizations, but the real nitty gritty stuff. I'm talking about using bit fiddling to avoid if statements where speculative processors might make mispredictions. Anything that might make a program compile to fewer machine instructions or avoid extra stack frame overhead.
This all started a year ago when I took a systems programming course at my university, and started learning C and C++. But I find myself doing this in the wrong places. Who cares if this trivial program that I wrote runs in 1.2 or 0.6 seconds? My future employers won't care if my code is 10% more efficient when it takes four times as long to write.
It's gotten to the point that I can't bring myself to use languages like Python because I don't know how it's implemented under the hood and can't predict how the different ways I could write a function will affect performance. How do I bring myself to trust that the compilers (or interpreters) and the programmers that wrote them will be sufficiently optimal, and just move on? 😩4
Achievement unlocked: malloc failed
(The system wasn't out of memory, I was just an idiot and allocated size*sizeof(int) to an int**)
I'd like to thank myself for this delightful exercise in debugging, the GNU debugger, Julian Seward and the rest of the valgrind team for providing the necessary tools.
But most of all, I'd like that three hours of my life back 😩4
I was tinkering around with my linux installation and trying to decide on a new terminal to use, and I ended up compiling st (suckless terminal). On a whim, I decided to look through the source code and see how much of it I would understand.
There was a C header file called arg.h that uses the preprocessor and macros to parse argument flags and songs by setting up a switch statement in a loop, all in under 50 LoC. To use it, just wrap the switch body between ARGBEGIN and ARGEND, and that's it. The comment at the top simply read "copy me if you can", a challenge to future programmers such as myself.
It was the most beautiful, elegant solution I have ever seen. I tried to tell my girlfriend about it, but she just didn't get it. Maybe some of you will appreciate it more:
So I just had my first coding interview for an internship next summer. It was online, because I'm currently on a different continent. The company uses coderpad.io to do the interview. The website restricts what packages you're allowed to use, and FORCES you to use poorly documented, deprecated ones. On top of that, it fails to send http get requests HALF of the time because of DNS problems! Gaaah!1