I saw many people they write code just like that, like writing english. I have been developing many applications in the past but still have to look at my previous projects to develop new projects.

Has it been like that for you before you became an expert?
How can I get it all in my head?


I think it is like anything you do enough times, it becomes second nature after a while and the things that required a lot of thought before, don't as much after the 10,000 time doing it.

I keep a rather comprehensive data base of good code examples. Search by keywords. It makes coding life easier.

I know exactly what you mean London-G, some stuff does stick but I do have to keep looking over previous code for help.

Practise makes perfect I guess...

It's a bit like driving a car. If you are going somewhere familiar you don't really think about what you are doing. If you are going someplace unfamiliar you have to watch for street signs and pay a lot of attention to every turn.

I often joke that I can read and write C++ code faster than English. It's probably true in sheer number of lines. But this is definitely just something you acquire with time. And yes, for a long time, I would always have to refer back to previous code for lots of stuff from basic file layout to specific programming tricks (or how to use a particular class or something). But over time, it is just that more and more things can be done without reference to previous stuff or online examples. And it just transitions like that.

Also, you might get the impression that "we" can put together a lot of code quickly by seeing us write examples when answering questions on Daniweb, or maybe when a teacher or tutor writes a demo program in two minutes. But remember that for most seasoned programmers, these kinds of exercises or small snippets of code present a very low level of difficulty. For example, I took a compulsory introductory Java course not too long ago, I solved all of the class' assignments for the term (about a dozen assignments) in little more than an hour, it's just that it's really really easy to do those things when you've programmed for so many years before. Because most of this stuff are things you've done hundreds of times before, so, you read the "problem description" and you instantly have all the code in your head, and then it's just a matter of typing it up (and remembering the language rules and syntax).

But I would say that writing such simple examples and answering questions on Daniweb (and elsewhere) helps quite a bit at developing the skill to do that quickly. In real life, you don't necessarily get to write many small (< 100 LOCs) programs, and the level of difficulty is higher, so the "raw" productivity (in LOCs per hour) is far less.

Everyone is right about the saying, "Practice makes perfect" but a lot of people don't realize is that you got to have a pretty well developed brain (doing math helps, reading helps, practice your coding and attempting it in different ways help) in order to write good code, as if you are writing an english essay. To me, a good trick is to keep challenging yourself, if you are not challenged, you will not grow...

I personally write code as if i were writing an essay but every once in a while, i need to make references...