Programming is hard.
From time to time all developers will get stuck on a problem and will need some assistance. Sometimes it is a developer early in their career. Sometimes it is an experienced developer working in an unfamiliar technology.
Be a Spotter
When you are the developer that is asked for assistance, there is a temptation for you to come in, take over and fix the problem. But this is also a wasted opportunity. It is something I am occasionally guilty of. This is a chance for you to strengthen the skill set of the other developer. In this situation, you should see yourself as a spotter.
In weightlifting, the spotter is the person that assists the person doing the heavy lifting. Here is the definition from Wikipedia:
Spotting in weight or resistance training, is the act of supporting another person during a particular exercise, with an emphasis on allowing the participant to lift or push more than they could normally do safely. Correct spotting involves knowing when to intervene and assist with a lift, and encouraging a training partner to push beyond the point in which they would normally 'rack' the weight (return it to its stationary position).
The spotter isn't there to lift the weight for the other person unless it is necessary. Their goals are to help the other person get stronger, encourage them, and keep them from getting hurt.
This is the attitude you should have when helping another developer. You should try to help them become a stronger developer. Yes, it might be faster in the short term for you just to do it yourself. But in the long term, the team will be more efficient when all of the developers are stronger.
The Wikipedia definition specifically mentions helping their partner "lift or push more than they could normally do safely". We want to enable our teammates to take on tasks that are on the edge of their ability level. Just as in weightlifting, this is where individuals can really grow and get stronger.
Ask for a Spotter
The other temptation for senior developers is that they don't want to ask for help because they think it is a sign of weakness. But again, the weightlifting analogy is helpful. Strong weightlifters don't bench press without a spotter. They know that they could hurt themselves. Strong developers need to recognize when they are at the edge of their knowledge. They need to admit that without help, they might hurt the code base or the project.
An important side benefit of asking for help is modeling this healthy behavior to our teammates. If the younger developers see the more experienced developers asking for help, they won't be tempted to hide their own struggles while thrashing on a problem.
I have a teammate at Aptera that is also a former student. Since joining our team, he has learned a lot about SQL and big data. At this point, he knows more about those topics than I do. So when I am writing complex SQL queries, I often ask him to "spot" me. There are still times when he asks me to "spot" him in C#. We help each other get stronger and achieve our maximum results.