b2cloud

2nd August 2013

#warning notes

Guides | Tutorial By 3 years ago

When coding, personal notes are a good way to make sure you don’t forget anything, and keep track of certain things. I often see people making notes either physically or in a document, however there is a better solution…

Physical notes

Physical notes aren’t very good. For one they are personal, so anybody else on the project will never see your notes unless you tell them about them. Also they may get lost on your desk, or one night when the cleaner comes in they may vanish!

Notes document

Unless you’re committing these to your git, any other developers wont see these either. Even if you do put them on your repo, they can be easily missed and forgotten about.

Comments in code

These have the advantage of being inside your code so hopefully the other devs and even yourself will remember to go back and look over them. Often they begin with something like // TODO:, so they can be searched for easily. As with the alternatives above though, they can be easily overlooked and forgotten.

A better solution

My favourite alternative is using the #warning preprocessor directive. This will create a warning just the same as any other compilation warning, so it’s in your face, and anybody else that opens the project for that matter.

I personally use Xcode, but any C based language in an IDE should show the warnings visually. Even when compiling through the command line, the warnings will show up in the terminal.

This can be done easily by simply typing #warning and then some text.

#warning Clean up this code after testing

These can also be useful when dynamically choosing urls, to ensure you don’t upload to the AppStore (or wherever else) connected to the development server.

#if DEBUG
#warning Using development server
#define SERVER_URL @"http://dev.b2cloud.com.au/service/v1"
#else
#define SERVER_URL @"http://api.b2cloud.com.au/service/v1"
#endif
Recommended Posts

Yammer integrations in ReactJS

Post by 3 years ago

I am writing this blog while I am working on a project for our client’s intranet website. The client requires the website has the ability to share, like and write comments in the website through

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!