Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 18.6 ('Git')
Instant purchase and download via GumRoad!

FEATURE

Writing Better Code

A few tips to get better code in Xojo

Issue: 18.6 (November/December 2020)
Author: Christian Schmitz
Author Bio: Christian Schmitz is the creator of the Monkeybread Software Xojo/Real Studio Plugins.
Article Description: No description available.
Article Length (in bytes): 13,319
Starting Page Number: 12
Article Number: 18602
Related Link(s): None

Excerpt of article text...

Today I offer you a few tips for better Xojo code. Perhaps you can add a few of those to your routines.

Comment First

Before you start writing the first line of code for a method, you should write a comment. The comment should not repeat what you can read in the code later, but answer the question of why you need the method, what it does, and why it does it this way. Basically lay out the purpose of the method and when to call it.

Declare invariants and assumptions. Like if you get a parameter, e.g. a FolderItem, you can document that you expect it to be not nil, valid, and either point to file, folder, or both. The caller may check to make sure some parameters are in range. Or declare that you check the parameter and raise exceptions. Document which exceptions may be raised by the method.

Next, you may think about the blocks in the method and write comments about each part of the method. Before you code, you may have described all parts in comments first. This is comment-driven development and is very helpful if you develop with several people. Each one needs to know why you chose some ways and not others to code a method.

Please do not use abbreviations as not everyone may know years later what you mean. In general, you can expect that you read code several times more often than you write it.

...End of Excerpt. Please purchase the magazine to read the full article.