DRY and OOP

Stats

83 visits, 94 views

Translations

This tutorial hasn't been translated.

Tools

If you've ever worked on big programming projects using modern languages before, you probably know what these mean, and save yourself some time: Skip ahead.

If you're wondering why I'm telling you to stop being wet, then read along.

DRY: Don't Repeat Yourself

DRY is a very important, yet very simple concept in programming: If you every need to run a bit of code twice at two different places, make it common.

The rule is simple: Don't repeat yourself. You have an enemy that throws arrows and snowballs? Make a common throwing code bit and make both your features use it.

A very common mistake among younger programmers is to just copy paste code around everywhere they need it.

Even if you didn't know about this rule, you might still see how it can be useful.

It makes code easier to read, maintain and update

So please use functions.

OOP did I say

functions?

OOP. Object Oriented Programming. Everything is an object and you can create a multitude of small objects that all inherit from one big object: That's the class system. Classes are the best modern way to efficiently write game code.

Good thing Construct doesn't have classes :D. Construct has families though! I made a whole article already on how to properly use them to simulate a class like behavior using events, so read through this if you didn't do it already: https://www.construct.net/en/blogs/skymen-13/optimal-write-events-construct-1049

Next Tutorial In Course

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!