Coding speed depends heavily on how familiar you are with the problem domain, language, libraries, and code base, and the quality of documentation for things you are not familiar with. It depends on the complexity of the task, and whether you have a sufficiently high-level roadmap that separates your task into meaningful, independent chunks. (The appropriate level can be something as high as MVC, or as low as various parts within a function.) Creating a roadmap of chunks is extremely helpful for any relatively complex task, because when you start working on one, you know exactly what you need to focus on and what not to. The alternative is fumbling your way through vaguely defined requirements, your brain lost in a haze of concerns that may not be relevant, with the likely result being poorly written and organized code.
Then there's your brain's state, dependent on all sorts of things like your health, wakefulness, nearness of deadlines, etc. Some of this can be easily manipulated, e.g. by listening to good coding music, meditating, drinking coffee, etc. Pair programming can also speed up coding considerably (though at the expense of having two programmers focused on the same thing instead of working simultaneously on different things). Part of this is because when a peer is looking over your shoulder, you approach coding as more of a performance, and thus don't lapse into idleness or reading Hacker News. Another part is that when you run into roadblocks, and need to, say, look up documentation, the two of you can cover more ground faster. There are a lot of other benefits that have been covered well by others, so I won't go into them.
I also find that when I start something new, whether a new project or a new part within a project, I'm usually very, very slow to get into it. I've discovered that this can usually be circumvented by focusing on some minimal first step, which gives you enough of a toehold with which to immerse yourself in the project/problem. Once you've reached that point, the hard part is stopping.
Then there's your brain's state, dependent on all sorts of things like your health, wakefulness, nearness of deadlines, etc. Some of this can be easily manipulated, e.g. by listening to good coding music, meditating, drinking coffee, etc. Pair programming can also speed up coding considerably (though at the expense of having two programmers focused on the same thing instead of working simultaneously on different things). Part of this is because when a peer is looking over your shoulder, you approach coding as more of a performance, and thus don't lapse into idleness or reading Hacker News. Another part is that when you run into roadblocks, and need to, say, look up documentation, the two of you can cover more ground faster. There are a lot of other benefits that have been covered well by others, so I won't go into them.
I also find that when I start something new, whether a new project or a new part within a project, I'm usually very, very slow to get into it. I've discovered that this can usually be circumvented by focusing on some minimal first step, which gives you enough of a toehold with which to immerse yourself in the project/problem. Once you've reached that point, the hard part is stopping.