I am a junior and I want to do it right from ground up. No spaghetti code. Just code that is correct, short, to the point, and pleasant to read.
Please elaborate on this topic, and point out do's and don't's.
Do: Use an IDE Do: Enforce coding standards, a la This JavaRanch article or Sun's own standards
Do: Read lots of books
Do: Practice a lot!
Do: Learn design patterns Do: Practice a lot!
Do: Go back and criticize your old code.
Do: Practice a lot!
Do: Get others to criticize your code
Do: Practice a lot!
Do: iterate all these over and over again
(1) Do use an IDE, but only after you've learned to program. Starting out with a language using an IDE will prevent you from understanding low-level stuff, so that when something goes wrong, you'll be helpless. Here at the Ranch, we always recommend that people use the command-line compiler "javac" and an editor like TextPad until they are comfortable with these tools, before moving on to an IDE. Using an IDE can be like wearing mittens on your hands!
(2) Be aware of design patterns, and learn to recognize them, but do not be looking for opportunities to use them! There's a terrible newbie syndrome wherein every problem is an opportunity to apply a design pattern; the result is enormous, over-complex, impossible-to-understand code. Don't do this. Design patterns were invented as a way to talk about code, not as a recipe book. Anyone who tells you otherwise is steering you wrong.
The advice about reading your own code, and other people's code, and getting feedback from others, is great. That's exactly how you learn.
ting yun wrote:I am a junior and I want to do it right from ground up. No spaghetti code. Just code that is correct, short, to the point, and pleasant to read.
This is what exactly I was thinking before and still sometimes. But you should not only go for THE BEST code on first attempt. This is a learning process. You code something , you look at your code, seek some improvements and code again. If you think that your code should be perfect on the first attempt itself then you would be stuck. If don't code bad , no chance of improvement (Don't misunderstood).
You can learn from others code. You can put your code here and ask for assessment.Spend sometime on this website.(I am addicted to this site, really.)
Be aware of design patterns, and learn to recognize them, but do not be looking for opportunities to use them! There's a terrible newbie syndrome wherein every problem is an opportunity to apply a design pattern; the result is enormous, over-complex, impossible-to-understand code.
I am the victim of this newbie syndrome. I have messed up my code because of that and later remove that unnecessary pattern that I have been motivated to use from other project.
My tip: don't overemphasize perfectionism when trying to come up with a product. It may seem that you have all the time there is to complete something, but consider what you want to have done and when. Some parts of the solutions are intentionally a bit 'dirtier' than other parts. Some years back I started programming a mud and found that I needed an easy way to make objects editable (through an ascii menu) and streamable, etc. I came up with two functions that objects would need to override, to fill up a DOM structure with their data (based on a template that would describe the members etc.) and from there it was handy to write generic code that deals with the actual work. Half a year later I wished I had just made it easier, because with knowledge of libraries and frameworks around I think I would have handled it differently and the solution that took _too_ much time looks shaky, not perfect.
I think it's a kind of psychological mania to get satisfied with code.
I experienced such a syndrome few years ago, achieved the result, i was satisfied with every line of code I wrote). But the real world usually brings you to the team. Not all team members code perfect. You perfect coding skill will rise into aggression against all team fellows who do not code well. So think twice what You want to achieve.
What perfect coding will give You: nothing but headache (imho) and feeling that You are better then other imperfect coders (they will not feel that though)
There are a lot of good aims to pursue: to create reliable programs, to be doc in real time programming, be on demand in market, rise IQ score, marry and grow up kids, do not be perfect coder!
Also i would say java is not a language to write perfect code. Programming on java You will usually repeat yourself, try python
ting yun, have you heard of JavaRanch's Cattle Drive? You learn some java and, just as important, you learn to write nice, readable code. You get feedback from a live person on your code for each assignment. Check it out:
I took the cattle drive and it taught me a lot about clean code - more than any other place, I think. It helped me *really* get some of the basic principles of writing readable code, not to mention an appreciation of the profound difference that a large number of small changes can make.
I never write perfect code, but I'm not really aiming for perfect - I'm aiming for good, clean, maintainable, readable code. One of the books that I found incredibly helpful is Clean Code by Robert Martin. By the time I had read through the first few pages I wanted to dig up some horrible code and make it a little better.
As luck would have it, I work on a project that has islands of festering code just waiting for me