wiki:HowtoGoodProgrammingTechniques

Version 1 (modified by Thanatermesis, 12 years ago) ( diff )

--

This is a list of some good programming techniques that I learned myself over the time

Programming Procedure

I normally follow a simple steps procedure when coding, to do in every new function:

  1. Write: I have the idea in mind, so I need first to make it working, this is normally ugly code but here, the goal is to make it working
  2. Make it good: Then I make better the code, including the methodologies of this coding like correct returning values, making a better structure and a better and readable identation
  3. Understanding: Good names in variables and functions is maybe the better correct programming tip that you can have, see the section of convention-names, this is a little slow procedure since thinking in the best names to use requires some brainstorming
  4. Cleanup: Now is time to remove all the useless parts, the goal is to use the simplest solutions and procedures, they are usually the most appropiate ones, try to reduce the code the maximum possible, this step consist in multiple reading of the function thinking on how it works, you will discover on this step a lot of bugs in your code that you won't imagine that exists.

Convention Names

Names in variables and functions are something very important, the convention to use is to be the smallest-size possible with a perfect understanding of its name and what exactly does, think on the structure like in object-programming languages, where the first name needs to be the biggest element and the last the smaller one, and in the end include the action.

Never do names like that:

  • download_resource_now: It doesn't has any sense or description, the action is in the first, now means nothing and resource nothing too
  • stmb_sizer_here_here: The double here means that your code is so ugly that you don't even believe it, sizer is not easy to understand and if stmb is not the name of a library or evident element, it is almost impossible to understand what it means

Better on that way:

  • cookie_download: we know that we are talking about cookies, and we don't need to include now because download is already the action, in case that we will have 2 different kinds of download we should use download_foo and download_bar, without keeping the possibility of a single download and having an extendeded one

But even better on that way:

  • myplugin_net_cookie_download: Structuring everything entirely is the best option, all our elements should start by myplugin which is our entire work about, net means the section were we are those codes (let's say we have core, net, visual, and sound)

In short, most of the times you will see that the names are writed in the inverse mode that how you talk them, if you doubt, just imagine to have some similar possible names and you sort them, you will see how they are sorted and which part of the name needs to come before the other ones

Note: See TracWiki for help on using the wiki.