Some people are not very good at organizing their free time so that they get enough sleep the night before. This will hurt your career as a programmer. If you want to improve your performance, drugs will be nowhere near as effective as sleep.
If you have a social or medical situation that making it so that you can't sleep, do whatever you can to fix that problem. I advise you to try to make it your top priority. Get professional help if you need it.
If you are in a situation where you can't sleep because your work/commute time is eating into your sleep time, quit. You are damaging your health and also your ability to grow as a programmer. It is not worth it in any way.
Nothing else I have done has been so important to my life and career as the above.
It is really amazing how much of a difference in your personality and abilities a good night's sleep can make.
I started using 100mg/day modafinil for the first time about a month ago (week days only). I felt no clear discernible cognitive enhancement that is often said about modafinil use. What I did however notice is that it does a good job keeping me awake to handle one more day in a sleep-deprived state ... only to crash with a god awful hangover a day later. (Severe headaches, dizziness and loss of physical strength). Modafinil masks your exhaustion artificially.
I'm down now to 50 mg (broken pill) for days I feel I need "a starter". This seems to be an optimal dose for me right now but I am certain I won't be using it long term or in larger doses.
Don't do it. At all.