Skip to content

Tip: Coding Guidelines

How do you format and organize your code? I’m here to tell you that your way is wrong and my way is right 🙂

In all seriousness, there is no one “right” way to write and organize code. But what is important is that you are consistent.

Every developer and team should have coding guidelines to help ensure that code is readable by everyone on the team (or even yourself several months from now). There is no such thing as coding guidelines that everyone will agree with, but the guidelines described here are meant to be a starting point and match the coding guidelines generally used for the Xojo example projects and sample code that you see in the Dev Center and other docs.

Consistency_is_the_key.jpg

So I will repeat: the most important thing is consistency. Regardless of what guidelines you choose to use, inconsistent code is more difficult to understand.

Here are just some of the things you should cover in your coding guidelines:

  • Naming: How should you name your constants, variables, methods, classes, properties, controls. For example, don’t name some constants as kValue, other as KVALUE and others as k_VALUE. That’s just crazy.
  • Formatting: How do you write keyword? Do you use all CAPS (“IF value = 1 THEN”), lowercase (“if value = 1 then”) or mixed case (“If value = 1 Then”)? I don’t care which you choose, but don’t mix them up because it shows a lack of attention to detail: “IF value = 1 then”. That makes my eyes bleed.
  • Spacing: How do you use spaces “value=1” or “value = 1”?
  • Friendships have been lost over spacing after parenthesis. know that there should be no spaces after parenthesis. Correct: “save(value1, value2)”. Incorrect: “save( value1, value2 )”
  • Where do you declare your local variables? At the top of the method (gross) or near where they are used?

Of course, there are even more things you can include, depending on your personality and the type of team you work with.

But if you want to name, format and write your code the One True Way, be sure to check out the coding guidelines I recommend in the Dev Center:

http://developer.xojo.com/coding-guidelines

You may argue with me here in the comments or on the forum. But remember, you’re still wrong! Happy coding!


Code Tip: Speed up SQLite with Write-Ahead Logging