Siriel 04 – #ifdef in Unity could lead into bad code maintainability

I was playing with Unity. Extending functionality bit by bit. Then I decided to make my game available also for mobile device.

So I searched for another tutorial from Unity – 2D Roguelike 14 of 14 : Mobile Controls. The tutorial seemed to be ok. But at one moment I froze in horror. The author was using #ifdef directly in high level code.

In my opinion this is very bad code smell. If you’re C expert and you’re playing with low-level API then you’ll need #ifdef, but this is high level code.

You may ask what is wrong about #ifdef in my “C# Script”. Well, here is very nice answer for C++.

#ifdef is something which should be treated with maximal caution, because it has tendency to explode into many Heisenbugs.

3. October 2016 at 20:38 - Development (Tags: , ). Both comments and pings are currently closed.

Comments are closed.