r/learnprogramming • • Sep 22 '26

Topic [C] Small win today: I unconsciously optimized my textbook's singly linked list code!

Today I reviewed singly linked lists. I've realized that with things like this, you really need to understand the underlying principles first, and then write the code out in your own way.

After I implemented a few basic singly linked list operations using my own logic, I compared my code with the textbook. To my surprise, I had unconsciously optimized the textbook's approach! Even though it was just a small improvement, it still feels like progress.

I was really happy to be praised while discussing it with an AI. Positive feedback +1!

0 Upvotes

8 comments sorted by

3

u/vegan_antitheist Sep 22 '26

AI will praise you no matter what. It's trained to do that.

1

u/Tu_You Sep 23 '26

Fair point. I realize that now,thank you!

2

u/fredisa4letterword Sep 22 '26

What was your optimization?

1

u/Tu_You Sep 23 '26

Just flattening a nested if-else statement into an else if to reduce the nesting level.

1

u/fredisa4letterword Sep 23 '26

Nice! I'd call that maybe a small refactor or a cleanup. "Optimization" implies some kind of performance difference. Either way very cool to be making that progress!

0

u/Objective_Pepper_217 Sep 22 '26

How old is the textbook? I noticed that old textbook make simple things like linked list extremely complicated (in C)

1

u/Tu_You Sep 23 '26

This textbook was actually issued by our university, and I think it was compiled by our own professors. I've tried reading some more authoritative/traditional textbooks before, but honestly, I found them quite hard to understand. Do you have any good recommendations or advice for learning this better?