Walls act as a shield that will protect your buildings from invading enemy troops, especially melee units. They are also the most expensive buildings to max out, considering that you are upgrading all the Wall units and not just one. Thus, the level of the player's wall may also be a factor in determining how active a player may be.
Gates can be placed between Walls to allow Roads and defenders to pass through your Walls, but are often a weak spot. In general, you should aim to upgrade your Gates to a higher level as they have less hitpoints than Walls at the same level.
You can start using Food as an alternative resources to upgrade Walls at level 9.
You can start using Wall Manual (stored in Archive) as an alternative resources to upgrade Walls at level 5 after 6.6 Update.
Don't just encircle your whole base in Walls or your enemy will only need to go through one layer of Walls to get at everything. Instead, only protect what is most valuable(along with defensive buildings) and have multiple layers of Walls.