Tuesday, July 25, 2017

Of Religion

I have a little experience in development, more than the age of most developers coming out of school.

I don't say I'm right, but all the best programmers I have worked with, tend to be religious about certain aspects of the code they write. This doesn't say they are right, but one thing is clear, consistency really does go along way to help with building code that works.

Normally when I interview, I like to see a code sample, normally before a second interview,  I try to review it with the people I work with, and I try to then review it with the person I'm interviewing.

For me this provides a great insight into the person, and their ability to handle big problems. Making sure your code is clean, and regular, removes the worry of trying to find problems in it. As often mistakes will be very visible just through the irregularities in the pattern in the code.

An ex partner that couldn't code, could always tell when I was looking on my code, or someone elses, just by the style from across the room.

Again, I'm not trying to say my style is right, but I find someone that doesn't have a style, will write code that will be harder to maintain, and keep functional. When everything is built with the same pattern, finding something new becomes easy, because you already know the pattern, like using the index in a book.

So I guess we get onto some things I like to do to keep my code clean:

All header files have:

#pragma once
#ifndef _MODULE_FILE_H_

#define  _MODULE_FILE_H_


#endif // _MODULE_FILE_H_

As guards to make sure they are only included once.

I tend to try and keep code in modules, with using a module/module.h include file to pull in everything I need.

I generally try and keep one class per file, although I do make exceptions where I think it makes sense, or keeps a piece of functionality hidden at the level it needs to operate.

Scope is very important to me. I use in/out as prefixes on function parameters, I use the l prefix to define locals, and the m prefix to define members. This allows me to quickly see at what level I'm playing.

I like singletons, and generally use the s prefix to hold the member.

I guess thats its for now, as we code, I guess we will get into more style issues.

So I have added some lines to the CMakeLists.txt

include_directories(
    ${SDL2_INCLUDE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
)


and now

#include


still allows main.cpp to build.

No comments:

Post a Comment