http://slides.claydowling.com/realpirates
clay@lazarusid.com
@ClayDowling
claydowling.com
Different build tools exist to make the job easier.
Build tools are their own programming language.
PROGNAME=myprogram
OBJS=$(patsubst %.c, %.o, $(wildcard *.c))
$(PROGNAME): $(OBJS)
$(CC) -o $@ $^
clean:
rm -f $(PROGNAME)
rm -f *.o
cmake_minimum_required(VERSION 2.8)
file(GLOB program_SRC
"*.c"
)
add_executable(myprogram ${program_SRC})
// Sorry, it's a beautiful
// mystery to me as well.
Programming is like playing with a loaded gun. C cocks the hammer for you.
Prefer
struct stat sb;
if (stat("file.txt", &sb))
Over
struct stat *sb = calloc(1, sizeof(struct stat));
if (stat("file.txt", sb))
If You Write… | Also Write… |
---|---|
malloc/calloc | free |
myobject_create | myobject_destroy |
Write automated tests for all of your code
Use valgrind on your tests
Do not ignore valgrind errors
“I am a mere mortal, and that’s okay.”
START_TEST(skillcmp_givenAandB_returnsNegativeOne) {
skill_t *a = skill_create("A", 0, S_CATEGORY, S_ATTRIBUTE);
skill_t *b = skill_create("B", 0, S_CATEGORY, S_ATTRIBUTE);
ck_assert_int_eq(-1, skill_cmp(a, b));
skill_destroy(a);
skill_destroy(b);
}
END_TEST
./test-genesyssheet
Unity test run 1 of 1
.....
-----------------------
5 Tests 0 Failures 0 Ignored
OK
all: test product
product: $(OBJECTS) main.o
$(CC) -o $@ $^
test: test-product
./test-product
valgrind test-product
test-product: $(TEST_OBJECTS) $(OBJECTS)
$(CC) -o $@ $^ $(TEST_LIBS)
Many common problems.
Many common solutions.
If it’s a network protocol, libcurl speaks it.
Easy to mock/test code using libcurl.
Easy to test without mocking.
Can have a server doing useful work in under an hour.
Database
Native, fast clients available for:
http://slides.claydowling.com/realpirates
clay@lazarusid.com
@ClayDowling
claydowling.com