Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

As a new programmer, it has always been hard to create applications, because I am still at the learning stage.

I understand that to achieve a particular affect or function in an application, there will be numerous ways to achieve the same result.

However, should I just purely create a function to it's working state, which means that as long as it works, just as the way I want it to, then it should be fine.

Can any fellow programmers of a higher level kindly let me know the right way of doing things?

share|improve this question

7 Answers 7

There are several "known" coding standards that you can look at. For example, for embedded C development - MISRA C would be a good start. This one is a nice C++ coding standard. There are probably others available for other languages.

In the end its a lot of common sense and common practices, you gain that with experience. Of course, workplaces have their own coding standards (or at least should have) to which you should adhere as well.

share|improve this answer
    
Now, it's been some time since I read it, but I seem to recall that MISRA is a total joke.# –  DeadMG Aug 29 '11 at 21:55
1  
@DeadMG - Joke? No. Why? It's targeted for a certain niche, and for those not in that niche it may look like an overkill. But for a safety critical development, that would be a very good guideline. I've worked with MISRA C when I was developing a coding standard for my team, and I took quite a few things from there (but definitely not everything, we were not developing a safety critical code that should have zero bugs). However I'm mentioning it here as an example of a very comprehensive coding standard. –  littleadv Aug 30 '11 at 6:53
    
It's been some time since I read it, so I don't recall any specific examples. I do, however, recall reading it and holding the firm belief that it was written by people with no idea what they were doing or saying. –  DeadMG Aug 30 '11 at 12:16
    
@DeadMG - then it seems to me that you had no idea what it was designed for. –  littleadv Aug 30 '11 at 21:33

The mantra that I repeat to my junior devs is "Make it work, then make it pretty." Your code should follow a standard for naming and what not. I use the Framework Design Guidlines when writing C# with one exception: I always place an _ before the name of a private member. Makes finding them that much easier.

Anyway, there is a second question here. And that is how to improve the code that you've written. I'll point to Clean Code and Triple P as must reads for developers wanting to learn how to code better.

share|improve this answer

We are all still at the learning stage. It will last forever.

I think the best way to improve your knowledge is by learning from other's code or by doing pair programming with higher profiles than you.

Therefore, you should do the following:

  • Ask for pair reviewing or programming actively. Don't wait for this to be proposed to you. If you are a solo developer, consider online reviewing platforms.

  • Read as much code as you can. It's how I learn many of the feature of the .NET framework. "Oh I wasn't aware I could do that in just one line of code!". It's like novel writers that gets their ideas from others authors. Don't know where to look? Pick a random open source project and browse in it, just like Stanley Kubrick did to get his inspiration: going to library and picking ANY book in ANY category.

In one Kubrick’s biographies he is described as using a simple method to expand his knowledge base. He would visit his library and select random books from random information categories, without even looking at the titles. He would then force himself to read those books. By doing this Stanley was forcing his mind to expand into new territory on a regular basis.

In order to learn even more quickly, put what you see in practice, in your own code or in samples projects. It will help a lot to memorize.

Learning is probably what drives us all in programming. It's a perpetual exploration.

share|improve this answer

Realistically, you can't appropriate other people's coding standards. This is because they have requirements you probably don't. For example, look at Google's C++ style guide. It is that way not because it produces good C++, but precisely the opposite- because it produces terrible C++ that's C-style so they can interact with their legacy C code.

The only way to realistically develop good coding standards is to either inherit them from someone who has already worked on the codebase for a long time, or to learn from your own hard experiences working on it.

You should design first, then code. Rushing into programming is a bad habit. But don't make it pretty- that's just a waste of time.

share|improve this answer

Some good improvement ways are:

  • reading books
  • working in a team, under the authority of experienced developers

You don't give us many information to help you more precisely...

share|improve this answer

I would approach improvements from several directions:

Use some tools/plugins that give you instant feedback during programming, so that you can make your code better readable, usable, robust, performant, correct. For instance in Java, you could use checkstyle, PMD, Findbugs

Write tests: that alone improves your development process, and gives you a safety net when you are experimenting and trying to improve your code, e.g. by refactoring.

Use metrics to check your result and get further hints. For instance in Java, thee is jdepend, metrics, JavaNCSS, EclEmma.

Get new ideas and information by

  • reading books
  • code review
  • pair programming
  • talking with other developers, e.g. on brown bag meetings / lunch breaks
  • listen to podcasts
  • read stackexchange posts.
share|improve this answer

I am personally fan of the High Integrity C++ standard.

The rules are extremely objective, there is no naming convention for example.

3 Class

3.1 General

High Integrity CPP Rule 3.1.1 Organise 'class' definitions by access level, in the following order: public, protected, private. (QACPP 2108, 2109, 2191, 2192, 2195)

Justification Order by decreasing scope of audience. Client program designers need to know public members; designers of potential subclasses need to know about protected members; and only implementors of the class need to know about private members and friends.

class C // correct access order
{
public: // ...
protected: // ...
private: // ...
};

Reference Industrial Strength C++ A.12, A.13;

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.