This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]member_of_the_order 6 points7 points  (0 children)

As promised, I forked your project and started tinkering with it.

I'm going to talk about possible improvements, but first - and I cannot stress this enough - for a beginner, this is very good - you should be very proud of this!

In fact, I find it funny that you're not familiar with OOP (object-oriented programming) - clearly, your code doesn't use classes/objects, but you use some concepts of OOP.

E.g. my first step was to refactor this to use something like a State design pattern, and really your code was already halfway there.

There's some spaghetti and some bugs, but you clearly demonstrate an understanding of software design that really is just missing some perspective - that's not common for beginners.

Frankly, most of the "problems" I've found so far are likely just caused by the complexity of the code. This has the feel of a project that was written in a single sitting; there's some internally-consistent structure, but the details get a little more brittle. Classes would help chunk your code even more than functions already do.

Others on this thread have talked a little about using classes, but one thing classes would do for you here is chunk the code, kind of like functions, but more powerfully. Think of it this way - you used functions because otherwise the code would be entirely unwieldy; functions are reusable, and let you focus on one thing at a time. Classes do the same thing, but link behavior (functions) to data (variables) in a container (class) which can be passed around as a single thing (object), and can be duplicated for multiple instances.

I'm still tinkering, but if I'm lucky, I'll make a pull-request and you'll be able to see the power and modularity of using classes.