r/learnprogramming • u/Lemenus • Oct 29 '26
How to train programming logic?
It's easy to learn syntaxis of a programming language, or buttons of a software, but it won't give you the skill, and programmer should learn how to solve problems, but even here it's possible to learn how to do it not in the best way possible, at least I have no idea what you need to do it in a very efficient way.
I just got my mind blown with this:
std::bitset<4> rotLeft(std::bitset<4> x, int n)
{
return (x<<n) | (x>>(4-n));
}It's a C++ function to rotate bitset, I would never figure out that it's possible to do it in THAT way, I did it with loop that stores bit that is about to get out of bounds and then putting in the beginning...
How do you even learn this kind of mentality / logic, to come up with such stuff? I just refuse to believe that it's done by practice alone
View all comments
1
u/Positive_Passion4817 Oct 29 '26 edited Oct 29 '26
I learned about that idea when briefly looking in to assembly language and then later relearned and used it when doing a module at university involving arduinos and trying to control led arrays as rapidly as possible if I remember right.
Sometimes you can be just lucky to stumble across new techniques and ideas. Sometimes it comes from just wondering if there are ways to do something because the way your are doing it seems awkward and you feel there had to be a better way. A bit of googling and usually you find there is.